Prettify output and clean up some code
This commit is contained in:
@@ -5,22 +5,22 @@ import random, copy
|
||||
def game_logic(l):
|
||||
oldHash = hash(tuple(l))
|
||||
|
||||
line_state = True
|
||||
line_active= True
|
||||
global moved
|
||||
merge = True
|
||||
while line_state:
|
||||
merged = False
|
||||
while line_active:
|
||||
for i in range(board_line-1):
|
||||
if l[i] == None and l[i+1] != None:
|
||||
mi=l.pop(i+1)
|
||||
l.pop(i)
|
||||
l.insert(i,mi)
|
||||
l.insert(i+1,None)
|
||||
elif l[i] != None and l[i] == l[i+1] and merge != False:
|
||||
elif l[i] != None and l[i] == l[i+1] and merged != True:
|
||||
mi=l.pop(i)
|
||||
l.insert(i,int(mi)*2)
|
||||
mi=l.pop(i+1)
|
||||
|
||||
l.pop(i+1)
|
||||
l.insert(i+1,None)
|
||||
merge = False
|
||||
|
||||
merged = True
|
||||
oldHash = hash(tuple(l))
|
||||
moved = True
|
||||
|
||||
@@ -28,7 +28,7 @@ def game_logic(l):
|
||||
|
||||
if oldHash == newHash:
|
||||
# print('Exiting: Boxes didn't move')
|
||||
line_state = False
|
||||
line_active = False
|
||||
else:
|
||||
# print('Repeating: Boxes moved')
|
||||
oldHash = newHash
|
||||
@@ -72,15 +72,10 @@ def movement():
|
||||
|
||||
if m != 'u' and moved == True:
|
||||
board_reset=copy.deepcopy(board_temp)
|
||||
# try:
|
||||
# direction in ['h','j','k','l']
|
||||
# print(direction)
|
||||
# except:
|
||||
# print('wtf')
|
||||
|
||||
def print_board():
|
||||
for i in range(0,board_size,board_line):
|
||||
print(board[i:i+board_line])
|
||||
print('{!s:<4}'.join(' '*(board_line+1)).format(*board[i:i+board_line]))
|
||||
|
||||
def add_number():
|
||||
global board
|
||||
|
||||
Reference in New Issue
Block a user