From 910b2aa1adb56091871cc668b0ac6646b8cc6a7b Mon Sep 17 00:00:00 2001 From: Jeremy Rand Date: Wed, 23 Jul 2014 14:11:27 -0500 Subject: [PATCH] More basic gameplay work. Now we set a random seed based on the time the user looks at the instructions --- apple2048.c | 39 +++++++++++++++++++++++++++++++++++++++ game.c | 3 +++ 2 files changed, 42 insertions(+) diff --git a/apple2048.c b/apple2048.c index 51cf1dd..a66c1a0 100644 --- a/apple2048.c +++ b/apple2048.c @@ -5,6 +5,43 @@ #include "game.h" +void printInstructions(void) +{ + int seed = 0; + + clrscr(); + printf( +// 0000000001111111111222222222233333333334 +// 1234567890123456789012345678901234567890 + " APPLE 2048\n" + "\n" + "USE I-J-K-M OR THE ARROW KEYS TO SLIDE\n" + "ALL TILES IN A DIRECTION. MATCHING\n" + "TILES ARE ADDED TOGETHER TO MAKE A NEW\n" + "TILE. ON EVERY MOVE, ONE MORE TILE IS\n" + "ADDED WITH A RANDOM VALUE OF EITHER 2\n" + "OR 4.\n" + "\n" + "PLAY ENDS WHEN ALL TILES ARE OCCUPIED\n" + "AND NO MORE MOVES ARE POSSIBLE. TRY\n" + "TO GET THE LARGEST TILE YOU CAN!\n" + "\n" + "PRESS ESCAPE OR Q TO QUIT AT ANY TIME.\n" + "PRESS R TO START A NEW GAME.\n" + "\n" + "\n" + "\n" + "\n" + " PRESS ANY KEY TO START"); + + while (!kbhit()) + seed++; + + cgetc(); + srand(seed); +} + + void printBoard(void) { tPos x; @@ -103,6 +140,8 @@ void handleNextEvent(void) int main(void) { + printInstructions(); + initGame(); while (true) { diff --git a/game.c b/game.c index 081dacd..ff8d087 100644 --- a/game.c +++ b/game.c @@ -167,6 +167,9 @@ void slideInDirection(tDir dir) // the same tile in a single turn. We set the value to a high // negative (< -1) and then flip the sign bit later. gTileValues[destPos] = -tileValue; + + if (tileValue == gNextTarget) + gNextTarget++; } else { gTileValues[destPos] = gTileValues[pos]; }