本文整理汇总了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())
示例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':
示例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)