Skip to content

Commit 5c6ab5e

Browse files
author
Ye
committed
update ...
1 parent a4f2099 commit 5c6ab5e

File tree

2 files changed

+8
-7
lines changed

2 files changed

+8
-7
lines changed

game2048.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ def _create_tiles(self):
2323
self._grid[avail] = new_tiles
2424

2525
def step(self, direction):
26-
self._grid[self._grid%10==0] /= 10
26+
self._grid[self._grid%10==0] //= 10
2727
merge_v, merge_h, grid_copy = copy(self._grid), copy(rot90(self._grid)), copy(self._grid)
2828
map(Game2048._merge_down, [merge_v, merge_h]) # try to merge tiles along two directions
2929
if merge_v[isnan(merge_v)].size is 0 and merge_h[isnan(merge_h)].size is 0: # Check if game is over
@@ -41,7 +41,7 @@ def step(self, direction):
4141

4242
def get_grid(self):
4343
grid = copy(self._grid)
44-
grid[grid%10==0] /= 10
44+
grid[grid%10==0] //= 10
4545
return grid
4646

4747
def get_new_tiles(self):
@@ -51,3 +51,4 @@ def get_new_tiles(self):
5151

5252
def get_score(self):
5353
return self._score
54+

main.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
from Tkinter import Tk, Label, Frame, BOTH
2-
from tkFont import Font
1+
from tkinter import Tk, Label, Frame, BOTH
2+
from tkinter.font import Font
33
from game2048 import Game2048, UP, DOWN, LEFT, RIGHT, ndenumerate, copy, isnan
44

55
key_map = {'Up': UP, 'Down': DOWN, 'Left': LEFT, 'Right': RIGHT}
@@ -33,10 +33,10 @@ def input_listener(event=None, game=None, tk_root=None, labels=None):
3333

3434
grid, labels = game.get_grid(), []
3535
for (i, j), value in ndenumerate(grid):
36-
frame = Frame(root, width=window_size/4-2, height=window_size/4-2)
37-
font = Font(family='Helvetica', weight='bold', size=window_size/15)
36+
frame = Frame(root, width=window_size//4-2, height=window_size//4-2)
37+
font = Font(family='Helvetica', weight='bold', size=window_size//15)
3838
frame.pack_propagate(0)
39-
frame.place(x=j*window_size/4+1, y=i*window_size/4+1)
39+
frame.place(x=j*window_size//4+1, y=i*window_size//4+1)
4040
(text, color) = ('', color_map['base']) if isnan(value) else ('{}'.format(int(value)), color_map[value][0])
4141
label = Label(frame, text=text, font=font, fg=color, bg=color_map['base'] if isnan(value) else color_map[value][1])
4242
label.pack(fill=BOTH, expand=True)

0 commit comments

Comments
 (0)