Initial commit. What a mess.
This commit is contained in:
commit
20fefda39c
|
@ -0,0 +1,186 @@
|
|||
#!/usr/bin/env python3
|
||||
#
|
||||
# Oberon: an application for managing correspondance gameplay
|
||||
# for board style games
|
||||
# by Brian Evans
|
||||
#_
|
||||
|
||||
import sys
|
||||
import os
|
||||
import sqlite3
|
||||
import re
|
||||
import subprocess
|
||||
|
||||
class c:
|
||||
black = ''
|
||||
red = '\033[0;31m'
|
||||
b_red = '\033[1;31m'
|
||||
yellow = '\033[1;33m'
|
||||
green = '\033[0;32m'
|
||||
b_green = '\033[1;32m'
|
||||
cyan = '\033[0;36m'
|
||||
b_cyan = '\033[1;36m'
|
||||
purple = '\033[1;35m'
|
||||
blue = '\033[0;34m'
|
||||
b_blue = '\033[1;34m'
|
||||
white = '\033[1;37m'
|
||||
end = '\033[0m'
|
||||
|
||||
#--------->
|
||||
|
||||
class User:
|
||||
def __init__(self):
|
||||
self.home_folder = os.path.expanduser('~')
|
||||
self.name = os.path.split(self.home_folder)[-1]
|
||||
self.current_games = self.get_games()
|
||||
self.history = self.get_history()
|
||||
|
||||
|
||||
def get_games(self):
|
||||
db_data = False # do db query
|
||||
# Retrieve current games
|
||||
return db_data
|
||||
|
||||
|
||||
def get_history(self):
|
||||
db_data = False # do db query
|
||||
# Retrieve history for this user
|
||||
return db_data
|
||||
|
||||
#-------->
|
||||
|
||||
class Interface:
|
||||
def __init__(self):
|
||||
self.user = User()
|
||||
self.screen = 'menu'
|
||||
self.userlist = self.get_user_list()
|
||||
self.mainloop()
|
||||
|
||||
|
||||
def main_menu(self):
|
||||
menu = [
|
||||
'{:^80}'.format('1) Create Game'),
|
||||
'{:^80}'.format('2) List Games'),
|
||||
'{:^80}'.format('3) View history'),
|
||||
'{:^80}'.format('4) Quit/Exit')
|
||||
]
|
||||
|
||||
print('\n{:^80}'.format('O B E R O N'))
|
||||
print('{:^80}\n'.format('Correspondence gaming system'))
|
||||
for x in menu:
|
||||
print('{:^80}'.format(x))
|
||||
selection = ''
|
||||
while selection not in ['1', '2', '3', '4', 'q', 'quit', 'exit']:
|
||||
selection = input(' oberon > ')
|
||||
if selection == '1':
|
||||
self.screen = 'create'
|
||||
elif selection == '2':
|
||||
self.screen = 'list'
|
||||
elif selection == '3':
|
||||
self.screen = 'history'
|
||||
elif selection in ['4','q','quit','exit']:
|
||||
sys.exit(0)
|
||||
|
||||
|
||||
def get_user_list(self):
|
||||
res = subprocess.run(['awk', '-F', ':', '{if ($7 == "/usr/local/bin/colorsh" && $1 != "brian")}', '/etc/passwd'], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
||||
res_list = res.stdout.decode('utf-8').split('\n')
|
||||
if res_list[0] == '':
|
||||
return []
|
||||
return res_list
|
||||
|
||||
|
||||
def create_game(self):
|
||||
if not len(self.userlist):
|
||||
self.screen = 'menu'
|
||||
print('\n')
|
||||
print('{}{:^80}{}'.format(c.white, 'There are no players available', c.end))
|
||||
print('\n')
|
||||
return False
|
||||
print('{:^80}'.format('The following players are available:\n'))
|
||||
for x in self.userlist:
|
||||
print('{:^80}'.format(x))
|
||||
print('\n')
|
||||
p2 = ''
|
||||
while not p2 in self.userlist:
|
||||
p2 = input('Who would you like to challenge? ')
|
||||
if not p2 in self.userlist:
|
||||
print('{}Invalid entry{}'.format(c.red, c.end))
|
||||
self.screen = 'play'
|
||||
|
||||
|
||||
def list_games(self):
|
||||
# List games user is currently playing
|
||||
# List any open games
|
||||
game_id = input('Choice > ')
|
||||
game = validate_game(game_id)
|
||||
if game:
|
||||
if p1 == self.user or p2 == self.user:
|
||||
# THis is getting wonky
|
||||
pass
|
||||
elif not p2:
|
||||
pass
|
||||
else:
|
||||
pass
|
||||
|
||||
|
||||
def get_game_list():
|
||||
# query for available open games and current games for player
|
||||
pass
|
||||
|
||||
def show_history(self):
|
||||
# query for this palyers win records
|
||||
# display them
|
||||
# options for back or quit
|
||||
pass
|
||||
|
||||
|
||||
def play_game(self):
|
||||
# acts as a router to game logic functions
|
||||
# based on which game is selected
|
||||
pass
|
||||
|
||||
|
||||
def mainloop(self):
|
||||
while True:
|
||||
if self.screen == 'menu':
|
||||
self.main_menu()
|
||||
elif self.screen == 'create':
|
||||
self.create_game()
|
||||
elif self.screen == 'list':
|
||||
self.list_games()
|
||||
elif self.screen == 'history':
|
||||
self.show_history()
|
||||
elif self.screen == 'play':
|
||||
self.play_game()
|
||||
|
||||
|
||||
class Game:
|
||||
def __init__(self, game_id):
|
||||
self.game_id = None
|
||||
self.game_board = None
|
||||
self.turn = None
|
||||
|
||||
def get_game_board():
|
||||
pass
|
||||
|
||||
|
||||
def validate_turn():
|
||||
pass
|
||||
|
||||
|
||||
def make_move():
|
||||
pass
|
||||
|
||||
|
||||
def validate_move():
|
||||
pass
|
||||
|
||||
|
||||
def check_win_state():
|
||||
pass
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
game = Interface()
|
||||
|
Loading…
Reference in New Issue