def dispatch(self, request, *args, **kwargs): self.game = Game.get_by_id(kwargs["game_id"]) user = get_user(request) self.game.check_timeout() if self.game.creator == user or self.game.opponent == user: return super(GameView, self).dispatch(request, *args, **kwargs) if not self.game.opponent and not self.game.completed: self.game.opponent = user self.game.save() hounds = [(1, 0), (3, 0), (5, 0), (7, 0)] for coords in hounds: square = self.game.get_square_by_coords(coords) if square and square.status == "Free": square.status = "Claimed" square.owner = user square.save() self.game.send_game_update() return super(GameView, self).dispatch(request, *args, **kwargs) else: messages.add_message( request, messages.ERROR, "Sorry, the selected game is not available for you.") return redirect("/lobby/")
def dispatch(self, request, *args, **kwargs): # get the game by the id self.game = Game.get_by_id(kwargs['game_id']) user = get_user(request) print('From the GameView, who is the user: {}'.format(user)) # check to see if the game is open and available for this user # if this player is the creator, just return if self.game.creator == user or self.game.opponent == user: return super(GameView, self).dispatch(request, *args, **kwargs) # if there is no opponent and the game is not yet completed, # set the opponent as this user if not self.game.opponent and not self.game.completed: self.game.opponent = user self.game.save() return super(GameView, self).dispatch(request, *args, **kwargs) else: messages.add_message(request, messages.ERROR, 'Sorry, the selected game is not available.') return redirect('/lobby/')