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


Python Game.start方法代码示例

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


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

示例1: test_gameplay

# 需要导入模块: from models import Game [as 别名]
# 或者: from models.Game import start [as 别名]
    def test_gameplay(self):
        #Make a game, game master
        game_master = make_users(1)[0]
        self.session.add(game_master)
        self.session.flush()
        game = Game(title='test game', password='testpassword', starting_money=3)
        self.session.add(game)
        self.session.flush()
        game.add_game_master(game_master)
        games_from_db = self.session.query(Game).all()
        self.assertEqual(1, len(games_from_db))
        self.assertEqual(game, games_from_db[0]) 
        
        #Make 3 players, and add them to the game.
        #Don't start the game yet; make sure no missions exist until we start.
        players = make_users(3)
        self.session.add_all(players)
        self.session.flush()
        game.add_users(players)
        self.assertEqual(0, len(game.get_missions()))
        game.start()
        #Now that we've started, each player should have a target, so there should be 3 missions
        self.assertTrue(game.started)
        self.assertEqual(3, len(game.get_missions()))
        
        #Get player 0's mission, and then shoot his target
        player_0_mission = self.session.query(Mission).filter_by(game_id=game.id, assassin_id=players[0].id).one()
        
        #Grab player 0's target's mission to make sure reassignment works
        player_0s_target_id = player_0_mission.target_id
        player_0s_targets_mission = self.session.query(Mission).filter_by(game_id=game.id, assassin_id=player_0s_target_id).one()
        
        #Fire away; this is valid!
        player_0_shooting_target = Shot(assassin_id=players[0].id, \
                                        target_id=player_0_mission.target_id, \
                                        game_id=game.id, \
                                        shot_picture='www.foo.com/headshot.jpg')
        self.session.add(player_0_shooting_target)
        self.session.flush()
        self.assertTrue(player_0_shooting_target.is_valid())
        
#        #Wait 90 minutes and then shoot again; this should work.
#        player_0_shooting_target = Shot(assassin_id=players[0].id, \
#                                        target_id=player_0_mission.target_id, \
#                                        game_id=game.id, \
#                                        shot_picture='www.foo.com/headshot.jpg')
#        self.session.add(player_0_shooting_target)
#        self.session.flush()
#        self.assertTrue(player_0_shooting_target.is_valid())
        
        
        #THIS CAN BE REFACTORED AND PROBABLY SHOULD BE
        pre_confirm_timestamp = datetime.datetime.now()
#        player_0_shooting_target.confirm_kill()
        game.mission_completed(player_0_mission)
        #Make sure the mission's completion time is updated when mission is confirmed
        self.assertTrue(player_0_mission.completed_timestamp - player_0_mission.assignment_timestamp < datetime.timedelta(seconds=10))
        #Game shouldn't be marked completed
        self.assertFalse(game.over)
        
        
        #Get player 0's new mission.  It should not be completed because that player is still alive since player 0's target did not kill his target.
        player_0_new_mission = self.session.query(Mission).filter_by(game_id=game.id, assassin_id=players[0].id, completed_timestamp=None).one()
        #Make sure that player 0's new mission is targeting whoever his original target was targeting
        self.assertEqual(player_0_new_mission.target_id, player_0s_targets_mission.target_id)
        
        #Player 0 waits 90 minutes and kills his second target; the only other remaining player of the game.
        player_0_shooting_target_2 = Shot(assassin_id=players[0].id, \
                                        target_id=player_0_new_mission.target_id, \
                                        game_id=game.id, \
                                        shot_picture='www.foo.com/headshot2.jpg',
                                        timestamp=datetime.datetime.now() + datetime.timedelta(minutes=90))
        self.assertTrue(player_0_shooting_target_2.is_valid())
        self.assertFalse(game.over)
        
        #THIS CAN BE REFACTORED AND PROBABLY SHOULD BE
        pre_confirm_timestamp = datetime.datetime.now()
#        player_0_shooting_target_2.confirm_kill()
        game.mission_completed(player_0_new_mission)
        #Make sure the mission's completion time is updated when mission is confirmed and that it's more recent than the assignment one.
        self.assertTrue(player_0_new_mission.completed_timestamp > player_0_new_mission.assignment_timestamp)
        
        #Now that player 0 has killed the other two players, the game should be over.
        self.assertTrue(game.over)
        #Get the winner User model from the database from the game's get_winner() method and make sure it's player 0.
        self.assertEqual(game.get_winner(), players[0])
开发者ID:sosso,项目名称:Assassins-Server,代码行数:88,代码来源:test_functional.py


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