Skip to content

teodoradriann/2048

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

25 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

This is my approach to the 2048 game. I chose to create a user-friendly interface that is visually appealing by using various colors to mark the numbers in the cells and by adding a cute character who serves as the player’s companion in my game. The game companion is something I thought would make my game unique and charming. It is not only a mascot but also a helpful assistant that alerts you whether or not you can use a command. It always greets you with a welcome message, and if you want to exit the game, it gets upset and asks you to keep playing.

The implementation of the game took me approximately 24 hours. I chose to make the game in the basic terminal format of 80x24 because that way, the mascot and the numbers on the board were best visible, given that I couldn’t scale the text that the mascot speaks to a larger size.

–Requirement 1–

I chose to create a simple and cute menu where you can navigate using the arrow keys and select the desired option by pressing Enter. The mascot is the main attraction of the menu and greets you with a welcome message. If you choose the “New Game” option, the game will start, and you can begin playing. If you choose the “Resume” option, the game will load, and you can continue playing from where you left off. If you choose the “Load” option, the game will load the last saved game, and you can continue playing from where you left off. If you choose the “Quit” option, the game will close, and you will return to the terminal.
For this requirement, I used the drawBuddy function to draw the mascot, mainScreen to draw the main screen, and select to move the asterisk based on the selected option.

–Requirement 2–

I drew the game board using the drawTable and updateTable functions.
The updateTable function updates the game board with the numbers from the table matrix and also changes the font color based on the number in the cell. I chose to use different colors for each number to make the game more attractive. The drawTable function draws the game board with - and | and calls the updateTable function to draw the numbers in the cells.

–Requirement 3–

For this requirement, I used the moveUp, moveDown, moveLeft, and moveRight functions to move the cells up, down, left, and right. I chose to create a function for each direction to make the code easier to understand and modify. Each function moves the cells in the desired direction and checks if they match to combine them. If the cell is not empty, the function searches for similar cells on the row or column to merge them.
After each move, I checked if the game was over or not, and if it was, I displayed a “Game Over” message.

–Requirement 4–

The returnTheBestMove and numberOfNullCells functions handle the game’s ability to play by itself and choose the best move to free up the most spaces.

–Requirement 5–

In the moveCells function, I checked after each move if the game was over or not, and if it was, I displayed a “Game Over” message.

Each function is thoroughly explained in 2048.c. I put a lot of emphasis on the game’s design and wanted it to be as beautiful as possible.
Some of the most interesting features of my game are: the mascot that talks to you and provides hints about the game commands, the ability to continue the game even if you close the program, the autosave feature when quitting the program, and the overall aesthetics of the game.

The functions that move the cells and the cell movement algorithm were the most difficult to implement, and I chose an approach that was as simplistic as possible, finding a solution for each cell. If the cell is empty (0), I look for other cells below it in the case of (W) to move into its place, and I also check if they match to combine them. If a cell is not empty, I search for similar cells on the row or column to merge them.

Another interesting functionality of my game is the ability to resume a game (Load) even if you close the application. The game automatically saves the current game when you quit using the Quit option in the menu, and when you open the game again, you can enjoy the uninterrupted game from where you left off.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published