コード例 #1
0
ファイル: game.py プロジェクト: oceanchild/goobleprojects
class Game(object):
    
    def __init__(self, board=None, level=None):
        if board is None:
            board = Board()
        self.board = board
        self.score = Score()
        if level is None:
            level = 1
        self.level = level
        self.speed_modifier = 1
    
    def step(self):
        self.board.step()
        rows_cleared = self.board.get_rows_cleared()
        self.score.add_pts_for_lines(rows_cleared)
        
    def rotate(self):
        self.board.rotate()
        
    def move(self, direction):
        self.board.move(direction)
        
    def drop(self):
        self.board.drop_shape()
        
    def get_score(self):
        return self.score.get_value()
    
    def get_speed(self):
        return int(Speed().for_start_level_and_curr_score(self.level, self.score.get_value()) / self.speed_modifier)
    
    def get_pieces(self):
        return self.board.get_pieces()
    
    def is_game_over(self):
        return self.board.is_game_over()
    
    def speed_up(self):
        self.speed_modifier = 1.5
        
    def slow_down(self):
        self.speed_modifier = 1
        
    def get_next_shape(self):
        return self.board.get_next_shape()
    
    def get_current_shape(self):
        return self.board.cur_shape
    
    def get_predicted_points(self):
        return self.board.get_predicted_points()
コード例 #2
0
class Test(unittest.TestCase):

    def setUp(self):
        self.score = Score()
        self.assertEqual(0, self.score.get_value())

    def test_score_100_points_for_one_line_cleared(self):
        self.score.add_pts_for_lines(1)
        self.assertEqual(100, self.score.get_value())
        
    def test_bonus_if_four_lines_cleared(self):
        self.score.add_pts_for_lines(4)
        self.assertEqual(800, self.score.get_value())
        
    def test_if_got_two_tetris_in_a_row_bonus_points(self):
        self.score.add_pts_for_lines(4)
        self.score.add_pts_for_lines(4)
        self.assertEqual(2000, self.score.get_value())