mirror of
https://github.com/jeremysrand/apple2048.git
synced 2024-06-08 06:29:30 +00:00
More basic gameplay work. Now we set a random seed based on the time the user looks at the instructions
This commit is contained in:
parent
0902ec0f79
commit
910b2aa1ad
39
apple2048.c
39
apple2048.c
|
@ -5,6 +5,43 @@
|
||||||
#include "game.h"
|
#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)
|
void printBoard(void)
|
||||||
{
|
{
|
||||||
tPos x;
|
tPos x;
|
||||||
|
@ -103,6 +140,8 @@ void handleNextEvent(void)
|
||||||
|
|
||||||
int main(void)
|
int main(void)
|
||||||
{
|
{
|
||||||
|
printInstructions();
|
||||||
|
|
||||||
initGame();
|
initGame();
|
||||||
|
|
||||||
while (true) {
|
while (true) {
|
||||||
|
|
3
game.c
3
game.c
|
@ -167,6 +167,9 @@ void slideInDirection(tDir dir)
|
||||||
// the same tile in a single turn. We set the value to a high
|
// the same tile in a single turn. We set the value to a high
|
||||||
// negative (< -1) and then flip the sign bit later.
|
// negative (< -1) and then flip the sign bit later.
|
||||||
gTileValues[destPos] = -tileValue;
|
gTileValues[destPos] = -tileValue;
|
||||||
|
|
||||||
|
if (tileValue == gNextTarget)
|
||||||
|
gNextTarget++;
|
||||||
} else {
|
} else {
|
||||||
gTileValues[destPos] = gTileValues[pos];
|
gTileValues[destPos] = gTileValues[pos];
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user