Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updated with #6 #39

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 28 additions & 8 deletions 2048_.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import random, pygame, sys
from pygame.locals import *
from random import randint
from time import sleep
import copy
import math
#defining the window size and other different specifications of the window
Expand Down Expand Up @@ -60,28 +61,31 @@
LEFT = 'left'
RIGHT = 'right'

TABLE=[[0,0,0,0],[0,0,0,0],[0,0,0,0],[0,0,0,0]]

def main():
global FPSCLOCK, screen, BASICFONT
global FPSCLOCK, screen, BASICFONT, game_over

game_over = True

pygame.init()
FPSCLOCK = pygame.time.Clock()
screen = pygame.display.set_mode((WINDOWWIDTH, WINDOWHEIGHT))
BASICFONT = pygame.font.Font('freesansbold.ttf', 18)
pygame.display.set_caption('2048')

showStartScreen()

while True:
runGame(TABLE)
gameover()
if game_over:
showStartScreen()
game_over = False
TABLE = [[0 for i in range(4)] for i in range(4)]

runGame(TABLE)


def showStartScreen():
#the start screen
titleFont = pygame.font.Font('freesansbold.ttf', 100)
titleSurf1 = titleFont.render('2048', True, WHITE, ORANGE)

drawPressKeyMsg()

while True:
Expand Down Expand Up @@ -156,6 +160,7 @@ def show(TABLE):
pygame.display.update()

def runGame(TABLE):
global game_over
TABLE=randomfill(TABLE)
TABLE=randomfill(TABLE)
show(TABLE)
Expand All @@ -181,7 +186,22 @@ def runGame(TABLE):
if new_table != TABLE:
TABLE=randomfill(new_table)
show(TABLE)


if gameOver(TABLE):
print 'Game over'
game_over=True
return

def gameOver(TABLE):
temp = TABLE
k = 0

for desired_key in ['w','s','a','d']:
new_table = key(desired_key, copy.deepcopy(TABLE))
if new_table == temp: k+=1

return k==4

def key(DIRECTION,TABLE):
if DIRECTION =='w':
for pi in range(1,4):
Expand Down