diff options
| author | Max <mahn.maxwell@gmail.com> | 2021-10-20 13:48:58 -0400 |
|---|---|---|
| committer | Max <mahn.maxwell@gmail.com> | 2021-10-20 13:48:58 -0400 |
| commit | 5129fa3b2a45d4e1a61aa0c4043a9958c462a3bf (patch) | |
| tree | 1c05750df6dc327927d9fd9fd9b310a2724785d9 | |
| parent | c426d7718b75574c3073810f4283ed492b4f9841 (diff) | |
prettier and score
| -rw-r--r-- | main.py | 25 |
1 files changed, 13 insertions, 12 deletions
@@ -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 |
