From 5129fa3b2a45d4e1a61aa0c4043a9958c462a3bf Mon Sep 17 00:00:00 2001 From: Max Date: Wed, 20 Oct 2021 13:48:58 -0400 Subject: prettier and score --- main.py | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/main.py b/main.py index 5c0c1f9..e194b47 100644 --- a/main.py +++ b/main.py @@ -4,11 +4,11 @@ import random # h a left key_left = [104, 97, 68] -# l d +# l d right key_right = [108, 100, 67] -# j s +# j s down key_down = [106, 115, 66] -# k w +# k w up key_up = [107, 119, 65] @@ -26,6 +26,8 @@ gamestate = [[0 for mx in range(maxX)] for my in range(maxY)] # INIT +global score +score = 0 stdscr = curses.initscr() curses.noecho() curses.curs_set(0) @@ -49,10 +51,6 @@ curses.init_pair(4, curses.COLOR_CYAN, curses.COLOR_BLACK) curses.init_pair(5, curses.COLOR_BLUE, curses.COLOR_BLACK) curses.init_pair(6, curses.COLOR_MAGENTA, curses.COLOR_BLACK) curses.init_pair(7, curses.COLOR_WHITE, curses.COLOR_BLACK) -curses.init_pair(8, curses.COLOR_BLACK, curses.COLOR_RED) -curses.init_pair(9, curses.COLOR_BLACK, curses.COLOR_YELLOW) -curses.init_pair(10, curses.COLOR_BLACK, curses.COLOR_GREEN) -curses.init_pair(11, curses.COLOR_BLACK, curses.COLOR_CYAN) # GRAPHICS @@ -61,24 +59,25 @@ def DrawSquare(x, y, val, box_color): val_len = len(str(val)) if val_len > 4: val_len = 4 - gamewin.addstr(y, x, "+" + "-" * (scaleX - 2) + "+", curses.color_pair(box_color)) - gamewin.addstr(y + 1, x, "|" + " " * math.ceil((4-val_len)/2) + str(val) + " " * math.floor((4-val_len)/2) + "|", curses.color_pair(box_color)) - gamewin.addstr(y + 2, x, "+" + "-" * (scaleX - 2) + "+", curses.color_pair(box_color)) + gamewin.addstr(y, x, "+" + "-" * (scaleX - 2) + "+", box_color) + gamewin.addstr(y + 1, x, "|" + " " * math.ceil((4-val_len)/2) + str(val) + " " * math.floor((4-val_len)/2) + "|", box_color) + gamewin.addstr(y + 2, x, "+" + "-" * (scaleX - 2) + "+", box_color) def FullDraw(): gamewin.clear() gamewin.box() + gamewin.addstr(0, math.floor((maxX * scaleX - len(str(score))) / 2), str(score), curses.A_BOLD) for i in range(maxY): for j in range(maxX): if gamestate[i][j] == 0: continue color = 1 try: - color = int(math.log(gamestate[i][j]) / math.log(2)) + color = int(math.log(gamestate[i][j]) / math.log(2)) - 1 # I gotta subtract one here so I can add it back in a few lines cuz the modulus will return zero in one instance. except: pass - DrawSquare(offsetX + j * scaleX, offsetY + i * scaleY, gamestate[i][j], color) + DrawSquare(offsetX + j * scaleX, offsetY + i * scaleY, gamestate[i][j], curses.color_pair((color % 8) + 1) + curses.A_BOLD * math.floor(color / 7)) # PROCESSING @@ -89,6 +88,8 @@ def Process(list_in): if list_in[i] == list_in[i + 1]: list_in[i] = 2 * list_in[i] del list_in[i + 1] + global score + score += list_in[i] i += 1 return list_in -- cgit v1.2.3