def roll_dice(request): player = Player.objects.get(session_id=request.session.session_key) # Lock the game - shouldn't be like that game = player.game game.in_progress = True game.save() # Roll two dice - will be random at some point (dice1, dice2) = rules.roll_dice() # Can't roll more than once (except when it's a double) if player.rolled_this_turn: return HttpResponse(FAILURE) # If it's a double, the player can roll twice. if dice1 != dice2: player.rolled_this_turn = True player.save() # Handle player movement rules.move_player(player, (dice1, dice2)) player.save() return HttpResponse( json.dumps({ 'success': True, 'dice1': dice1, 'dice2': dice2, 'square': player.square.position }))
def roll_dice(request): player = Player.objects.get(session_id=request.session.session_key) # Lock the game - shouldn't be like that game = player.game game.in_progress = True game.save() # Roll two dice - will be random at some point (dice1, dice2) = rules.roll_dice(); # Can't roll more than once (except when it's a double) if player.rolled_this_turn: return HttpResponse(FAILURE) # If it's a double, the player can roll twice. if dice1 != dice2: player.rolled_this_turn = True player.save() # Handle player movement rules.move_player(player, (dice1, dice2)) player.save() return HttpResponse(json.dumps( { 'success': True, 'dice1': dice1, 'dice2': dice2, 'square': player.square.position }))
def test_pay_rent_mortgaged_utility(self): utility = Square.objects.get(game=self.game, position=5).utility self.set_bought(self.john, utility) self.set_mortgaged(utility) money_before = self.mary.player().money rules.move_player(self.mary.player(), (0, 5)) self.assertEquals(self.mary.player().money, money_before)
def test_pay_rent_mortgaged_property(self): property = Square.objects.get(game=self.game, position=1).property self.set_bought(self.john, property) self.set_mortgaged(property) money_before = self.mary.player().money rules.move_player(self.mary.player(), (0, 1)) self.assertEquals(self.mary.player().money, money_before)
def test_pay_rent_your_property(self): self.set_bought( self.john, Square.objects.get(game=self.game, position=1).property) money_before = self.john.player().money rules.move_player(self.john.player(), (0, 1)) self.assertEquals(self.john.player().money, money_before)
def setUp(self): Client().get('/new_game/public', follow=True) self.game = Game.objects.all()[0] self.game.player_set.all().delete( ) # Delete dummy player that created the game self.john = Client() self.mary = Client() self.john.get('/game/{0}/'.format(self.game.id), follow=True) self.mary.get('/game/{0}/'.format(self.game.id), follow=True) self.money_before = self.john.player().money rules.move_player(self.john.player(), (30, 0)) # Roll a 30 to land on "Go to jail"
def test_pay_rent_multiple_utilities(self): self.set_bought(self.john, Square.objects.get(game=self.game, position=5).utility) self.set_bought( self.john, Square.objects.get(game=self.game, position=12).utility) self.set_bought( self.john, Square.objects.get(game=self.game, position=15).utility) money_before = self.mary.player().money rules.move_player(self.mary.player(), (0, 5)) utility = Square.objects.get(game=self.game, position=5).utility self.assertEquals(self.mary.player().money, money_before - utility.tax_site * 3)
def test_jail_liberate_by_dice(self): rules.move_player(self.john.player(), (1, 1)) self.assertFalse(self.john.player().is_in_jail()) self.assertEquals(self.john.player().money, self.money_before)
def test_jail_stay_for_three_turns(self): for t in range(3): self.assertTrue(self.john.player().is_in_jail()) rules.move_player(self.john.player(), (3, 5)) self.assertFalse(self.john.player().is_in_jail()) self.assertEquals(self.john.player().money, self.money_before - 50)