Added kill option to game creation as well as play order choice
This commit is contained in:
parent
888878b385
commit
286e591ee0
Binary file not shown.
23
oberon
23
oberon
|
@ -3,13 +3,14 @@
|
||||||
import sys
|
import sys
|
||||||
import sqlite3 as sql
|
import sqlite3 as sql
|
||||||
import os
|
import os
|
||||||
|
from os.path import isfile as fileexists
|
||||||
import subprocess
|
import subprocess
|
||||||
import json
|
import json
|
||||||
from gomoku import Gomoku
|
from gomoku import Gomoku
|
||||||
from isola import Isola
|
from isola import Isola
|
||||||
from brandubh import Brandubh
|
from brandubh import Brandubh
|
||||||
|
|
||||||
version = '0.8.0'
|
version = '0.8.1'
|
||||||
home_folder = os.path.expanduser('~')
|
home_folder = os.path.expanduser('~')
|
||||||
username = os.path.split(home_folder)[-1]
|
username = os.path.split(home_folder)[-1]
|
||||||
database = '/var/lib/oberon/oberon.sqlite'
|
database = '/var/lib/oberon/oberon.sqlite'
|
||||||
|
@ -131,6 +132,8 @@ def display_help():
|
||||||
print('{:20} {}'.format('create [user]', 'create a game against the user provided'))
|
print('{:20} {}'.format('create [user]', 'create a game against the user provided'))
|
||||||
print('{:20} {}'.format('play [game_id]', 'make a move or view the board for the game id provided'))
|
print('{:20} {}'.format('play [game_id]', 'make a move or view the board for the game id provided'))
|
||||||
print('')
|
print('')
|
||||||
|
print('if you do not want to play games simply add a file named ".killoberon" to your home directory and users will not be able to create games with you')
|
||||||
|
print('')
|
||||||
|
|
||||||
|
|
||||||
# Binds to the CREATE command
|
# Binds to the CREATE command
|
||||||
|
@ -144,6 +147,10 @@ def create_game(enemy):
|
||||||
print('There is no avialable player with the name {}.\nGame not created.'.format(enemy))
|
print('There is no avialable player with the name {}.\nGame not created.'.format(enemy))
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
if fileexists('/home/{}/.killoberon'.format(enemy)):
|
||||||
|
print('{} does not wish to play games in oberon. Please try creating a game with a different user.'.format(enemy))
|
||||||
|
return False
|
||||||
|
|
||||||
print_header()
|
print_header()
|
||||||
print('Which game would you like to play?\n\n(1) Gomoku/Five In a Row\n(2) Isola\n(3) Brandubh\n\nor (Q)uit')
|
print('Which game would you like to play?\n\n(1) Gomoku/Five In a Row\n(2) Isola\n(3) Brandubh\n\nor (Q)uit')
|
||||||
while True:
|
while True:
|
||||||
|
@ -179,9 +186,21 @@ def create_game(enemy):
|
||||||
game_board[3][3] = ' D '
|
game_board[3][3] = ' D '
|
||||||
game_choice = 'brandubh'
|
game_choice = 'brandubh'
|
||||||
|
|
||||||
|
player = '0'
|
||||||
|
print('')
|
||||||
|
while not player in ['1','2']:
|
||||||
|
print('Play as player 1 or player 2 (enter the number)')
|
||||||
|
player = input('> ')
|
||||||
|
|
||||||
|
if player == '2':
|
||||||
|
temp = enemy
|
||||||
|
enemy = username
|
||||||
|
player = temp
|
||||||
|
else:
|
||||||
|
player = username
|
||||||
|
|
||||||
q = "INSERT INTO games VALUES (?, ?, ?, ?, ?, ?, ?)"
|
q = "INSERT INTO games VALUES (?, ?, ?, ?, ?, ?, ?)"
|
||||||
v = (username, enemy, game_choice, 'playing', json.dumps(game_board), 1, None)
|
v = (player, enemy, game_choice, 'playing', json.dumps(game_board), 1, None)
|
||||||
res = db_do(q, v, True)
|
res = db_do(q, v, True)
|
||||||
if res:
|
if res:
|
||||||
print('Game between {} and {} created!'.format(username, enemy))
|
print('Game between {} and {} created!'.format(username, enemy))
|
||||||
|
|
Loading…
Reference in New Issue