matei1608/2048
Folders and files
| Name | Name | Last commit date | ||
|---|---|---|---|---|
Repository files navigation
Creator: Matei-Cristian Lazarescu The implementation of the game took about 15 hours. To start the game, you need to open a new linux terminal inside the directory and write the commands: "make", and "make run". The Game Menu will appear. How I implemented the Game: In the main function, I call the meniu_principal function. This function generates a menu with three options: New Game, Resume, and Quit. If I select New Game, a new game starts, during which I generate two random numbers at two random positions. If I press the down arrow, the program makes a move downwards; if I press the up arrow, the program moves upwards; if I press the right arrow, the program moves to the right; and if I press the left arrow, the program moves to the left. I have a function that continuously checks if the game has been lost (I verify this using copies that simulate the moves and then check if the simulated moves are identical to the initial state). I also have a function that checks if the game has been won (if the value 2048 has been achieved). Using variables that keep track of the last input time, an automatic move occurs every 30 seconds after the last command (the most efficient move considering the remaining free spaces). If I press "q", the program pauses the game and calls the meniu_principal function, which creates the main menu. At this point, if I select Resume, the game starts from where it was paused. If I select New Game, the matrix that holds the values from the board is reinitialized to 0, and a new game begins.