Commits

Chris Beelby committed 1082ce7

Changed UpFront object so that it can be built up rather than needing to specify
first and second players information at creation time.

  • Participants
  • Parent commits 6411337

Comments (0)

Files changed (3)

File upfront/game.py

             repr(self.nation), self.weapon, self.morale, self.panic, repr(self.rank))
 
 class UpFront(object):
-    def __init__(self, player1name, player1nation, player2name, player2nation):
+    def __init__(self, player1, player1nation, player2=None, player2nation=None):
         """
-        Create basic setup of an Up Front game. player1name and player2name are the names
+        Create basic setup of an Up Front game. player1 and player2 are the names
         of the players for reference.
 
         player1nation and player2nation should be one of: 'germany', 'america', or 'russia'.
         america.
         """
 
-        self.__validateNations(player1nation, player2nation)
         self.state = 'setup'
-        self.player1name = player1name
+        self.player1 = player1
         self.player1nation = player1nation
-        self.player2name = player2name
+        self.player2 = player2
         self.player2nation = player2nation
 
-        self.personalityCards = [self.__getCards(player1nation), self.__getCards(player2nation)]
-
     def __validateNations(self, nation1, nation2):
         nations = ['america', 'germany', 'russia']
 
         if not nation1 == 'america' and not nation2 == 'america':
             raise ValueError('At least one player must be American')
 
-    def __getCards(self, nation):
+    def getCards(nation):
         if nation == 'germany':
             pistol = {'type': 'Machine Pistol', 'name': 'MP 38',
                 'firepower': {0:0, 1:0, 2:0, 3:1, 4:3, 5:5}}

File upfront/templates/game.mako

+<%inherit file="base.mako"/>
+
+

File upfront/views.py

 
 @view_config(context=OpenGame, renderer='upfront:templates/game.mako', name='join')
 def join_game(context, request):
-    return dict(nation=request.subpath[0]) 
+    game = UpFront(context.player1, context.player1nation, request.user, request.subpath[0])
+    id = int(context.__name__)
+    games = context.__parent__
+    del games.openGames[id]
+    games.games[id] = game
+    context.player1.games[id] = game
+    request.user.games[id] = game 
+    return dict(game=game) 
 
 @view_config(context=OpenGame, name='delete', permission='delete-game')
 @view_config(context=UpFront, name='delete', permission='delete-game')
 
 @view_config(context=Games, renderer='upfront:templates/opengames.mako', name='open')
 def open_games(context, request):
-    games = request.root['games'].openGames
+    games = context.openGames
     return dict(games=games)
 
 @view_config(context=Games, renderer='upfront:templates/newgame.mako', permission='create-game', name='new')