Skip to content

Commit

Permalink
finished basic version of app
Browse files Browse the repository at this point in the history
  • Loading branch information
iamlogand committed Jun 27, 2022
1 parent 86f0b0d commit 07929e2
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 27 deletions.
Binary file added __pycache__/gui.cpython-310.pyc
Binary file not shown.
46 changes: 46 additions & 0 deletions gui.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import PySimpleGUI as sg

TITLE = "Diplomacy Nation Picker"

def build_results_dict(nations):
player_names = sorted(nations.keys())
pattern = "• {0} will play as {1}"
results = [""] * 7
for i in range(0, len(player_names)):
results[i] = pattern.format(player_names[i], nations[player_names[i]])
return results

def show_results(nations):
results = build_results_dict(nations)
desc = "Results"
layout = [[sg.Text(desc)], [sg.VPush()],
[sg.Text(results[0])], [sg.Text(results[1])], [sg.Text(results[2])], [sg.Text(results[3])], [sg.Text(results[4])], [sg.Text(results[5])], [sg.Text(results[6])],
[sg.VPush()], [sg.Push(), sg.Exit()]]
window = sg.Window(TITLE, layout, size=(300,300))
values = manage_window(window)
return values[0]

def get_player_name(player_number):
prompt = "Player {0} name".format(player_number)
layout = [[sg.Text(prompt), sg.Push(), sg.InputText(focus=True)], [sg.VPush()], [sg.Push(), sg.Exit(), sg.OK()]]
window = sg.Window(TITLE, layout, size=(300,100))
values = manage_window(window)
return values[0].strip().capitalize()

def get_player_count():
prompt = "Number of players"
options = ["2", "3", "4", "5", "6", "7"]
layout = [[sg.Text(prompt), sg.Push(), sg.Combo(options, size=(10, 0), readonly=True)], [sg.VPush()], [sg.Push(), sg.Exit(), sg.OK()]]
window = sg.Window(TITLE, layout, size=(300,100))
values = manage_window(window)
return int(values[0])

def manage_window(window):
while True:
event, values = window.read()
if event == "Exit" or event == sg.WIN_CLOSED:
quit()
if event == 'OK':
break
window.close()
return values
52 changes: 25 additions & 27 deletions main.py
Original file line number Diff line number Diff line change
@@ -1,43 +1,41 @@
import PySimpleGUI as sg
import random
from gui import *

TITLE = "Diplomacy Nation Picker"
def assign_nations(nations, names):
output_dict = {}
for name in names:
selected_nation = random.choice(nations)
nations.remove(selected_nation)
output_dict[name] = selected_nation
return output_dict

def get_player_name(player_number):
prompt = "Player {0} name".format(player_number)
layout = [[sg.Text(prompt), sg.Push(), sg.InputText(focus=True)], [sg.VPush()], [sg.Push(), sg.Exit(), sg.OK()]]
window = sg.Window(TITLE, layout, size=(300,100))
values = manage_window(window)
return values[0]
def limit_nations(player_count):
if player_count == 7:
return ["Austria", "England", "France", "Germany", "Italy", "Russia", "Turkey"]
if player_count == 6:
return ["Austria", "England", "France", "Germany", "Russia", "Turkey"]
if player_count == 5:
return ["Austria", "England", "France", "Russia", "Turkey"]
if player_count == 4:
return ["England", "France", "Russia", "Turkey"]
if player_count == 3:
return ["France", "Germany", "Austria"]
if player_count == 2:
return ["France", "Austria"]

def get_player_names(player_count):
names = []
for player_number in range(1, player_count + 1):
names.append(get_player_name(player_number))
return random.shuffle(names)

def get_player_count():
prompt = "Number of players"
options = ["1", "2", "3", "4", "5", "6", "7"]
layout = [[sg.Text(prompt), sg.Push(), sg.Combo(options, size=(10, 0), readonly=True)], [sg.VPush()], [sg.Push(), sg.Exit(), sg.OK()]]
window = sg.Window(TITLE, layout, size=(300,100))
values = manage_window(window)
return int(values[0])

def manage_window(window):
while True:
event, values = window.read()
if event == "Exit" or event == sg.WIN_CLOSED:
quit()
if event == 'OK':
break
window.close()
return values
random.shuffle(names)
return names

def main():
while True:
player_count = get_player_count()
names = get_player_names(player_count)
assigned_nations = assign_nations(limit_nations(player_count), names)
show_results(assigned_nations)
break

if __name__ == "__main__":
Expand Down

0 comments on commit 07929e2

Please sign in to comment.