Просмотр исходного кода

remove duplicate command for next turn, outline procedure for getting score info

George C. Privon 8 лет назад
Родитель
Сommit
fbe99d763f
1 измененных файлов с 75 добавлено и 7 удалено
  1. 75 7
      cgame.py

+ 75 - 7
cgame.py

@@ -36,8 +36,8 @@ class cgame:
         """
         """
 
 
         self.commands = [('r', 'record score'),
         self.commands = [('r', 'record score'),
-                         ('t', 'advance turn, no score'),
-                         ('e', 'end game (or play if already in postgame scoring'),
+                         ('n', 'next turn'),
+                         ('e', 'end game (or end play if already in postgame scoring)'),
                          ('s', '(current) score and game status'),
                          ('s', '(current) score and game status'),
                          ('q', 'quit (will be removed for real gameplay'),
                          ('q', 'quit (will be removed for real gameplay'),
                          ('?', 'print help')]
                          ('?', 'print help')]
@@ -65,6 +65,7 @@ class cgame:
 
 
         # game state information
         # game state information
         self.state = 0  # 0 for main game, 1 for postgame, 2 for ended game
         self.state = 0  # 0 for main game, 1 for postgame, 2 for ended game
+        self.nscore = 0
         self.ntile = 0  # number of tiles played
         self.ntile = 0  # number of tiles played
         self.nbuilder = 0   # number of tiles placed due to builders
         self.nbuilder = 0   # number of tiles placed due to builders
         self.totaltiles = 72    # may be increased by expansions
         self.totaltiles = 72    # may be increased by expansions
@@ -98,6 +99,8 @@ class cgame:
 
 
         gID = self.cur.execute('select last_insert_rowid();').fetchall()[0]
         gID = self.cur.execute('select last_insert_rowid();').fetchall()[0]
 
 
+        self.conn.commit()
+
         self.gameID = gID[0]
         self.gameID = gID[0]
 
 
 
 
@@ -187,10 +190,76 @@ class cgame:
         Record a score event in the game
         Record a score event in the game
         """
         """
 
 
+        score = {'gameID': self.gameID,
+                 'playerID': -1,
+                 'turnNum': self.ntile,
+                 'scoreID': self.nscore,
+                 'ingame' : 1,
+                 'points' : 0,
+                 'scoretype': '',
+                 'sharedscore': 0,
+                 'token': '',
+                 'extras': '',
+                 'comments': ''}
+
         if self.state:
         if self.state:
-            ingame = 0
+            score['ingame'] = 0
 
 
-        player = self.getCurrentPlayer()
+        # ask the user which player scored
+        score['playerID'] = ...
+
+        # get points for score
+        VALID = False
+        while not VALID:
+            score = input("Enter the total number of points: ")
+            try:
+                score['points'] = int(score)
+                VALID = True
+            except:
+                _sys.stderr.write("'" + commnd + "' is not a valid score.\n")
+                continue
+
+        # get the score type
+        VALID = False
+        while not VALID:
+            # here i want a list of valid score types
+            stype = input("Please select the score type: ")
+
+
+        # shared score?
+        VALID = False
+        while not VALID:
+            shared = input("Was this score shared with another player (y/n)? ")
+
+        # see which token scored
+        # really this should be expanded to allow multiple token types for one score
+        if len(self.tokens) > 1:
+            VALID = False
+            while not VALID:
+                for i, token in enumerate(self.tokens):
+                    sys.stdout.write("{0:d}) ".format(i+1) + token + "\n")
+                tID = input("Please select the token type: ")
+                try:
+                    score['token'] += self.tokens[int(tID-1)]
+                    VALID = True
+                except:
+                    _sys.stderr.write("'" + command + "' is not a valid token.\n")
+                    continue
+        else:
+            score['token'] = self.tokens[0]
+
+
+        # now construct a SQL query
+        command = 'INSERT INTO scores VALUE ({0:d},'.format(self.gameID)
+        command = command + '{0:d}, {1:d},'.format(self.ntile,
+                                                  self.nscore)
+
+        if score['sharedscore']:
+            # get the other player(s) who scored and construct SQL inserts for
+            # scores
+
+        # now increment the score number
+        self.nscore += 1
 
 
         return 0
         return 0
 
 
@@ -214,6 +283,7 @@ class cgame:
         command = command + ', {0:d}, {1:d})'.format(bID, player[0])
         command = command + ', {0:d}, {1:d})'.format(bID, player[0])
 
 
         self.cur.execute(command)
         self.cur.execute(command)
+        self.conn.commit()
 
 
         self.ntile += 1
         self.ntile += 1
         if builder:
         if builder:
@@ -253,11 +323,9 @@ class cgame:
             elif _re.match('s', cmd, _re.IGNORECASE):
             elif _re.match('s', cmd, _re.IGNORECASE):
                 self.printStatus(tilestats=True)
                 self.printStatus(tilestats=True)
             elif _re.match('n', cmd, _re.IGNORECASE):
             elif _re.match('n', cmd, _re.IGNORECASE):
-                self.advanceTurn()
+                self.advanceTurn(builder=False)
             elif _re.match('r', cmd, _re.IGNORECASE):
             elif _re.match('r', cmd, _re.IGNORECASE):
                 self.recordScore()
                 self.recordScore()
-            elif _re.match('t', cmd, _re.IGNORECASE):
-                self.advanceTurn(builder=False)
             elif _re.match('b', cmd, _re.IGNORECASE):
             elif _re.match('b', cmd, _re.IGNORECASE):
                 self.advanceTurn(builder=True)
                 self.advanceTurn(builder=True)
             elif _re.match('\?', cmd, _re.IGNORECASE):
             elif _re.match('\?', cmd, _re.IGNORECASE):