ALPHA/cli_menu.py

136 lines
3.8 KiB
Python

import mech
import os
class cli_menu():
def __init__(self):
self.main_menu = """Main Menu:
(n)ew mech,
(l)ist a player's mechs,
(m)odify a mech,
or (q)uit the session.
"""
self.mech_list = []
self.menu_choices = {
"n": self.make_mech(self.mech_list),
"l": self.get_player_mechs(self.mech_list),
"m": self.modify_mech(self.mech_list)
}
self.mech_modify_options = {
"n": "name",
"v": "dez",
"s": "size",
"p": "skill",
"t": "tmm"
}
#self.menu_choices = ["n", "l", "q", "m"]
#self.mech_modify_options = ["n","v","s","p","t","b"]
# add more choices as needed
def make_mech(self,mech_list):
# create a new mech
new = mech.Mech(quiet=False, debug=False)
# instantiate a Mech with CLI options for the mech's info
mech_list.append(new)
# add that to the mech_list
return mech_list
def get_player_mechs(self,mech_list, player=''):
# lists all mechs of a player
player = input("Search for player name: ")
print("Mech list for: ", player,"\n")
for unit in mech_list:
u = unit # just for easy typing
if u.get_player() == player:
print("Mech name: ", u.get_name())
print("Mech variant: ", u.get_dez())
print("Mech size: ", u.get_size())
print("\n")
def search_player(self,mech_list):
# creates list of mechs of a certain player
# not front-facing function
# used for modify_mech()
player = input("Search for player: ")
temp_list = []
i = 0
for unit in mech_list:
if unit.get_player() == player:
print('Unit: ', i, '\n')
print(unit.card)
temp_list.append(unit)
i = i + 1
return temp_list
def modify_mech_attribute(self,mech_to_modify,user_choice):
if user_choice != 'b':
while user_choice not in self.mech_modify_options:
user_choice = input("Invalid option. Try again: ")
mech_to_modify[user_choice] = input("Change the data: ")
else:
print("Going back to the menu")
#return mech_to_modify
def modify_mech(self,mech_list):
# lets user modify a mech's attribute
mechs_to_modify_list = self.search_player(mech_list)
print("Which mech do you want to change?: ")
selection = mechs_to_modify_list[int(input())]
print("""
What attribute do you want to modify?
(n)ame,
(v)ariant,
(s)ize,
(p)ilot skill,
(t)mm,
or, (b)ack to the menu:
""")
self.modify_mech_attribute(selection,input())
def menu(self):
print(self.main_menu)
choice = input("Make your choice: ")
if choice == 'q':
print("Bye!")
return False
while choice not in self.menu_choices:
choice = input("Incorrect input. Try again: ")
self.menu_choices[choice]
#elif choice == 'n':
# self.menu_choices[n]
# return True
#elif choice == 'l':
# self.get_player_mechs(self.mech_list)
# return True
#elif choice == 'q':
# print("Bye!")
# return False
#elif choice == 'm':
# self.modify_mech(self.mech_list)
#else:
# print("This should literally be impossible to get to.")
# print("THOU FOOL! THOU HAST DESECRATED MINE ROBITZ")