当前位置: 首页>>代码示例>>Python>>正文


Python Game.end方法代码示例

本文整理汇总了Python中term2048.game.Game.end方法的典型用法代码示例。如果您正苦于以下问题:Python Game.end方法的具体用法?Python Game.end怎么用?Python Game.end使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在term2048.game.Game的用法示例。


在下文中一共展示了Game.end方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: TestGame

# 需要导入模块: from term2048.game import Game [as 别名]
# 或者: from term2048.game.Game import end [as 别名]
class TestGame(unittest.TestCase):

    def setUp(self):
        Board.SIZE = _BSIZE
        Game.SCORES_FILE = None
        self.g = Game(scores_file=None)
        self.b = self.g.board

    def test_init_with_size_3_goal_4(self):
        g = Game(size=3, goal=4, scores_file=None)
        self.assertEqual(g.board.size(), 3)

    # == .saveBestScore == #

    def test_save_best_score_no_file(self):
        self.g.score = 42
        self.g.saveBestScore()
        self.assertEqual(self.g.best_score, 42)

    # == .end == #

    def test_end_can_play(self):
        self.assertFalse(self.g.end())

    # == .getCellStr == #

    def test_getCellStr_unknown_number(self):
        self.b.setCell(0, 0, 0)
        self.assertEqual(self.g.getCellStr(0, 0), '  .')

    def test_getCellStr_unknown_number(self):
        self.b.setCell(0, 0, 42)
        self.assertEqual(self.g.getCellStr(0, 0),
                '%s 42%s' % (Fore.RESET, Fore.RESET))

    # == .boardToString == #

    def test_boardToString_height_no_margins(self):
        s = self.g.boardToString()
        self.assertEqual(len(s.split("\n")), self.b.size())

    # == .__str__ == #

    def test_str_height_no_margins(self):
        s = str(self.g)
        self.assertEqual(len(s.split("\n")), self.b.size())
开发者ID:JosephRedfern,项目名称:term2048,代码行数:48,代码来源:test_game.py

示例2: TestGame

# 需要导入模块: from term2048.game import Game [as 别名]
# 或者: from term2048.game.Game import end [as 别名]

#.........这里部分代码省略.........
        self.assertEqual(self.g.score, s)
        self.assertEqual(self.g.best_score, s)

    def test_inc_2_score(self):
        s = 3
        i = 2
        self.g.score = s
        self.g.best_score = s
        self.g.incScore(i)
        self.assertEqual(self.g.score, s + i)
        self.assertEqual(self.g.best_score, s + i)

    def test_inc_score_update_best_score(self):
        s = 3
        i = 2
        self.g.score = s
        self.g.best_score = 0
        self.g.incScore(i)
        self.assertEqual(self.g.score, s + i)
        self.assertEqual(self.g.best_score, s + i)

    def test_inc_score_dont_update_best_score_if_higher(self):
        s = 3
        bs = 80
        i = 2
        self.g.score = s
        self.g.best_score = bs
        self.g.incScore(i)
        self.assertEqual(self.g.score, s + i)
        self.assertEqual(self.g.best_score, bs)

    # == .end == #

    def test_end_can_play(self):
        self.assertFalse(self.g.end())

    # == .readMove == #

    def test_read_unknown_move(self):
        kp._setNextKey(-1)
        self.assertEqual(self.g.readMove(), None)

    def test_read_known_move(self):
        kp._setNextKey(kp.LEFT)
        self.assertEqual(self.g.readMove(), Board.LEFT)

    # == .loop == #

    def test_simple_win_loop(self):
        kp._setNextKey(kp.UP)
        g = Game(goal=4, size=2, clear_screen=False)
        g.board.cells = [
            [2, 0],
            [2, 0]
        ]
        g.loop()

    def test_simple_win_loop_clear(self):
        kp._setNextKey(kp.UP)
        g = Game(goal=4, size=2)
        g.board.cells = [
            [2, 0],
            [2, 0]
        ]
        self.assertEqual(g.loop(), 4)
        if os.name == 'nt':
开发者ID:Primer42,项目名称:term2048-AI,代码行数:70,代码来源:test_game.py

示例3: TestGame

# 需要导入模块: from term2048.game import Game [as 别名]
# 或者: from term2048.game.Game import end [as 别名]
class TestGame(unittest.TestCase):

    def setUp(self):
        Board.SIZE = _BSIZE
        Game.SCORES_FILE = None
        self.g = Game(scores_file=None)
        self.b = self.g.board

    def test_init_with_size_3_goal_4(self):
        g = Game(size=3, goal=4, scores_file=None)
        self.assertEqual(g.board.size(), 3)

    # == .end == #

    # == .saveBestScore == #

    def test_save_best_score_no_file(self):
        self.g.score = 42
        self.g.saveBestScore()
        self.assertEqual(self.g.best_score, 42)

    def test_save_best_score_with_file(self):
        scores_file = NamedTemporaryFile(delete=True)
        g = Game(scores_file=scores_file.name)
        g.best_score = 0
        g.score = 1000
        g.saveBestScore()
        self.assertEqual(g.best_score, 1000)

    # == .end == #

    def test_end_can_play(self):
        self.assertFalse(self.g.end())

    # == .getCellStr == #

    def test_getCellStr_unknown_number(self):
        self.b.setCell(0, 0, 0)
        self.assertEqual(self.g.getCellStr(0, 0), '  .')

    def test_getCellStr_unknown_number(self):
        self.b.setCell(0, 0, 42)
        self.assertEqual(self.g.getCellStr(0, 0),
                '%s 42%s' % (Fore.RESET, Fore.RESET))

    def test_getCellStr_unknown_number_azmode(self):
        g = Game(azmode=True)
        g.board.setCell(0, 0, 0)
        self.assertEqual(g.getCellStr(0, 0), '.')

    def test_getCellStr_unknown_number_azmode(self):
        g = Game(azmode=True)
        g.board.setCell(0, 0, 42)
        self.assertEqual(g.getCellStr(0, 0), '?')

    # == .boardToString == #

    def test_boardToString_height_no_margins(self):
        s = self.g.boardToString()
        self.assertEqual(len(s.split("\n")), self.b.size())

    # == .__str__ == #

    def test_str_height_no_margins(self):
        s = str(self.g)
        self.assertEqual(len(s.split("\n")), self.b.size())

    # == .loadBestScore == #

    def test_init_with_local_scores_file(self):
        scores_file = NamedTemporaryFile(delete=False)
        scores_file.write('2048'.encode())
        scores_file.close()

        g = Game(scores_file=scores_file.name)
        self.assertEqual(g.best_score, 2048)

        remove(scores_file.name)

    def test_init_with_local_scores_file_fail(self):
        scores_file = NamedTemporaryFile(delete=False)
        scores_file.close()

        g = Game(scores_file=scores_file.name)

        remove(scores_file.name)
开发者ID:techgaun,项目名称:term2048,代码行数:88,代码来源:test_game.py


注:本文中的term2048.game.Game.end方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。