Return to Python 3.X
This commit is contained in:
parent
fe0c8d24b3
commit
fcacd497d6
36
terminis.py
36
terminis.py
@ -11,6 +11,7 @@ except ImportError:
|
|||||||
import random
|
import random
|
||||||
import sched
|
import sched
|
||||||
import time
|
import time
|
||||||
|
import functools
|
||||||
|
|
||||||
|
|
||||||
# You can change controls here.
|
# You can change controls here.
|
||||||
@ -60,14 +61,14 @@ class Rotation:
|
|||||||
|
|
||||||
|
|
||||||
class Color:
|
class Color:
|
||||||
BLACK = curses.COLOR_BLACK
|
BLACK = 0
|
||||||
WHITE = curses.COLOR_WHITE
|
WHITE = 1
|
||||||
YELLOW = curses.COLOR_YELLOW
|
YELLOW = 2
|
||||||
RED = curses.COLOR_RED
|
RED = 3
|
||||||
GREEN = curses.COLOR_GREEN
|
GREEN = 4
|
||||||
BLUE = curses.COLOR_BLUE
|
BLUE = 5
|
||||||
MAGENTA = curses.COLOR_MAGENTA
|
MAGENTA = 6
|
||||||
CYAN = curses.COLOR_CYAN
|
CYAN = 7
|
||||||
ORANGE = 8
|
ORANGE = 8
|
||||||
|
|
||||||
|
|
||||||
@ -94,7 +95,7 @@ class Screen:
|
|||||||
curses.init_pair(Color.RED, curses.COLOR_RED+8, curses.COLOR_RED+8)
|
curses.init_pair(Color.RED, curses.COLOR_RED+8, curses.COLOR_RED+8)
|
||||||
curses.init_pair(Color.GREEN, curses.COLOR_GREEN+8, curses.COLOR_GREEN+8)
|
curses.init_pair(Color.GREEN, curses.COLOR_GREEN+8, curses.COLOR_GREEN+8)
|
||||||
curses.init_pair(Color.YELLOW, curses.COLOR_YELLOW+8, curses.COLOR_YELLOW+8)
|
curses.init_pair(Color.YELLOW, curses.COLOR_YELLOW+8, curses.COLOR_YELLOW+8)
|
||||||
curses.init_pair(Color.BLUE, curses.COLOR_BLUE, curses.COLOR_BLUE+8)
|
curses.init_pair(Color.BLUE, curses.COLOR_BLUE+8, curses.COLOR_BLUE+8)
|
||||||
curses.init_pair(Color.MAGENTA, curses.COLOR_MAGENTA+8, curses.COLOR_MAGENTA+8)
|
curses.init_pair(Color.MAGENTA, curses.COLOR_MAGENTA+8, curses.COLOR_MAGENTA+8)
|
||||||
curses.init_pair(Color.CYAN, curses.COLOR_CYAN+8, curses.COLOR_CYAN+8)
|
curses.init_pair(Color.CYAN, curses.COLOR_CYAN+8, curses.COLOR_CYAN+8)
|
||||||
curses.init_pair(Color.WHITE, curses.COLOR_CYAN+8, curses.COLOR_CYAN+8)
|
curses.init_pair(Color.WHITE, curses.COLOR_CYAN+8, curses.COLOR_CYAN+8)
|
||||||
@ -309,8 +310,12 @@ class Window:
|
|||||||
if self.TITLE:
|
if self.TITLE:
|
||||||
self.title_begin_x = (width-len(self.TITLE)) // 2 + 1
|
self.title_begin_x = (width-len(self.TITLE)) // 2 + 1
|
||||||
self.piece = None
|
self.piece = None
|
||||||
self.has_colors = curses.has_colors()
|
|
||||||
|
|
||||||
|
@property
|
||||||
|
@functools.lru_cache()
|
||||||
|
def has_colors(self):
|
||||||
|
return curses.has_colors()
|
||||||
|
|
||||||
def draw_border(self):
|
def draw_border(self):
|
||||||
self.window.erase()
|
self.window.erase()
|
||||||
self.window.border()
|
self.window.border()
|
||||||
@ -343,7 +348,7 @@ class Matrix(Window):
|
|||||||
def __init__(self, game, begin_x, begin_y):
|
def __init__(self, game, begin_x, begin_y):
|
||||||
begin_x += (game.WIDTH - self.WIDTH) // 2
|
begin_x += (game.WIDTH - self.WIDTH) // 2
|
||||||
begin_y += (game.HEIGHT - self.HEIGHT) // 2
|
begin_y += (game.HEIGHT - self.HEIGHT) // 2
|
||||||
Window.__init__(self, self.WIDTH, self.HEIGHT, begin_x, begin_y)
|
super().__init__(self.WIDTH, self.HEIGHT, begin_x, begin_y)
|
||||||
self.game = game
|
self.game = game
|
||||||
self.cells = [
|
self.cells = [
|
||||||
[None for x in range(self.NB_COLS)]
|
[None for x in range(self.NB_COLS)]
|
||||||
@ -390,7 +395,7 @@ class Hold(Window):
|
|||||||
PIECE_POSITION = Point(6, 3)
|
PIECE_POSITION = Point(6, 3)
|
||||||
|
|
||||||
def __init__(self, width, begin_x, begin_y):
|
def __init__(self, width, begin_x, begin_y):
|
||||||
Window.__init__(self, width, self.HEIGHT, begin_x, begin_y)
|
super().__init__(width, self.HEIGHT, begin_x, begin_y)
|
||||||
|
|
||||||
def refresh(self, paused=False):
|
def refresh(self, paused=False):
|
||||||
self.draw_border()
|
self.draw_border()
|
||||||
@ -405,7 +410,7 @@ class Next(Window):
|
|||||||
PIECE_POSITION = Point(6, 3)
|
PIECE_POSITION = Point(6, 3)
|
||||||
|
|
||||||
def __init__(self, width, begin_x, begin_y):
|
def __init__(self, width, begin_x, begin_y):
|
||||||
Window.__init__(self, width, self.HEIGHT, begin_x, begin_y)
|
super().__init__(width, self.HEIGHT, begin_x, begin_y)
|
||||||
self.window = curses.newwin(self.HEIGHT, width, begin_y, begin_x)
|
self.window = curses.newwin(self.HEIGHT, width, begin_y, begin_x)
|
||||||
|
|
||||||
def refresh(self, paused=False):
|
def refresh(self, paused=False):
|
||||||
@ -427,7 +432,7 @@ class Stats(Window):
|
|||||||
TITLE = "STATS"
|
TITLE = "STATS"
|
||||||
|
|
||||||
def __init__(self, width, height, begin_x, begin_y, level):
|
def __init__(self, width, height, begin_x, begin_y, level):
|
||||||
Window.__init__(self, width, height, begin_x, begin_y)
|
super().__init__(width, height, begin_x, begin_y)
|
||||||
self.width = width
|
self.width = width
|
||||||
self.height = height
|
self.height = height
|
||||||
self.level = level - 1
|
self.level = level - 1
|
||||||
@ -439,7 +444,7 @@ class Stats(Window):
|
|||||||
except:
|
except:
|
||||||
self.high_score = 0
|
self.high_score = 0
|
||||||
self.time = time.time()
|
self.time = time.time()
|
||||||
self.clock_timer = scheduler.enter(1, 2, self.refresh, tuple())
|
self.clock_timer = scheduler.enter(1, 2, self.refresh)
|
||||||
self.lines_cleared = 0
|
self.lines_cleared = 0
|
||||||
|
|
||||||
def refresh(self):
|
def refresh(self):
|
||||||
@ -669,3 +674,4 @@ def main():
|
|||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
main()
|
main()
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user