parameter error handling, return 1 on error

master
panki27 7 years ago
parent b70138661d
commit aecd5cdb6c

@ -1,5 +1,5 @@
#!/usr/bin/env python3 #!/usr/bin/env python3
#TODO: highscore, monochrome, flags red if too many #TODO: highscore, monochrome, flags red if too many, adventure mode
import random, io, sys, time, os import random, io, sys, time, os
import curses import curses
@ -34,7 +34,7 @@ clWhite, clRed, clCyan, clBlue, clYellow, clGreen, clInverted = None, None, None
difficulty = 'medium' difficulty = 'medium'
param_error = 'minebash: Invalid parameters. See \'minebash help\' for help ' param_error = 'minebash: Invalid parameters. See \'minebash help\' for help '
helpstr = '''Usage: minebash [easy|medium|hard] [width height minecount] helpstr = '''Usage: minebash [easy|medium|hard] | [width height minecount]
Difficulty presets: Difficulty presets:
easy: 5x5 4 mines easy: 5x5 4 mines
@ -69,20 +69,24 @@ if len(sys.argv) > 1:
MINECOUNT = 35 MINECOUNT = 35
else: else:
print(param_error) print(param_error)
sys.exit(0) sys.exit(1)
difficulty = sys.argv[1] difficulty = sys.argv[1]
elif len(sys.argv) == 4: #this means the user has specified width, height and minecount elif len(sys.argv) == 4: #this means the user has specified width, height and minecount
width = int(sys.argv[1]) try:
height = int(sys.argv[2]) width = int(sys.argv[1])
height = int(sys.argv[2])
except ValueError:
print(param_error)
sys.exit(1)
if int(sys.argv[3]) < width*height: if int(sys.argv[3]) < width*height:
MINECOUNT = int(sys.argv[3]) MINECOUNT = int(sys.argv[3])
difficulty = 'custom' difficulty = 'custom'
else: else:
print('Minecount muss be less than width x height.') print('Minecount muss be less than width x height.')
system.exit(0) sys.exit(1)
else: else:
print(param_error) print(param_error)
sys.exit(0) sys.exit(1)
playfield = [[UNKNOWN for x in range(width)] for y in range(height)] playfield = [[UNKNOWN for x in range(width)] for y in range(height)]
headline = '┌' headline = '┌'

Loading…
Cancel
Save