本文整理汇总了Python中Game.Game.finished方法的典型用法代码示例。如果您正苦于以下问题:Python Game.finished方法的具体用法?Python Game.finished怎么用?Python Game.finished使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Game.Game
的用法示例。
在下文中一共展示了Game.finished方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: Test
# 需要导入模块: from Game import Game [as 别名]
# 或者: from Game.Game import finished [as 别名]
class Test(unittest.TestCase):
def setUp(self):
self.game = Game()
self.redPlayer = Player(PlayerColor.Red, Strategy())
self.bluePlayer = Player(PlayerColor.Blue, Strategy())
self.yellowPlayer = Player(PlayerColor.Yellow, Strategy())
self.greenPlayer = Player(PlayerColor.Green, Strategy())
for p in [self.redPlayer, self.bluePlayer, self.yellowPlayer, self.greenPlayer]:
self.game.addPlayer(p)
def testAddingPlayer(self):
self.game = Game()
self.assertEqual(self.game.playerCount(), 0, "no player at start")
self.game.addPlayer(self.redPlayer)
self.assertEqual(self.game.playerCount(), 1, "one player added")
self.game.addPlayer(self.bluePlayer)
self.assertEqual(self.game.playerCount(), 2, "two players added")
def testGameFinished(self):
self.assertFalse(self.game.finished(), "game should not be finished at start")
def testPlayerOrderAtStart(self):
self.assertEqual(self.game.playerCount(), 4, "all four players added")
self.assertListEqual([self.redPlayer, self.bluePlayer, self.yellowPlayer, self.greenPlayer],
self.game.getPlayers())
def testPlayerOrderScore(self):
self.redPlayer.addScore(3)
self.bluePlayer.addScore(2)
self.yellowPlayer.addScore(4)
self.greenPlayer.addScore(2)
self.assertListEqual([self.yellowPlayer, self.redPlayer, self.bluePlayer, self.greenPlayer],
self.game.getPlayers())
def testPlayerOrderSecondCriteria(self):
self.bluePlayer.addResources([3])
self.assertEqual(self.game.playerCount(), 4, "all four players added")
self.assertListEqual([self.bluePlayer, self.redPlayer, self.yellowPlayer, self.greenPlayer],
self.game.getPlayers())
def testMixedScores(self):
self.redPlayer.addResources([3,3,3,3,4,5,5])
self.redPlayer.buyHut(SimpleHut(4,5,5),[4,5,5])
self.yellowPlayer.addResources([3,3,4,4,4,4,6,6,8,9])
self.bluePlayer.addResources([3,3,4,4,4,4,6,6,9])
self.greenPlayer.addResources([3,3,4,4,4,4,6,6,9])
self.assertListEqual([self.redPlayer, self.yellowPlayer, self.bluePlayer, self.greenPlayer],
self.game.getPlayers())
示例2: Test
# 需要导入模块: from Game import Game [as 别名]
# 或者: from Game.Game import finished [as 别名]
class Test(unittest.TestCase):
def setUp(self):
self.game = Game()
def testAddingPlayer(self):
self.assertEqual(self.game.playerCount(), 0, "no player at start")
self.game.addPlayer(Player("Red", Strategy()))
self.assertEqual(self.game.playerCount(), 1, "one player added")
def testGameFinished(self):
self.assertFalse(self.game.finished(), "game should not be finished at start")
示例3: play
# 需要导入模块: from Game import Game [as 别名]
# 或者: from Game.Game import finished [as 别名]
def play():
game = Game()
print(game.current_board())
while True:
prompt = "Player %s>> " % game.current_player()
index = list(map(int,list(input(prompt))))
try:
game.move(index)
except RuntimeError:
print("That position has already been used")
continue
except IndexError:
print("Invalid position specified")
continue
print(game.current_board())
if game.finished():
print("Player %s wins!" % game.current_player())
break
game.next()
示例4: TTTGame
# 需要导入模块: from Game import Game [as 别名]
# 或者: from Game.Game import finished [as 别名]
class TTTGame(Widget):
def __init__(self,**kwargs):
super(TTTGame,self).__init__(**kwargs)
self.size_hint = (1,1)
self.internal_game = Game()
def getCenter(self):
c_x = int(self.center_x)
c_y = int(self.center_y)
return (c_x,c_y)
def oneThird_region(self):
onethird_x = int(self.center_x/3)
onethird_y = int(self.center_y/3)
return (onethird_x,onethird_y)
def getRegions_x(self):
(cx,cy) = self.getCenter()
(onethird_x,onethird_y) = self.oneThird_region()
region0 = [0,cx - onethird_x]
region1 = [cx - onethird_x,cx + onethird_x]
region2 = [cx + onethird_x,self.width]
return [region0,region1,region2]
def getRegions_y(self):
(cx,cy) = self.getCenter()
(onethird_x,onethird_y) = self.oneThird_region()
region0 = [cy + onethird_y,self.height]
region1 = [cy - onethird_y,cy + onethird_y]
region2 = [0,cy - onethird_y]
return [region0,region1,region2]
def get_index(self,position,regions):
index = 0
for region in regions:
if position in range(*region):
cord = index
index += 1
return index
def on_touch_down(self,touch):
x_regions = self.getRegions_x()
y_regions = self.getRegions_y()
print(str(x_regions))
touchX,touchY = (int(touch.x),int(touch.y))
print("TouchX: "+str(touchX))
X_cord = get_index(touchX,x_regions)
Y_cord = get_index(touchY,y_regions)
cord = [X_cord,Y_cord]
self.advance_game(cord)
def draw_letter(self,x,y,letter):
letter = Label(text=letter,font_size=70)
x_region = self.getRegions_x()[x]
y_region = self.getRegions_y()[y]
letter.center_x = (x_region[0]+x_region[1])/2
letter.top = (y_region[0]+y_region[1])/2
self.add_widget(letter)
def advance_game(self,cord):
try:
self.internal_game.move(cord)
print(self.internal_game.current_board())
if self.internal_game.finished():
print("Player %s wins!!" % self.internal_game.current_player())
sys.exit(0)
self.draw_letter(cord[0],cord[1],self.internal_game.current_player())
self.internal_game.next()
except IndexError:
print("Invalid board position")
except RuntimeError:
print("That position has already beed used")