parameter error handling, return 1 on error
This commit is contained in:
parent
b70138661d
commit
aecd5cdb6c
18
minebash
18
minebash
@ -1,5 +1,5 @@
|
||||
#!/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 curses
|
||||
@ -34,7 +34,7 @@ clWhite, clRed, clCyan, clBlue, clYellow, clGreen, clInverted = None, None, None
|
||||
difficulty = 'medium'
|
||||
|
||||
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:
|
||||
easy: 5x5 4 mines
|
||||
@ -69,20 +69,24 @@ if len(sys.argv) > 1:
|
||||
MINECOUNT = 35
|
||||
else:
|
||||
print(param_error)
|
||||
sys.exit(0)
|
||||
sys.exit(1)
|
||||
difficulty = sys.argv[1]
|
||||
elif len(sys.argv) == 4: #this means the user has specified width, height and minecount
|
||||
width = int(sys.argv[1])
|
||||
height = int(sys.argv[2])
|
||||
try:
|
||||
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:
|
||||
MINECOUNT = int(sys.argv[3])
|
||||
difficulty = 'custom'
|
||||
else:
|
||||
print('Minecount muss be less than width x height.')
|
||||
system.exit(0)
|
||||
sys.exit(1)
|
||||
else:
|
||||
print(param_error)
|
||||
sys.exit(0)
|
||||
sys.exit(1)
|
||||
playfield = [[UNKNOWN for x in range(width)] for y in range(height)]
|
||||
|
||||
headline = '┌'
|
||||
|
Loading…
Reference in New Issue
Block a user