Changed the list format to show whose turn it is
This commit is contained in:
parent
974d453494
commit
2c2612c019
25
oberon
25
oberon
|
@ -19,6 +19,7 @@ def print_header():
|
|||
print('\nO B E R O N v{}\n'.format(version))
|
||||
|
||||
|
||||
# Binds to the CREATE command
|
||||
def create_game(enemy):
|
||||
if enemy == username:
|
||||
print('This system is designed for multiuser games. You cannot create a game against yourself.')
|
||||
|
@ -49,6 +50,7 @@ def validate_input(r,c, board):
|
|||
return True
|
||||
|
||||
|
||||
# Binds to the AVAILABLE command
|
||||
def available_moves():
|
||||
q = "SELECT p1, p2, turn FROM games WHERE winner is null and (p1 = ? or p2 = ?)"
|
||||
v = (username, username)
|
||||
|
@ -105,6 +107,7 @@ def set_winner(game, winner):
|
|||
return db_do(q, v, True)
|
||||
|
||||
|
||||
# Binds to the PLAY command
|
||||
def play_game(gid):
|
||||
q = "SELECT rowid, p1, p2, game_board, turn FROM games WHERE rowid = ?"
|
||||
v = (gid,)
|
||||
|
@ -192,6 +195,7 @@ def print_board(gb):
|
|||
print('')
|
||||
|
||||
|
||||
# Binds to the HISTORY command
|
||||
def show_game_record():
|
||||
q = "SELECT rowid, p1, p2, winner FROM games WHERE winner is not NULL and (p1 = ? or p2 = ?)"
|
||||
v = (username, username)
|
||||
|
@ -209,24 +213,27 @@ def show_game_record():
|
|||
return True
|
||||
|
||||
|
||||
# Binds to the LIST command
|
||||
def list_games():
|
||||
q = "SELECT rowid, p1, p2, game_type, game_status FROM games WHERE winner is NULL and (p1 = ? or p2 = ?)"
|
||||
q = "SELECT rowid, p1, p2, game_type, game_status, turn FROM games WHERE winner is NULL and (p1 = ? or p2 = ?)"
|
||||
v = (username, username)
|
||||
res = db_do(q, v)
|
||||
if res == False:
|
||||
print('Database error. Contact the sysadmin or try another time.')
|
||||
return False
|
||||
print_header()
|
||||
print('{:^8} {:^10} {:^10} {:^12}'.format('ID', 'Player 1', 'Player 2', 'Game Status'))
|
||||
print('-------- ---------- ---------- ------------')
|
||||
print('{:^8} {:^10} {:^10} {:^22}'.format('ID', 'Player 1', 'Player 2', 'Game Status'))
|
||||
print('-------- ---------- ---------- ----------------------')
|
||||
for x in res:
|
||||
print("{:^8} {:^10} {:^10} {:^12}".format(x[0], x[1], x[2], x[4]))
|
||||
pturn = x[2] if x[5] % 2 == 0 else x[1]
|
||||
print("{:^8} {:^10} {:^10} {:^22}".format(x[0], x[1], x[2], pturn +"'s turn"))
|
||||
if not len(res):
|
||||
print('You are not currently playing any games...')
|
||||
print('')
|
||||
return True
|
||||
|
||||
|
||||
# Binds to the HELP command
|
||||
def display_help():
|
||||
print_header()
|
||||
print('syntax: oberon [command [option]]\n')
|
||||
|
@ -242,8 +249,8 @@ def parse_args():
|
|||
args = sys.argv
|
||||
arg_len = len(args)
|
||||
if arg_len == 1:
|
||||
print('Invalid arguments. Run "oberon help".')
|
||||
sys.exit(1)
|
||||
display_help()
|
||||
sys.exit(0)
|
||||
if arg_len == 2:
|
||||
if args[1] == 'list':
|
||||
l = list_games()
|
||||
|
@ -251,8 +258,10 @@ def parse_args():
|
|||
sys.exit(0)
|
||||
sys.exit(1)
|
||||
elif args[1] == 'history':
|
||||
show_game_record()
|
||||
sys.exit(0)
|
||||
h = show_game_record()
|
||||
if h:
|
||||
sys.exit(0)
|
||||
sys.exit(1)
|
||||
elif args[1] == 'available':
|
||||
available_moves()
|
||||
sys.exit(0)
|
||||
|
|
Loading…
Reference in New Issue