From fa5d961a81e4d69cb15d0f7588044a02dcb3354b Mon Sep 17 00:00:00 2001 From: h45-taylor <harvey.taylor3@live.uwe.ac.uk> Date: Wed, 10 Jan 2024 21:19:52 +0000 Subject: [PATCH] added movement function discription to README file --- README.md | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 4211b85..c63fc52 100644 --- a/README.md +++ b/README.md @@ -57,9 +57,16 @@ I initilise a variable to hold the user input and then output to ask for movemen I then use a switch statement to match what key was pressed and to run a function to move the board in the respected way that was inputted. +### Move Functions + +Because they are all similar i will just combine them all together like how only one has commments on it in the code. I will just explain `Moveleft`. For the movement functions i first created a for loop that loops through all of the rows on the grid then there is another for loop. While it loops through it checks if the current tile is empty and if it is it will find the first number tile on the right making it position `[i] [k]` and move it left to the current position `[i] [j]` then sets the current postion `[i] [j]` to empty or 0. +We then use an else statement to try and merge tiles if the current tile isnt empty is done by checking if the tile next to it is empty `board[i][k] != 0` if `[i][k]` isnt 0 then i check if the current position `[i][j]` matches with the target position `[i][k]` if it does then i merge them by multiplying the leftmost one `[i][k]` by itsself and setting the other one to 0 and setting the movement bool to true. + +The only differences between the others is that `moveright` checks for merges on the right. `moveup` and `movedown` loops through the grid column then rows whereas move right and left loops though row then column. + ### How To Run - Compile using "g++ main.cpp 2048.cpp -o 2048" + Compile using "clang++ main.cpp 2048.cpp -o 2048" Then run using ./2048 #### How To Play -- GitLab