Added kill option to game creation as well as play order choice

This commit is contained in:
sloumdrone 2019-04-27 16:24:38 -07:00
parent 888878b385
commit 286e591ee0
2 changed files with 21 additions and 2 deletions

Binary file not shown.

23
oberon
View File

@ -3,13 +3,14 @@
import sys
import sqlite3 as sql
import os
from os.path import isfile as fileexists
import subprocess
import json
from gomoku import Gomoku
from isola import Isola
from brandubh import Brandubh
version = '0.8.0'
version = '0.8.1'
home_folder = os.path.expanduser('~')
username = os.path.split(home_folder)[-1]
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('play [game_id]', 'make a move or view the board for the game id provided'))
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
@ -144,6 +147,10 @@ def create_game(enemy):
print('There is no avialable player with the name {}.\nGame not created.'.format(enemy))
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('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:
@ -179,9 +186,21 @@ def create_game(enemy):
game_board[3][3] = ' D '
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 (?, ?, ?, ?, ?, ?, ?)"
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)
if res:
print('Game between {} and {} created!'.format(username, enemy))