Преглед изворни кода

do checks for input values. Fixes #3

George C. Privon пре 8 година
родитељ
комит
da0dbba366
2 измењених фајлова са 19 додато и 5 уклоњено
  1. 3 1
      CHANGELOG.md
  2. 16 4
      cgame.py

+ 3 - 1
CHANGELOG.md

@@ -2,10 +2,12 @@
 
 ## 0.X Series
 
-### 0.1.2
+### upcoming
 
 #### Bugfixes
 
+* check inputs
+
 #### Enhancements
 
 * Require a minimum of 2 players

+ 16 - 4
cgame.py

@@ -120,8 +120,14 @@ class cgame:
         if len(dbplayers):
             for dbplayer in dbplayers:
                 _sys.stdout.write("{0:d}) ".format(dbplayer[0]) + dbplayer[1] + '\n')
-            playerinput = input("Please list the IDs for the players in this game (in order of play): ")
-            playerIDs = [int(x) for x in playerinput.split()]
+            VALID = False
+            while not VALID:
+                playerinput = input("Please list the IDs for the players in this game (in order of play): ")
+                try:
+                    playerIDs = [int(x) for x in playerinput.split()]
+                    VALID = True
+                except:
+                    _sys.stderr.write("Error: input must be a list of integers separated by spaces.\n")
 
             if len(playerIDs) < 2:
                 _sys.stderr.write("Playing alone? You need at least one opponent!\n")
@@ -161,8 +167,14 @@ class cgame:
             if len(dbexpans):
                 for dbexpan in dbexpans:
                     _sys.stdout.write("{0:d}) ".format(dbexpan[0]) + dbexpan[1] + '\n')
-                expaninput = input("Please list the numbers for the " + exptype + " used in this game: ")
-                expanIDs = [int(x) for x in expaninput.split()]
+                VALID = False
+                while not VALID:
+                    expaninput = input("Please list the numbers for the " + exptype + " used in this game: ")
+                    try:
+                        expanIDs = [int(x) for x in expaninput.split()]
+                        VALID = True
+                    except:
+                        _sys.stderr.write("Error: input must be a list of integers separated by spaces.\n")
                 for expanID in expanIDs:
                     matched = False
                     # add the builder cmd if Traders & Builders is used