/2048-GameCode

This is 2048 game code

Primary LanguagePython

py2048

This is 2048 game code

About this game:-

In this we want to form a number given by user by moving the numbers in the board .We can move numbers up,down ,right,left and if there are same number which are present consecutively then they merges in one and turn into twice of this number .If user unable to create given number then he loses.

NOTE:- Always give winning number in such a way that the given number is in the power of 2. i.e (2^i) where i may be 1,2,3,4,5,6..........

We can use it for size 2 and size 1 also.

In size 1 if the winning number is same as random number comes in one box then the user wins otherwise lose.

There is a file named py2048.py is 2048 game code

os.system('cls') command is used to clear screen after move.

Run this code on windows only as.system('cls')is used in code which runs in windows.

Make every move after minimum(0.5s) because without time command time.sleep(0.5s) game running very fast and it takes input twice on single key press.

To run this game in command line we have to write command:-

Capture

Modules required for this code:-

Capture1

Initializing of board

There is appending of row according to the size given by user in the empty matrix named mat.

Functions used in this code:-

a. def rowleft()

This function shifts all the rows to the left.

b. def rev()

This function used to reverse the row.

c. def transpose()

This function is used to get transpose of the matrix.

d. def merleft()

This function merges matrix to the left.

e. def merright()

This function merges matrix to the right.

f. def merdown()

This function merges matrix to down.

g. def merup()

This function merges matrix in up direction.

h.def pickvalue()

This function randomly pickly value btwn 2 and 4.

i.def addvalue()

This function add this random value at random place in mat named matrix.

j.def won()

This function checks the win condition after every move.

k.def nomove()

This function checks that there is more move available or not after every move.

Some snapshots of game:-

#Capture3 #Capture2 #Capture4

PLAY AND ENJOY!!!!