FidoNet Echomail Archive
c_echo

<<< Previous Index Next >>>

From: Kurt Kuzba
To: All
Date: 2004-09-20 12:37:52
Subject: [C] numdrop4 v4.4 - [1 of 6]

From: "Kurt Kuzba" <kkuzba{at}centurytel.net>

Vacation time again.  More edits, more fun. Better code.  Added shuffle. 
Cleaned up a bit.
/*_|_|  numdrop4.c  v4.4  PUBLIC DOMAIN 9/20/2004 by Kurt Kuzba
_|_|_|  A simple number game. ANSI C with some non-ANSI functions. _|_|_| 
Tested in VC++ 5.0 as a console app. _|_|_|  Part 1 of 6
_|_|*/
#include <stdio.h>
#include <stdlib.h>
#include <conio.h>
#include <time.h>
#include <string.h>
typedef struct{ char S[81]; } Text; typedef struct{ char L[11]; }
sGameLine; typedef struct{ sGameLine C[10]; int X, Y, Score; }
sGameColumns; typedef struct{ sGameColumns B[51]; int Move;} sGameHistory;
int rnd(int lo, int hi)
{   return lo+(int)(((long)rand()*(long)(hi-lo+1))/RAND_MAX); }
/* return integer from lo to hi, inclusive */
void stuffsquare(sGameHistory* GBs, int y, int x, int c, int m) {
GBs->B[m].C[y].L[x] = (char)c; }
/* assign value to game line string array */
void swapsquares(char* c1, char* c2) { int iTemp = *c1; *c1 = *c2; *c2 =
(char)iTemp; }
/* swap values at two char pointers */
int squarevalue(sGameHistory*  GBs, int y, int x) { return
GBs->B[GBs->Move].C[y].L[x] - '0'; }
/* return value at game grid xy point. */
void InitArray(sGameHistory* GBs)
{
  int iTa, iTb;
 /* iterators */
  char shuffle[101], *Tokens = "1234567895";
 /* array and preset values for array */
  for(iTa = 0; iTa < 91; iTa+= 10)
    sprintf(shuffle + iTa, "%s", Tokens);
 /* put preset values into array */
  for(iTa = 0; iTa < 900; iTa++)
  {
    iTb = rnd(0, 99);
    swapsquares(shuffle + (iTa % 100), shuffle + (rnd(0, 1000) % 100));
  }
 /* randomize array contents */
  GBs->B[0].Y = GBs->B[0].X = GBs->B[0].Score = GBs->Move = 0;
 /* initialize game position, move, and score */
  for(iTa = 0; iTa < 10; iTa++)
  {
    sprintf(GBs->B[0].C[iTa].L, "%.10s", shuffle + (iTa * 10));
  /* insert data from randomized string into game grid */
  }
}
void show_array(sGameHistory* GBs)
{
  char buf[15], *top_bottom = " o------------o";
 /* buffer for display string construction */
  sGameColumns* GC = &GBs->B[GBs->Move];
 /* handy pointer to current game grid */
  int iTa, y = GC->Y, x = GC->X;
 /* iterator and handy grid xy integer values */
  system("cls");
  puts("Use arrow keys, Space, ?");
  puts(top_bottom);
  sprintf(buf, " |            |");
  buf[x + 3] = (char)'*';
  puts(buf);
 /* set up game grid top border and display */
  for(iTa = 0; iTa < 10; iTa++)
  {
    if(iTa == y)
    {
      printf(" |*%s*|\n", GC->C[iTa].L);
   /* print cursor markers and line */
    }
    else
    {
       printf(" | %s |\n", GC->C[iTa].L);
   /* print game grid border and line */
    }
  }
 /* display game grid and left/right borders */
  puts(buf);
  puts(top_bottom);
 /* set up and display game grid bottom border */
  printf("\nPoints  :%d\n", GC->Score);
  printf("Moves   :%d\n", GBs->Move);
  printf("Location %d,%d\n", x, y);
 /* display current game info */
}
/*_|_|  end numdrop4.c  v4.4  Part 1 of 6  _|_|*/

--- BBBS/LiI v4.01 Flag-5
 * Origin: Prism's_Point (1:261/38.1)
SEEN-BY: 633/267 270
@PATH: 261/38 123/500 106/2000 633/267


<<< Previous Index Next >>>