Created cli_menu.py
This will hold all the menu options. Main will only be used for housing the main loop. Trying to make stuff more modular. Not fully functional though, because the dictionary functions automatically run upon instantiation of a cli_menu() object. Still trying to fix that.
This commit is contained in:
parent
5949b747ef
commit
991e37d06d
|
@ -0,0 +1,135 @@
|
|||
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")
|
||||
|
71
main.py
71
main.py
|
@ -1,65 +1,18 @@
|
|||
import mech
|
||||
import cli_menu as clm
|
||||
import os
|
||||
|
||||
debug = True
|
||||
|
||||
mech_list = []
|
||||
|
||||
menu_choices = ["n","l","q"]
|
||||
# add more choices as needed
|
||||
|
||||
main_menu = """ Main Menu:
|
||||
(n)ew mech,
|
||||
(l)ist a player's mechs,
|
||||
or (q)uit the session.
|
||||
"""
|
||||
|
||||
def make_mech(mech_list):
|
||||
# take the given mech list
|
||||
m = mech.Mech(quiet=False, debug=False)
|
||||
mech_list.append(m)
|
||||
return mech_list
|
||||
|
||||
|
||||
def get_player_mechs(mech_list):
|
||||
player = input("Search for player name: ")
|
||||
print("Mech list for: ",player)
|
||||
for unit in mech_list:
|
||||
u = unit.card # just for easy typing
|
||||
if u["player"] == player:
|
||||
print("Mech name: ",u["name"])
|
||||
print("Mech variant: ",u["dez"])
|
||||
print("Mech size: ",u["size"])
|
||||
print("\n")
|
||||
|
||||
|
||||
def menu(choice):
|
||||
if choice not in menu_choices:
|
||||
print("Incorrect choice. Try again.")
|
||||
os.system('cls' if os.name == 'nt' else 'clear')
|
||||
elif choice == 'n':
|
||||
make_mech(mech_list)
|
||||
return True
|
||||
elif choice == 'l':
|
||||
get_player_mechs(mech_list)
|
||||
return True
|
||||
elif choice == 'q':
|
||||
print("Bye!")
|
||||
return False
|
||||
else:
|
||||
print("This should literally be impossible to get to.")
|
||||
print("THOU FOOL! THOU HAST DESECRATED MINE ROBITZ")
|
||||
|
||||
|
||||
def main(debug):
|
||||
play = True
|
||||
while play:
|
||||
# Clear the screen
|
||||
os.system('cls' if os.name == 'nt' else 'clear')
|
||||
|
||||
print(main_menu)
|
||||
play = menu(input("Make your choice: "))
|
||||
# will automatically break the loop if you select 'q'
|
||||
|
||||
|
||||
play = True
|
||||
menu = clm.cli_menu()
|
||||
# menu.menu(input("Make your choice: "))
|
||||
while play:
|
||||
# Clear the screen
|
||||
play = menu.menu()
|
||||
os.system('cls' if os.name == 'nt' else 'clear')
|
||||
# will automatically break the loop if you select 'q'
|
||||
|
||||
|
||||
main(debug)
|
||||
|
||||
|
|
Loading…
Reference in New Issue