From c948bbcb21fd6dfa2cd421001ce16ac3f3ad51b2 Mon Sep 17 00:00:00 2001 From: Steelwing723 Date: Sun, 23 Jan 2022 09:23:50 -0600 Subject: [PATCH 1/9] Color customization update --- classes.py | 32 +++++++++++++++++++++++-------- colors.py | 28 ++++++++++++++++----------- menu_upgradesAndCustomizations.py | 32 +++++++++++++++++++++++-------- 3 files changed, 65 insertions(+), 27 deletions(-) diff --git a/classes.py b/classes.py index dcb08c7..2b47134 100644 --- a/classes.py +++ b/classes.py @@ -42,21 +42,37 @@ def biomeColor(biome): def strongholdColor(color): if color == 'red': - return textColor.RED + return RED if color == 'green': - return textColor.GREEN + return GREEN if color == 'magenta': - return textColor.MAGENTA + return MAGENTA if color == 'white': - return textColor.BOLD + return BOLD if color == 'blue': - return textColor.BLUE + return BLUE if color == 'yellow': - return textColor.YELLOW + return YELLOW if color == 'cyan': - return textColor.CYAN + return CYAN if color == 'gray': - return textColor.DARK_GRAY + return DARK_GRAY + if color == 'purple': + return PURPLE + if color == 'orange': + return ORANGE + if color == 'teal': + return TEAL + if color == 'pink': + return PINK + if color == 'brown': + return BROWN + if color == 'mint': + return MINT + if color == 'salmon': + return SALMON + if color == 'lavender': + return LAVENDER #the fiefdom class holds variables that define a player's stats class Fiefdom: diff --git a/colors.py b/colors.py index 72ac358..d3d5b20 100644 --- a/colors.py +++ b/colors.py @@ -5,6 +5,11 @@ #================================================= #define some text colors +#I want to start weeding out the use of this. +#Initially I liked the idea of having a class for colors, +#and it may still not be a bad idea, but I think it's easier +#to just type the color and makes for less text in those long +#strings that tend to happen. class textColor: RED = '\033[91m' DARK_RED = "\033[31m" @@ -29,6 +34,8 @@ class textColor: UNDERLINE = '\033[4m' #More, lazier color definitions. +#Some of the original colors were changed in this last update. +#I've commented them out instead of removing them entirely -SW RED = '\033[91m' ORANGE = "\u001b[38;5;208m" PINK = "\033[38;5;213m" @@ -67,29 +74,28 @@ class textColor: DIM = '\033[2m' BOLD = '\033[1m' UNDERLINE = '\033[4m' -# BOLD_DARK_GREEN = "\033[32m \033[1m" -# INTENSE_CYAN = "\033[0;96m" INTENSE_PURPLE = "\033[0;95m" -# INTENSE_BLACK = "\033[1;90m" -# MAGENTA_BACKGROUND = "\u001b[45m" -# WHITE_BACKGROUND = "\033[47m" CYAN_BACKGROUND = "\033[0;106m" -# TEST_COLOR = "\033[41m" +#===================== +# Stronghold Colors +#===================== +# I was thinking we could randomize the stronghold color on creation, but haven't decided. +colors = ['red', 'green', 'magenta', 'blue', 'yellow', 'cyan', 'gray', 'purple', 'orange', 'teal', 'pink', 'brown', 'mint', 'salmon', 'lavender'] #===================== # Unit Colors #===================== -COLOR_THIEF = MAGENTA -COLOR_WARRIOR = LIGHT_GRAY -COLOR_FARMER = WARNING -COLOR_VENDOR = DARK_YELLOW +COLOR_THIEF = LAVENDER +COLOR_WARRIOR = BLUE_GRAY +COLOR_FARMER = YELLOW +COLOR_VENDOR = BRIGHT_YELLOW COLOR_FISHER = CYAN COLOR_SCAVENGER = TEAL COLOR_LUMBERJACK = GREEN COLOR_HUNTER = DARK_GREEN COLOR_MINER = RED -COLOR_PROSPECTOR = DARK_RED +COLOR_PROSPECTOR = SCARLET #===================== # Outpost Colors diff --git a/menu_upgradesAndCustomizations.py b/menu_upgradesAndCustomizations.py index 23d784f..e340d28 100644 --- a/menu_upgradesAndCustomizations.py +++ b/menu_upgradesAndCustomizations.py @@ -220,14 +220,14 @@ def UpgradesAndCustomizations(screen, userStronghold): print('\n\n\n\n\n') print(" Choose a Stronghold Color:") print(' -------------------------------------') - print(''' {1}: Red '''+textColor.RED+'''#'''+textColor.RESET+''' ''') - print(''' {2}: Green '''+textColor.GREEN+'''#'''+textColor.RESET+''' ''') - print(''' {3}: Blue '''+textColor.BLUE+'''#'''+textColor.RESET+''' ''') - print(''' {4}: Yellow '''+textColor.YELLOW+'''#'''+textColor.RESET+''' ''') - print(''' {5}: Magenta '''+textColor.MAGENTA+'''#'''+textColor.RESET+''' ''') - print(''' {6}: Cyan '''+textColor.CYAN+'''#'''+textColor.RESET+''' ''') - print(''' {7}: White '''+textColor.BOLD+'''#'''+textColor.RESET+''' ''') - print(''' {8}: Gray '''+textColor.DARK_GRAY+'''#'''+textColor.RESET+''' ''') + print(''' {1}: Red '''+RED+'''#'''+RESET+''' {10}: Purple '''+PURPLE+'''#'''+RESET+''' ''') + print(''' {2}: Green '''+GREEN+'''#'''+RESET+''' {11}: Orange '''+ORANGE+'''#'''+RESET+''' ''') + print(''' {3}: Blue '''+BLUE+'''#'''+RESET+''' {12}: Teal '''+TEAL+'''#'''+RESET+''' ''') + print(''' {4}: Yellow '''+YELLOW+'''#'''+RESET+''' {13}: Pink '''+PINK+'''#'''+RESET+''' ''') + print(''' {5}: Magenta '''+MAGENTA+'''#'''+RESET+''' {14}: Brown '''+BROWN+'''#'''+RESET+''' ''') + print(''' {6}: Cyan '''+CYAN+'''#'''+RESET+''' {15}: Mint '''+MINT+'''#'''+RESET+''' ''') + print(''' {7}: White '''+BOLD+'''#'''+RESET+''' {16}: Salmon '''+SALMON+'''#'''+RESET+''' ''') + print(''' {8}: Gray '''+DARK_GRAY+'''#'''+RESET+''' {17}: Lavender '''+LAVENDER+'''#'''+RESET+''' ''') print(' {9}: Leave color as is') print(' -------------------------------------') print('') @@ -249,6 +249,22 @@ def UpgradesAndCustomizations(screen, userStronghold): userStronghold.color = 'white' if command == "8": userStronghold.color = 'gray' + if command == "10": + userStronghold.color = 'purple' + if command == "11": + userStronghold.color = 'orange' + if command == "12": + userStronghold.color = 'teal' + if command == "13": + userStronghold.color = 'pink' + if command == "14": + userStronghold.color = 'brown' + if command == "15": + userStronghold.color = 'mint' + if command == "16": + userStronghold.color = 'salmon' + if command == "17": + userStronghold.color = 'lavender' userStronghold.write() screen = "stronghold" From fca732e61cf51d9a54c495d70532167c5405495f Mon Sep 17 00:00:00 2001 From: Steelwing723 Date: Mon, 24 Jan 2022 09:39:44 -0600 Subject: [PATCH 2/9] Various --- art.py | 4 +-- classes.py | 34 ------------------------- colors.py | 41 ++++++++++++++++++++++++++++++- menu_fiefBuildings.py | 39 +++++++++++++++-------------- menu_upgradesAndCustomizations.py | 2 +- 5 files changed, 63 insertions(+), 57 deletions(-) diff --git a/art.py b/art.py index 3e6d309..54a200c 100644 --- a/art.py +++ b/art.py @@ -40,7 +40,7 @@ def header(username): ' |_|| || |(_||||(/_(_| | | (/_ | (_|(_)||| \_|(_||||(/_ \n' + ' ' + '\n' + - (line5.center(138, '-')) + '\n' + + (line5.center(156, '-')) + '\n' + (line6.center(155, ' ')) + '\n') # (ANNOUNCEMENT.center(119, '-')) + ' ') @@ -66,7 +66,7 @@ def headerHomeStronghold(username): ' |_|| || |(_||||(/_(_| | | (/_ | (_|(_)||| \_|(_||||(/_ \n' + ' ' + '\n' + - (line5.center(138, '-')) + '\n' + + (line5.center(156, '-')) + '\n' + (line6.center(155, ' ')) + '\n' + (ANNOUNCEMENT.center(120, '-')) + ' ') diff --git a/classes.py b/classes.py index 2b47134..42d2b91 100644 --- a/classes.py +++ b/classes.py @@ -39,40 +39,6 @@ def biomeColor(biome): return textColor.GREEN elif biome == PLAINS: return textColor.YELLOW - -def strongholdColor(color): - if color == 'red': - return RED - if color == 'green': - return GREEN - if color == 'magenta': - return MAGENTA - if color == 'white': - return BOLD - if color == 'blue': - return BLUE - if color == 'yellow': - return YELLOW - if color == 'cyan': - return CYAN - if color == 'gray': - return DARK_GRAY - if color == 'purple': - return PURPLE - if color == 'orange': - return ORANGE - if color == 'teal': - return TEAL - if color == 'pink': - return PINK - if color == 'brown': - return BROWN - if color == 'mint': - return MINT - if color == 'salmon': - return SALMON - if color == 'lavender': - return LAVENDER #the fiefdom class holds variables that define a player's stats class Fiefdom: diff --git a/colors.py b/colors.py index d3d5b20..69685ee 100644 --- a/colors.py +++ b/colors.py @@ -112,4 +112,43 @@ class textColor: C_FOOD = DARK_RED C_WOOD = DARK_GREEN C_STONE = DARK_GRAY -C_ORE = DARK_MAGENTA \ No newline at end of file +C_ORE = DARK_MAGENTA + +#=====================#=====================#===================== +# [strongholdColor] +# parameter: color +# returns: a color code based on the passed color variable +#=====================#=====================#===================== +def strongholdColor(color): + if color == 'red': + return RED + if color == 'green': + return GREEN + if color == 'magenta': + return MAGENTA + if color == 'white': + return BOLD + if color == 'blue': + return BLUE + if color == 'yellow': + return YELLOW + if color == 'cyan': + return CYAN + if color == 'gray': + return DARK_GRAY + if color == 'purple': + return PURPLE + if color == 'orange': + return ORANGE + if color == 'teal': + return TEAL + if color == 'pink': + return PINK + if color == 'brown': + return BROWN + if color == 'mint': + return MINT + if color == 'salmon': + return SALMON + if color == 'lavender': + return LAVENDER \ No newline at end of file diff --git a/menu_fiefBuildings.py b/menu_fiefBuildings.py index 21056cd..9d8f1f6 100644 --- a/menu_fiefBuildings.py +++ b/menu_fiefBuildings.py @@ -67,13 +67,14 @@ def FiefBuildingsMenu(screen, userStronghold): if int(attackFief.op_mineSecondaryUnits) > 0: print(" You have " + WARNING + str(attackFief.op_mineSecondaryUnits) + COLOR_PROSPECTOR + " Prospectors" + RESET + " gathering iron at a rate of " + CYAN + str(attackFief.GetSecondaryPer("mine")) + RESET + " per hour.\n") - print(' --------------------------------------') - print(" You see room for:") - print(" " + GREEN + str(attackFief.adjacentPlains) + RESET + " Farms") - print(" " + GREEN + str(attackFief.adjacentWater) + RESET + " Fisheries") - print(" " + GREEN + str(attackFief.adjacentForests) + RESET + " Lumber Mills") - print(" " + GREEN + str(attackFief.adjacentMountains) + RESET + " Mines") - print(' --------------------------------------') + if attackFief.op_farmlandNumBuilt == '0' and attackFief.op_fisheryNumBuilt == '0' and attackFief.op_lumberMillNumBuilt == '0' and attackFief.op_mineNumBuilt == '0': + print(' --------------------------------------') + print(" You see room for:") + print(" " + GREEN + str(attackFief.adjacentPlains) + RESET + " Farms") + print(" " + GREEN + str(int(attackFief.adjacentWater) + int(attackFief.adjacentRivers)) + RESET + " Fisheries") + print(" " + GREEN + str(attackFief.adjacentForests) + RESET + " Lumber Mills") + print(" " + GREEN + str(attackFief.adjacentMountains) + RESET + " Mines") + print(' --------------------------------------') print("\n Avalible Commands:") @@ -138,7 +139,7 @@ def FiefBuildingsMenu(screen, userStronghold): art_placeholder("Art of a Farmland outpost based on current tier") print("\n Avalible Commands:") - print(' -------------------------------------') + print(' --------------------------------------------------------------------------') print(' {1}: Go Back') if int(attackFief.op_farmlandPrimaryUnits) < (int(UCAP_FARMER) * int(attackFief.op_farmlandNumBuilt)): print(' {2}: Hire' + COLOR_FARMER + ' Farmers' + RESET) @@ -147,8 +148,8 @@ def FiefBuildingsMenu(screen, userStronghold): if int(attackFief.op_farmlandNumBuilt) > 0 and int(attackFief.op_farmlandTier) < 2: print(' {4}: Upgrade' + OP_COLOR_FARMLAND + ' Farmlands' + RESET) if int(attackFief.op_farmlandNumBuilt) < int(attackFief.adjacentPlains): - print(' {5}: Construct New' + OP_COLOR_FARMLAND + ' Farmland' + RESET) - print(' -------------------------------------') + print(' {5}: Construct New' + OP_COLOR_FARMLAND + ' Farmland' + RESET + " (Room for " + LIME + str(int(attackFief.adjacentPlains) - int(attackFief.op_farmlandNumBuilt)) + RESET + " more)") + print(' --------------------------------------------------------------------------') print('') command = input(" Enter your command: ") @@ -202,7 +203,7 @@ def FiefBuildingsMenu(screen, userStronghold): art_placeholder("Art of a Fishery outpost based on current tier") print("\n Avalible Commands:") - print(' -------------------------------------') + print(' --------------------------------------------------------------------------') print(' {1}: Go Back') if int(attackFief.op_fisheryPrimaryUnits) < (int(UCAP_FISHER) * int(attackFief.op_fisheryNumBuilt)): print(' {2}: Hire' + COLOR_FISHER + ' Fishers' + RESET) @@ -211,8 +212,8 @@ def FiefBuildingsMenu(screen, userStronghold): if int(attackFief.op_fisheryNumBuilt) > 0 and int(attackFief.op_fisheryTier) < 2: print(' {4}: Upgrade' + OP_COLOR_FISHERY + ' Fisheries' + RESET) if int(attackFief.op_fisheryNumBuilt) < int(attackFief.adjacentWater) + int(attackFief.adjacentRivers): - print(' {5}: Construct New' + OP_COLOR_FISHERY + ' Fishery' + RESET) - print(' -------------------------------------') + print(' {5}: Construct New' + OP_COLOR_FISHERY + ' Fishery' + RESET + " (Room for " + LIME + str(int(attackFief.adjacentWater) + int(attackFief.adjacentRivers) - int(attackFief.op_fisheryNumBuilt)) + RESET + " more)") + print(' --------------------------------------------------------------------------') print('') command = input(" Enter your command: ") @@ -264,7 +265,7 @@ def FiefBuildingsMenu(screen, userStronghold): art_placeholder("Art of a Lumber Mill outpost based on current tier") print("\n Avalible Commands:") - print(' -------------------------------------') + print(' --------------------------------------------------------------------------') print(' {1}: Go Back') if int(attackFief.op_lumberMillPrimaryUnits) < (int(UCAP_LUMBERJACK) * int(attackFief.op_lumberMillNumBuilt)): print(' {2}: Hire' + COLOR_LUMBERJACK + ' Lumberjacks' + RESET) @@ -273,8 +274,8 @@ def FiefBuildingsMenu(screen, userStronghold): if int(attackFief.op_lumberMillNumBuilt) > 0 and int(attackFief.op_lumberMillTier) < 2: print(' {4}: Upgrade' + OP_COLOR_LUMBERMILL + ' Lumber Mills' + RESET) if int(attackFief.op_lumberMillNumBuilt) < int(attackFief.adjacentForests): - print(' {5}: Construct New' + OP_COLOR_LUMBERMILL + ' Lumber Mill' + RESET) - print(' -------------------------------------') + print(' {5}: Construct New' + OP_COLOR_LUMBERMILL + ' Lumber Mill' + RESET + " (Room for " + LIME + str(int(attackFief.adjacentForests) - int(attackFief.op_lumberMillNumBuilt)) + RESET + " more)") + print(' --------------------------------------------------------------------------') print('') command = input(" Enter your command: ") @@ -325,7 +326,7 @@ def FiefBuildingsMenu(screen, userStronghold): art_placeholder("Art of a Mine outpost based on current tier") print("\n Avalible Commands:") - print(' -------------------------------------') + print(' --------------------------------------------------------------------------') print(' {1}: Go Back') if int(attackFief.op_minePrimaryUnits) < (int(UCAP_MINER) * int(attackFief.op_mineNumBuilt)): print(' {2}: Hire' + COLOR_MINER + ' Miners' + RESET) @@ -334,8 +335,8 @@ def FiefBuildingsMenu(screen, userStronghold): if int(attackFief.op_mineNumBuilt) > 0 and int(attackFief.op_mineTier) < 2: print(' {4}: Upgrade' + OP_COLOR_MINE + ' Mines' + RESET) if int(attackFief.op_mineNumBuilt) < int(attackFief.adjacentMountains): - print(' {5}: Construct New' + OP_COLOR_MINE + ' Mine' + RESET) - print(' -------------------------------------') + print(' {5}: Construct New' + OP_COLOR_MINE + ' Mine' + RESET + " (Room for " + LIME + str(int(attackFief.adjacentMountains) - int(attackFief.op_mineNumBuilt)) + RESET + " more)") + print(' --------------------------------------------------------------------------') print('') command = input(" Enter your command: ") diff --git a/menu_upgradesAndCustomizations.py b/menu_upgradesAndCustomizations.py index e340d28..ee0b91e 100644 --- a/menu_upgradesAndCustomizations.py +++ b/menu_upgradesAndCustomizations.py @@ -224,7 +224,7 @@ def UpgradesAndCustomizations(screen, userStronghold): print(''' {2}: Green '''+GREEN+'''#'''+RESET+''' {11}: Orange '''+ORANGE+'''#'''+RESET+''' ''') print(''' {3}: Blue '''+BLUE+'''#'''+RESET+''' {12}: Teal '''+TEAL+'''#'''+RESET+''' ''') print(''' {4}: Yellow '''+YELLOW+'''#'''+RESET+''' {13}: Pink '''+PINK+'''#'''+RESET+''' ''') - print(''' {5}: Magenta '''+MAGENTA+'''#'''+RESET+''' {14}: Brown '''+BROWN+'''#'''+RESET+''' ''') + print(''' {5}: Magenta '''+MAGENTA+'''#'''+RESET+''' {14}: Brown '''+BROWN+'''#'''+RESET+''' ''') print(''' {6}: Cyan '''+CYAN+'''#'''+RESET+''' {15}: Mint '''+MINT+'''#'''+RESET+''' ''') print(''' {7}: White '''+BOLD+'''#'''+RESET+''' {16}: Salmon '''+SALMON+'''#'''+RESET+''' ''') print(''' {8}: Gray '''+DARK_GRAY+'''#'''+RESET+''' {17}: Lavender '''+LAVENDER+'''#'''+RESET+''' ''') From fa22aadaa29d84093450d5cea20307d5a187b094 Mon Sep 17 00:00:00 2001 From: Steelwing723 Date: Mon, 24 Jan 2022 16:04:52 -0600 Subject: [PATCH 3/9] Battalions --- armies.py | 140 ++++++++++++----- art.py | 24 ++- colors.py | 24 ++- fiefdomgame.py | 7 +- globals.py | 167 +++++++++++++++++++- menu_battalions.py | 45 +++++- worldmap.py | 369 +++++++++++++++++++++++++++++++++++++++++++++ 7 files changed, 725 insertions(+), 51 deletions(-) diff --git a/armies.py b/armies.py index 6a9de7d..9d04072 100644 --- a/armies.py +++ b/armies.py @@ -1,4 +1,6 @@ from colors import * +from classes import * +import random #====================================================================================== # ::Idea Board:: @@ -62,11 +64,23 @@ class Armies: # xPos, yPos # Adds a new battalion to the Armies battalions list #================================================================================== - def AddBattalion(self, name, commander, numTroops, attLevel, speed, stamina, rations, xPos, yPos): - newBattalion = Battalion(name, commander, numTroops, attLevel, speed, stamina, rations, xPos, yPos) + def AddBattalion(self, name, commander, numTroops, attLevel, speed, stamina, rations, xPos, yPos, invGold, invFood, invWood, invStone, invOre): + newBattalion = Battalion(name, commander, numTroops, attLevel, speed, stamina, rations, xPos, yPos, invGold, invFood, invWood, invStone, invOre) self.battalions.append(newBattalion) - self.write() - self.read() + + #================================================================================== + # [ExistingName] + # parameters: self, name + # returns: True/False + # Compares passed name to other battalion names in battalions + #================================================================================== + def ExistingName(self, name): + # self.read() + for i in range(len(self.battalions)): + if str(self.battalions[i].name) == str(name): + return True + else: + return False #================================================================================== # [GetBattalions] @@ -79,6 +93,17 @@ def GetBattalions(self): batts.append(self.battalions[i].ListDetails()) return batts + #================================================================================== + # [GetBattalionObjects] + # parameters: self + # Gets a list of battalions + #================================================================================== + def GetBattalionObjects(self): + batts = [] + for i in range(len(self.battalions)): + batts.append(self.battalions[i]) + return batts + #================================================================================== # [GetBattalion] # parameters: self, index @@ -101,34 +126,8 @@ def RemoveBattalion(self, index): #================================================================================== def write(self): armiesFile = 'armies/serverArmies.txt' - #If no file has been made yet: - try: - with open(armiesFile, 'x') as f: - f.write(str("[")) - for i in range(len(self.battalions)): - f.write(str("[")) - f.write("('" + str(self.battalions[i].name) + "'), ") - f.write("('" + str(self.battalions[i].commander) + "'), ") - f.write("('" + str(self.battalions[i].numTroops) + "'), ") - f.write("('" + str(self.battalions[i].attLevel) + "'), ") - f.write("('" + str(self.battalions[i].speed) + "'), ") - f.write("('" + str(self.battalions[i].stamina) + "'), ") - f.write("('" + str(self.battalions[i].rations) + "'), ") - f.write("('" + str(self.battalions[i].xPos) + "'), ") - f.write("('" + str(self.battalions[i].yPos) + "')") - if i < len(self.battalions) - 1: - f.write(str("], ")) - else: - f.write(str("]")) - f.write(str("]")) - except: - print('Could not write armies file!') - pass - #If file has already been made: try: - print("Trying to Open") - with open(armiesFile, 'x') as f: - print("About to loop") + with open(armiesFile, 'w') as f: f.write(str("[")) for i in range(len(self.battalions)): f.write(str("[")) @@ -140,7 +139,12 @@ def write(self): f.write("('" + str(self.battalions[i].stamina) + "'), ") f.write("('" + str(self.battalions[i].rations) + "'), ") f.write("('" + str(self.battalions[i].xPos) + "'), ") - f.write("('" + str(self.battalions[i].yPos) + "')") + f.write("('" + str(self.battalions[i].yPos) + "'),") + f.write("('" + str(self.battalions[i].invGold) + "'),") + f.write("('" + str(self.battalions[i].invFood) + "'),") + f.write("('" + str(self.battalions[i].invWood) + "'),") + f.write("('" + str(self.battalions[i].invStone) + "'),") + f.write("('" + str(self.battalions[i].invOre) + "')") if i < len(self.battalions) - 1: f.write(str("], ")) else: @@ -162,7 +166,7 @@ def read(self): readArmiesFile.close() for i in range(len(rL)): - self.AddBattalion(str(rL[i][0]), str(rL[i][1]), str(rL[i][2]), str(rL[i][3]), str(rL[i][4]), str(rL[i][5]), str(rL[i][6]), str(rL[i][7]), str(rL[i][8])) + self.AddBattalion(str(rL[i][0]), str(rL[i][1]), str(rL[i][2]), str(rL[i][3]), str(rL[i][4]), str(rL[i][5]), str(rL[i][6]), str(rL[i][7]), str(rL[i][8]), str(rL[i][9]), str(rL[i][10]), str(rL[i][11]), str(rL[i][12]), str(rL[i][13])) except: print('Could not read armies file!') @@ -178,8 +182,13 @@ class Battalion: rations = "0" xPos = "0" yPos = "0" + invGold = "0" + invFood = "0" + invWood = "0" + invStone = "0" + invOre = "0" - def __init__(self, name, commander, numTroops, attLevel, speed, stamina, rations, xPos, yPos): + def __init__(self, name, commander, numTroops, attLevel, speed, stamina, rations, xPos, yPos, invGold, invFood, invWood, invStone, invOre): self.name = name self.commander = commander self.numTroops = numTroops @@ -189,6 +198,11 @@ def __init__(self, name, commander, numTroops, attLevel, speed, stamina, rations self.rations = rations self.xPos = xPos self.yPos = yPos + self.invGold = invGold + self.invFood = invFood + self.invWood = invWood + self.invStone = invStone + self.invOre = invOre def ListDetails(self): name = str(" name: " + str(self.name)) @@ -200,6 +214,62 @@ def ListDetails(self): rations = str(" rations: " + str(self.rations)) xPos = str(" xPos: " + str(self.xPos)) yPos = str(" yPos: " + str(self.yPos)) + invGold = str(" Gold: " + str(self.invGold)) + invFood = str(" Food: " + str(self.invFood)) + invWood = str(" Wood: " + str(self.invWood)) + invStone = str(" Stone: " + str(self.invStone)) + invOre = str(" Ore: " + str(self.invOre)) + + return str(name + commander + numTroops + attLevel + speed + stamina + rations + xPos + yPos + invGold + invFood + invWood + invStone + invOre) + + def MenuBar(self, userStronghold): + SHC = StrongholdColor(userStronghold.color) + name = str("{ " + SHC + str(self.name) + RESET + " }") + # commander = str(" commander: " + str(self.commander)) + numTroops = str(" | Warriors: " + COLOR_WARRIOR + str(self.numTroops) + RESET) + attLevel = str(" | Attack: " + MAGENTA + str(self.attLevel) + RESET) + speed = str(" | Speed: " + LIME + str(self.speed) + RESET) + stamina = str(" | Stamina: " + YELLOW + str(self.stamina) + RESET) + # rations = str(" | Rations: " + C_FOOD + str(self.rations) + RESET) + xPos = str(" | X: " + RED_GRAY + str(self.xPos) + RESET) + yPos = str(" | Y: " + RED_GRAY + str(self.yPos) + RESET) + + return str(name + numTroops + attLevel + speed + stamina + xPos + yPos) + + def MenuBarWithLocation(self, userStronghold, location): + SHC = StrongholdColor(userStronghold.color) + name = str("{ " + SHC + str(self.name) + RESET + " }") + # commander = str(" commander: " + str(self.commander)) + numTroops = str(" | Warriors: " + COLOR_WARRIOR + str(self.numTroops) + RESET) + attLevel = str(" | Attack: " + MAGENTA + str(self.attLevel) + RESET) + speed = str(" | Speed: " + LIME + str(self.speed) + RESET) + stamina = str(" | Stamina: " + YELLOW + str(self.stamina) + RESET) + # rations = str(" | Rations: " + C_FOOD + str(self.rations) + RESET) + # xPos = str(" | X: " + RED_GRAY + str(self.xPos) + RESET) + # yPos = str(" | Y: " + RED_GRAY + str(self.yPos) + RESET) + loc = str(" | Location: " + RED_GRAY + location) + + return str(name + numTroops + attLevel + speed + stamina + loc) + + def Inventory(self): + invGold = str("| Gold: " + C_GOLD + str(self.invGold) + RESET) + invFood = str(" | Food: " + C_FOOD + str(self.invFood) + RESET) + invWood = str(" | Wood: " + C_WOOD + str(self.invWood) + RESET) + invStone = str(" | Stone: " + C_STONE + str(self.invStone) + RESET) + invOre = str(" | Ore: " + C_ORE + str(self.invOre) + RESET + " |") + + return str(invGold + invFood + invWood + invStone + invOre) + + def PrintGold(self): + return str(C_GOLD + str(self.invGold) + RESET) + def PrintFood(self): + return str(C_FOOD + str(self.invFood) + RESET) + def PrintWood(self): + return str(C_WOOD + str(self.invWood) + RESET) + def PrintStone(self): + return str(C_STONE + str(self.invStone) + RESET) + def PrintOre(self): + return str(C_ORE + str(self.invOre) + RESET) + - return str(name + commander + numTroops + attLevel + speed + stamina + rations + xPos + yPos) diff --git a/art.py b/art.py index 54a200c..d635628 100644 --- a/art.py +++ b/art.py @@ -1,4 +1,4 @@ -from classes import * +from worldmap import * #This displays the announcement game-wide #Format it with spaces at the beginning and end @@ -153,6 +153,26 @@ def headerFief(fief): (line5.center(173, '-')) + '\n') # (ANNOUNCEMENT.center(110, '-')) + '\n') +#This is a header for displaying Battalion information. +def headerBattalion(bat, userStronghold, serverMap): + location = GetLocation(serverMap, bat.yPos, bat.xPos) + if location == "": + menu = str(bat.MenuBar(userStronghold)) + spacer = 196 + else: + menu = str(bat.MenuBarWithLocation(userStronghold, location)) + spacer = 186 + R = textColor.RESET + C = userStronghold.color + inventory = bat.Inventory() + print('\n' + +' __ _ __ \n' + +' | |__ __ _ __ _ _| |_ o _ _|_ _| _ __ /__ _ __ _ \n' + +' |_|| || |(_||||(/_(_| | | (/_ | (_|(_)||| \_|(_||||(/_ \n' + +' ' + '\n' + + (menu.center(spacer, '-')) + '\n' + + (inventory.center(170, '-')) + '\n') + #Define Art: #==================================================================================================================== # Splash Screen Art @@ -262,7 +282,7 @@ def art_titleScreen(): def art_stronghold(biome, color): #if an error is thrown related to this art, it is likely just because #the passed biome/color didn't have a value. The real problem is with the stronghold class. - F = strongholdColor(color) + F = StrongholdColor(color) C = biomeColor(biome) R = textColor.RESET M = textColor.MAGENTA diff --git a/colors.py b/colors.py index 69685ee..eec6e0f 100644 --- a/colors.py +++ b/colors.py @@ -115,11 +115,11 @@ class textColor: C_ORE = DARK_MAGENTA #=====================#=====================#===================== -# [strongholdColor] +# [StrongholdColor] # parameter: color # returns: a color code based on the passed color variable #=====================#=====================#===================== -def strongholdColor(color): +def StrongholdColor(color): if color == 'red': return RED if color == 'green': @@ -151,4 +151,22 @@ def strongholdColor(color): if color == 'salmon': return SALMON if color == 'lavender': - return LAVENDER \ No newline at end of file + return LAVENDER + + + +#define biome globals: +WATER = '~' +RIVER = ['/','|','\\'] +MOUNTAIN = 'M' +PLAINS = '#' +FOREST = '^' +BACKSLASH_SUB = 'L' #This needed to be added so the program could properly read/write '\' + +def BiomeColor(biome): + if biome == MOUNTAIN: + return textColor.DARK_GRAY + elif biome == FOREST: + return textColor.GREEN + elif biome == PLAINS: + return textColor.YELLOW \ No newline at end of file diff --git a/fiefdomgame.py b/fiefdomgame.py index 2ec94e4..b31ee09 100644 --- a/fiefdomgame.py +++ b/fiefdomgame.py @@ -349,7 +349,7 @@ print(' {3}: Hire and Recruit {9}: More Options') print(' {4}: Upgrades and Customization {10}: How To Play') print(' {5}: View The World Map {11}: View Event Log') - print(' {6}: Send Resources To Your Fiefdoms') + print(' {6}: Send Resources To Your Fiefdoms {12}: Manage Battalions') print(' ----------------------------------------------------------------------------------------------------') print('') command = input(" Enter your command: ") @@ -388,6 +388,11 @@ if command == '11': screen = 'logPrint' + if command == '12': + STRONGHOLD = True + USER_STRONGHOLD = True + screen = 'battalions' + #The following command is for testing only! if command == 'devtest' or command == 'dt': diff --git a/globals.py b/globals.py index 7a0e1c2..dae3f6f 100644 --- a/globals.py +++ b/globals.py @@ -69,6 +69,13 @@ MARKET_ITEM_THRESHOLD = 5 MAX_LISTING_AMOUNT = 10 +#===================== +# Others +#===================== +ILLEGAL_CHARACTERS = ["\\", "//", "`", "{", "}", "(", ")", "[", "]", "_", "*", "$", "#", "<", ">", "'"] +ILLEGAL_USERNAMES = ['', ' ', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '10', '11', '12', '13', '14', '15', 'The Wandering Merchant'] +BATTALION_NAME_CAP = 25 + #===================== # Resources #===================== @@ -92,7 +99,7 @@ FIEFDOM_WARRIOR_MAX = 100 #===================== -# Weather +# Weather #===================== WEATHER_SYSTEM_MOD = 0 #think of this as a seasonal modifier for temperature BASELINE_TEMP = 72 #this is the baseline for global temp calculations @@ -248,12 +255,11 @@ def FirstLaunch(): # Prevents the use of certain usernames that may interfere with menu operations. #======================================================================================================== def CheckLegalUsername(username): - illegalUserNames = ['', ' ', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '10', '11', '12', '13', '14', '15', 'The Wandering Merchant'] if len(username) < 18: if username.strip() == "": return False - for i in range(len(illegalUserNames)): - if username == illegalUserNames[i]: + for i in range(len(ILLEGAL_USERNAMES)): + if username == ILLEGAL_USERNAMES[i]: return False return True os.system('clear') @@ -2206,3 +2212,156 @@ def PurchasedGood(userStronghold, num): # current_time = now.strftime("%H:%M") # logFile.write('\n' + username + ' |--| Time: ' + current_time + ' |--| Event: ' + inputString) + + + + + + + + +#======================================================================================================== +# [IsPositiveIntEqualOrGreaterThan] +# parameters: integer, amount +# returns: True/False +# Checks if passed integer is both positive and an integer and then if it is more than "amount" +#======================================================================================================== +def IsPositiveIntEqualOrGreaterThan(integer, amount): + if IsPositiveInteger(integer) == False: + return False + elif int(integer) < int(amount): + return False + else: + return True + + + + +#======================================================================================================== +#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +#======================================================================================================== +# Battalions +#======================================================================================================== +#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +#======================================================================================================== + +#================================================================================== +# [GetAnswer] +# parameters: question, qType, comparable, cap +# When passed a question, checks the type and compares it to the comparable +# before eventually returning a proper result. +#================================================================================== +def GetAnswer(question, qType, comparable, cap): + looping = True + foundChar = False + while looping: + if qType == '>': + response = input(question) + if IsPositiveIntEqualOrGreaterThan(response, comparable): + if cap != None: + if int(response) > int(cap): + print(" Error, can't be over " + str(cap) + "!") + else: + return response + else: + return response + else: + print(" Input a positive integer equal to or greater than: " + str(comparable)) + elif qType == '<': + response = input(question) + if IsPositiveIntEqualOrLessThan(response, comparable): + return response + else: + print(" Input a positive integer equal to or less than: " + str(comparable)) + elif qType == 'in': + response = input(question) + if response in comparable: + return response + else: + print(" Choose a proper option from: " + str(*comparable)) + + elif qType == 'legalString': + response = input(question) + if int(len(response)) <= int(cap): + for i in range(len(ILLEGAL_USERNAMES)): + if str(ILLEGAL_USERNAMES[i]) == str(response): + print(" Error, not a legal input!") + return "" + for i in range(len(ILLEGAL_CHARACTERS)): + for j in range(len(response)): + if response[j] == ILLEGAL_CHARACTERS[i]: + foundChar = True + badChar = response[j] + break + else: + continue + break + if foundChar: + print(" Error, can't use " + str(badChar) + " in input!\n") + else: + return response + else: + print(" Error, input can't be longer than " + str(cap) + " characters!\n") + else: + return "" + + + +#================================================================================== +# [CreateNewBattalion] +# parameter: station +# Makes a new battalion at the passed station +#================================================================================== +def CreateNewBattalion(station): + if isinstance(station, Stronghold): + os.system("clear") + header(station.name) + if int(station.defenders) < BATTALION_MIN: + print("\n You don't have enough warriors at this location to make a battalion!\n") + nothing = input(" Press enter to continue : ") + return "battalions" + else: + name = "Default Battalion" + commander = str(station.ruler) + numTroops = BATTALION_MIN + attLevel = station.attLevel + speed = 1 + stamina = 1 + rations = 0 + xPos = str(station.xCoordinate) + yPos = str(station.yCoordinate) + + os.system("clear") + header(station.name) + print("\n Creating New Battalion: \n") + + name = GetAnswer(" Name your Battalion: ", "legalString", None, BATTALION_NAME_CAP) + if str(name) == "": + return "battalions" + if serverArmies.ExistingName(name): + print("\n Battalion name already taken!") + nothing = input(" Press enter to continue") + return "battalions" + print("") + numTroops = GetAnswer(str(" How many troops will you assign to " + WARNING + str(name) + RESET + "? [min " + str(BATTALION_MIN) + "]: "), ">", BATTALION_MIN, BATTALION_MAX) + if int(numTroops) > int(station.defenders): + print(" You don't have enough troops for this battalion!\n") + nothing = input(" Press enter to continue") + return "battalions" + print("") + + serverArmies.AddBattalion(str(name), str(commander), str(numTroops), str(attLevel), str(speed), str(stamina), str(rations), str(xPos), str(yPos), 0, 0, 0, 0, 0) + serverArmies.write() + nothing = input(" Press enter to continue") + return "battalions" + + else: + os.system("clear") + headerFief(station) + if int(station.defenders) < BATTALION_MIN: + print("\n You don't have enough warriors at this location to make a battalion!\n") + nothing = input(" Press enter to continue : ") + return "battalions" + + return "battalions" + diff --git a/menu_battalions.py b/menu_battalions.py index 5fa9bb0..bb2746f 100644 --- a/menu_battalions.py +++ b/menu_battalions.py @@ -2,26 +2,35 @@ from armies import * def BattalionMenu(screen, userStronghold, STRONGHOLD, USER_STRONGHOLD): + currentBattalion = 0 if screen == "battalions": os.system("clear") header(userStronghold.name) serverArmies.read() - battalions = serverArmies.GetBattalions() + battalions = serverArmies.GetBattalionObjects() count = 0 - print("\n Your Battalions\n") + yourBattalions = [] + + print("\n Battalions at Your Command:\n") for i in range(len(battalions)): if str(battalions[i].commander) == str(userStronghold.name): count = count + 1 + yourBattalions.append(battalions[i]) leftNumber = str(CYAN + " {" + str(count) + "}" + RESET).rjust(17, " ") - print(str(leftNumber) + " " + str(battalions[i].ListDetails)) + location = GetLocation(serverMap, battalions[i].yPos, battalions[i].xPos) + if location == "": + print(str(leftNumber) + " " + str(battalions[i].MenuBar(userStronghold))) + else: + print(str(leftNumber) + " " + str(battalions[i].MenuBarWithLocation(userStronghold, location))) print("\n Avalible Commands:") print(' ------------------------------------------------------') print(' {R}: Return to Stronghold') - print(' {Enter a number above to view the offer}: ') + print(' {C}: Create Battalion') + print(' ' + CYAN + '{Enter a number above to view that battalion}: ' + RESET) print(' ------------------------------------------------------') print('') command = input(" Enter your command: ") @@ -29,8 +38,32 @@ def BattalionMenu(screen, userStronghold, STRONGHOLD, USER_STRONGHOLD): command = str(command.lower()) if str(command) == 'r': - screen = "stronghold" + return "stronghold" + elif str(command) == 'c': + return CreateNewBattalion(userStronghold) + elif IsPositiveIntEqualOrLessThan(command, count): + currentBattalion = yourBattalions[int(command) - 1] + screen = "commandBattalion" + else: + return "battalions" + + if screen == "commandBattalion": + os.system("clear") + headerBattalion(currentBattalion, userStronghold, serverMap) + GenerateMiniMap(serverMap, currentBattalion.yPos, currentBattalion.xPos) + + print() + + print("\n Avalible Commands:") + print(' ------------------------------------------------------') + print(' {1}: Go Back') + print(' ------------------------------------------------------') + print('') + command = input(" Enter your command: ") + + if str(command) == '1': + return "battalions" else: - screen = "market" + return "battalions" return screen \ No newline at end of file diff --git a/worldmap.py b/worldmap.py index b7b2086..e7fd5e6 100644 --- a/worldmap.py +++ b/worldmap.py @@ -2520,4 +2520,373 @@ def LoadingAnimation(thingLoading): print(thingLoading + '...') time.sleep(0.1) + + + +#-------------------------------------------------------------------------------------------------------------- +# [PositionOffMap] +# parameters: y, x +# returns: True/False - if either coordinate is off the map +#-------------------------------------------------------------------------------------------------------------- +def PositionOffMap(y, x): + if int(y) < 0: + return True + if int(x) < 0: + return True + if int(y) >= MAP_HEIGHT: + return True + if int(x) >= MAP_WIDTH: + return True + + return False + + +#-------------------------------------------------------------------------------------------------------------- +# [FarScanSurroundings] +# parameters: mapClass, posY, posX +# returns: 2d list of surroundings (2 spaces out from center) +#-------------------------------------------------------------------------------------------------------------- +def FarScanSurroundings(mapClass, y, x): + wMap = mapClass.worldMap + posY = int(y) + posX = int(x) + + C = LOCATION + try: + dN = wMap[posY - 1][posX] + if PositionOffMap(posY-1, posX): + dN = ' ' + except: + dN = ' ' + try: + dNN = wMap[posY - 2][posX] + if PositionOffMap(posY-2, posX): + dNN = ' ' + except: + dNN = ' ' + try: + dNE = wMap[posY - 1][posX + 1] + if PositionOffMap(posY-1, posX+1): + dNE = ' ' + except: + dNE = ' ' + try: + dNNE = wMap[posY - 2][posX + 1] + if PositionOffMap(posY-2, posX+1): + dNNE = ' ' + except: + dNNE = ' ' + try: + dNNEE = wMap[posY - 2][posX + 2] + if PositionOffMap(posY-2, posX+2): + dNNEE = ' ' + except: + dNNEE = ' ' + try: + dNEE = wMap[posY - 1][posX + 2] + if PositionOffMap(posY-1, posX+2): + dNEE = ' ' + except: + dNEE = ' ' + try: + dE = wMap[posY][posX + 1] + if PositionOffMap(posY, posX+1): + dE = ' ' + except: + dE = ' ' + try: + dEE = wMap[posY][posX + 2] + if PositionOffMap(posY, posX+2): + dEE = ' ' + except: + dEE = ' ' + try: + dSE = wMap[posY + 1][posX + 1] + if PositionOffMap(posY+1, posX+1): + dSE = ' ' + except: + dSE = ' ' + try: + dSEE = wMap[posY + 1][posX + 2] + if PositionOffMap(posY+1, posX+2): + dSEE = ' ' + except: + dSEE = ' ' + try: + dSSEE = wMap[posY + 2][posX + 2] + if PositionOffMap(posY+2, posX+2): + dSSEE = ' ' + except: + dSSEE = ' ' + try: + dSSE = wMap[posY + 2][posX + 1] + if PositionOffMap(posY+2, posX+1): + dSSE = ' ' + except: + dSSE = ' ' + try: + dS = wMap[posY + 1][posX] + if PositionOffMap(posY+1, posX): + dS = ' ' + except: + dS = ' ' + try: + dSS = wMap[posY + 2][posX] + if PositionOffMap(posY+2, posX): + dSS = ' ' + except: + dSS = ' ' + try: + dSW = wMap[posY + 1][posX - 1] + if PositionOffMap(posY+1, posX-1): + dSW = ' ' + except: + dSW = ' ' + try: + dSSW = wMap[posY + 2][posX - 1] + if PositionOffMap(posY+2, posX-1): + dSSW = ' ' + except: + dSSW = ' ' + try: + dSSWW = wMap[posY + 2][posX - 2] + if PositionOffMap(posY+2, posX-2): + dSSWW = ' ' + except: + dSSWW = ' ' + try: + dSWW = wMap[posY + 1][posX - 2] + if PositionOffMap(posY+1, posX-2): + dSWW = ' ' + except: + dSWW = ' ' + try: + dW = wMap[posY][posX - 1] + if PositionOffMap(posY, posX-1): + dW = ' ' + except: + dW = ' ' + try: + dWW = wMap[posY][posX - 2] + if PositionOffMap(posY, posX-2): + dWW = ' ' + except: + dWW = ' ' + try: + dNW = wMap[posY - 1][posX - 1] + if PositionOffMap(posY-1, posX-1): + dNW = ' ' + except: + dNW = ' ' + try: + dNWW = wMap[posY - 1][posX - 2] + if PositionOffMap(posY-1, posX-2): + dNWW = ' ' + except: + dNWW = ' ' + try: + dNNWW = wMap[posY - 2][posX - 2] + if PositionOffMap(posY-2, posX-2): + dNNWW = ' ' + except: + dNNWW = ' ' + try: + dNNW = wMap[posY - 2][posX - 1] + if PositionOffMap(posY-2, posX-1): + dNNW = ' ' + except: + dNNW = ' ' + + # return [dN, dNE, dE, dSE, dS, dSW, dW, dNW] + # return [dN, dNN, dNE, dNNE, dNNEE, dNEE, dE, dEE, dSE, dSEE, dSSEE, dSSE, dS, dSS, dSW, dSSW, dSSWW, dSWW, dW, dWW, dNW, dNWW, dNNWW, dNNW] + return [[dNNWW, dNNW, dNN, dNNE, dNNEE], [dNWW, dNW, dN, dNE, dNEE], [dWW, dW, C, dE, dEE], [dSWW, dSW, dS, dSE, dSEE], [dSSWW, dSSW, dSS, dSSE, dSSEE]] + +#-------------------------------------------------------------------------------------------------------------- +# [PrintMiniMap] +# parameters: mList +# prints out a minimap based on passed 2d-list +#-------------------------------------------------------------------------------------------------------------- +def PrintMiniMap(mList, y, x): + borderColor = RED_GRAY + borderSymb = str('-') + print(borderColor + " " + str("Surroundings").center(19, borderSymb) + RESET) + for i in range(len(mList)): + print(str(borderColor + " " + borderSymb + RESET), sep='', end=' ', flush=True) + for j in range(len(mList[i])): + if str(mList[i][j]) == WATER: + print(str(IC_WATER + " " + str(mList[i][j]) + RESET), sep='', end=' ', flush=True) + elif str(mList[i][j]) == RIVER[0]: + print(str(IC_RIVER + " " + str(mList[i][j]) + RESET), sep='', end=' ', flush=True) + elif str(mList[i][j]) == RIVER[1]: + print(str(IC_RIVER + " " + str(mList[i][j]) + RESET), sep='', end=' ', flush=True) + elif str(mList[i][j]) == RIVER[2]: + print(str(IC_RIVER + " " + str(mList[i][j]) + RESET), sep='', end=' ', flush=True) + elif str(mList[i][j]) == PLAINS: + print(str(IC_PLAINS + " " + str(mList[i][j]) + RESET), sep='', end=' ', flush=True) + elif str(mList[i][j]) == FOREST: + print(str(IC_FOREST + " " + str(mList[i][j]) + RESET), sep='', end=' ', flush=True) + elif str(mList[i][j]) == MOUNTAIN: + print(str(IC_MOUNTAIN + " " + str(mList[i][j]) + RESET), sep='', end=' ', flush=True) + elif str(mList[i][j]) == FIEF: + print(str(IC_FIEF + " " + str(mList[i][j]) + RESET), sep='', end=' ', flush=True) + elif str(mList[i][j]) == STRONGHOLD: + print(str(IC_STRONGHOLD + " " + str(mList[i][j]) + RESET), sep='', end=' ', flush=True) + elif str(mList[i][j]) == LOCATION: + print(str(BLUE_GRAY + " " + str(mList[i][j]) + RESET), sep='', end=' ', flush=True) + else: + print(str(NAVY + " " + str("*" + RESET)), sep='', end=' ', flush=True) + print(borderColor + " " + borderSymb + RESET) + print(str(borderColor + " " + str("(" + RESET + str(x) + ", " + str(y) + borderColor + ")").center(34, borderSymb) + RESET)) + +#-------------------------------------------------------------------------------------------------------------- +# [GenerateMiniMap] +# parameters: mapClass, yPos, xPos +# Creates and prints out a minimap +#-------------------------------------------------------------------------------------------------------------- +def GenerateMiniMap(mapClass, yPos, xPos): + mList = FarScanSurroundings(mapClass, yPos, xPos) + PrintMiniMap(mList, yPos, xPos) + + + +#-------------------------------------------------------------------------------------------------------------- +# [PrintWorldMapWithLocation] +# Parameters: wMap, userName, yPos, xPos +# Iterates through a WorldMap and prints a color version. Also prints fiefs along side +#-------------------------------------------------------------------------------------------------------------- +def PrintWorldMapWithLocation(wMap, userName, yPos, xPos): + for i in range(MAP_HEIGHT): + fiefsInRow = GetFiefRow(i, userName) + strongholdsInRow = GetStrongholdRow(i, userName) + for j in range(MAP_WIDTH): + symbol = wMap[i][j] + if j == 0: + if j == int(xPos) and i == int(yPos): + print(' ' + IC_LOCATION + LOCATION + RESET, end=" ") + elif symbol == UNEXPLORED: + print(' ' + IC_UNEXPLORED + symbol + RESET, end=" ") + elif symbol == EMPTY: + print(' ' + symbol, end=" ") + elif symbol == WATER: + print(' ' + IC_WATER + symbol + RESET, end=" ") + elif symbol == RIVER[0] or symbol == RIVER[1] or symbol == RIVER[2]: + print(' ' + IC_RIVER + symbol + RESET, end=" ") + elif symbol == FOREST: + print(' ' + IC_FOREST + symbol + RESET, end=" ") + elif symbol == PLAINS: + print(' ' + IC_PLAINS + symbol + RESET, end=" ") + elif symbol == MOUNTAIN: + print(' ' + IC_MOUNTAIN + symbol + RESET, end=" ") + elif symbol == FIEF: + print(' ' + GetFiefByOwner(i, j, userName) + RESET, end=" ") + elif symbol == STRONGHOLD: + print(' ' + IC_STRONGHOLD + symbol + RESET, end=" ") + elif symbol == LOCATION: + print(' ' + IC_LOCATION + symbol + RESET, end=" ") + elif j == MAP_WIDTH - 1: + if j == int(xPos) and i == int(yPos): + print(IC_LOCATION + LOCATION + RESET, *fiefsInRow, *strongholdsInRow, end=" ") + elif symbol == UNEXPLORED: + print(IC_UNEXPLORED + symbol + RESET, *fiefsInRow, *strongholdsInRow, end=" ") + elif symbol == EMPTY: + print(symbol, *fiefsInRow, *strongholdsInRow, end=" ") + elif symbol == WATER: + print(IC_WATER + symbol + RESET, *fiefsInRow, *strongholdsInRow, end=" ") + elif symbol == RIVER[0] or symbol == RIVER[1] or symbol == RIVER[2]: + print(IC_RIVER + symbol + RESET, *fiefsInRow, *strongholdsInRow, end=" ") + elif symbol == FOREST: + print(IC_FOREST + symbol + RESET, *fiefsInRow, *strongholdsInRow, end=" ") + elif symbol == PLAINS: + print(IC_PLAINS + symbol + RESET, *fiefsInRow, *strongholdsInRow, end=" ") + elif symbol == MOUNTAIN: + print(IC_MOUNTAIN + symbol + RESET, *fiefsInRow, *strongholdsInRow, end=" ") + elif symbol == FIEF: + print(GetFiefByOwner(i, j, userName) + RESET, *fiefsInRow, *strongholdsInRow, end=" ") + elif symbol == STRONGHOLD: + print(IC_STRONGHOLD + symbol + RESET, *fiefsInRow, *strongholdsInRow, end=" ") + elif symbol == LOCATION: + print(IC_LOCATION + symbol + RESET, *fiefsInRow, *strongholdsInRow, end=" ") + else: + if j == int(xPos) and i == int(yPos): + print(IC_LOCATION + LOCATION + RESET, end=" ") + elif symbol == UNEXPLORED: + print(IC_UNEXPLORED + symbol + RESET, end=" ") + elif symbol == EMPTY: + print(symbol, end=" ") + elif symbol == WATER: + print(IC_WATER + symbol + RESET, end=" ") + elif symbol == RIVER[0] or symbol == RIVER[1] or symbol == RIVER[2]: + print(IC_RIVER + symbol + RESET, end=" ") + elif symbol == FOREST: + print(IC_FOREST + symbol + RESET, end=" ") + elif symbol == PLAINS: + print(IC_PLAINS + symbol + RESET, end=" ") + elif symbol == MOUNTAIN: + print(IC_MOUNTAIN + symbol + RESET, end=" ") + elif symbol == FIEF: + print(GetFiefByOwner(i, j, userName) + RESET, end=" ") + elif symbol == STRONGHOLD: + print(IC_STRONGHOLD + symbol + RESET, end=" ") + elif symbol == LOCATION: + print(IC_LOCATION + symbol + RESET, end=" ") + print('') + +#-------------------------------------------------------------------------------------------------------------- +# [GetFiefByCoordinates] +# Parameters: yPos, xPos +# Returns: fief class at coordinates +#-------------------------------------------------------------------------------------------------------------- +def GetFiefByCoordinates(yPos, xPos): + for filename in os.listdir('fiefs'): + with open(os.path.join('fiefs', filename), 'r') as f: + tempName = filename[:-4] + tempName = Fiefdom() + tempName.name = filename[:-4] + tempName.read() + if int(tempName.yCoordinate) == yPos and int(tempName.xCoordinate) == xPos: + return tempName +#-------------------------------------------------------------------------------------------------------------- +# [GetStrongholdByCoordinates] +# Parameters: yPos, xPos +# Returns: fief class at coordinates +#-------------------------------------------------------------------------------------------------------------- +def GetStrongholdByCoordinates(yPos, xPos): + for filename in os.listdir('strongholds'): + with open(os.path.join('strongholds', filename), 'r') as f: + tempName = filename[:-4] + tempName = Stronghold() + tempName.name = filename[:-4] + tempName.read() + if int(tempName.yCoordinate) == yPos and int(tempName.xCoordinate) == xPos: + print(" Found " + str(tempName.name) + "'s Stronghold!") + nothing = input(" continue...") + return tempName + +#-------------------------------------------------------------------------------------------------------------- +# [GetLocation] +# Parameters: mapClass, yPos, xPos +# +# Looks at current location and determines if there is something there. Returns the name of that thing if +# something is found. Otherwise returns "". +#-------------------------------------------------------------------------------------------------------------- +def GetLocation(mapClass, yPos, xPos): + if str(mapClass.worldMap[int(yPos)][int(xPos)]) == FIEF: + tempFief = Fiefdom() + tempFief = GetFiefByCoordinates(yPos, xPos) + if isinstance(tempFief, Fiefdom): + return str(BiomeColor(tempFief.biome) + str(tempFief.name) + RESET) + else: + return "" + + elif str(mapClass.worldMap[int(yPos)][int(xPos)]) == STRONGHOLD: + tempStronghold = Stronghold() + tempStronghold = GetStrongholdByCoordinates(yPos, xPos) + if isinstance(tempStronghold, Stronghold): + return str((tempStronghold.color) + str(tempStronghold.name) + "'s Stronghold" + RESET) + else: + return "" + + else: + return "" + #eof \ No newline at end of file From 15fcbfa67c418a89103fa403e3a6fc2c4c967b7a Mon Sep 17 00:00:00 2001 From: Steelwing723 Date: Mon, 24 Jan 2022 17:24:37 -0600 Subject: [PATCH 4/9] Updated Several Things --- armies.py | 5 +++-- art.py | 4 ++-- menu_battalions.py | 2 -- menu_garrison.py | 4 ++-- worldmap.py | 8 +++----- 5 files changed, 10 insertions(+), 13 deletions(-) diff --git a/armies.py b/armies.py index 9d04072..c82cfb6 100644 --- a/armies.py +++ b/armies.py @@ -169,7 +169,7 @@ def read(self): self.AddBattalion(str(rL[i][0]), str(rL[i][1]), str(rL[i][2]), str(rL[i][3]), str(rL[i][4]), str(rL[i][5]), str(rL[i][6]), str(rL[i][7]), str(rL[i][8]), str(rL[i][9]), str(rL[i][10]), str(rL[i][11]), str(rL[i][12]), str(rL[i][13])) except: - print('Could not read armies file!') + # print('Could not read armies file!') pass class Battalion: @@ -247,7 +247,8 @@ def MenuBarWithLocation(self, userStronghold, location): # rations = str(" | Rations: " + C_FOOD + str(self.rations) + RESET) # xPos = str(" | X: " + RED_GRAY + str(self.xPos) + RESET) # yPos = str(" | Y: " + RED_GRAY + str(self.yPos) + RESET) - loc = str(" | Location: " + RED_GRAY + location) + # loc = str(" | Location: " + RED_GRAY + location) + loc = str(" | " + location) return str(name + numTroops + attLevel + speed + stamina + loc) diff --git a/art.py b/art.py index d635628..1341455 100644 --- a/art.py +++ b/art.py @@ -161,7 +161,7 @@ def headerBattalion(bat, userStronghold, serverMap): spacer = 196 else: menu = str(bat.MenuBarWithLocation(userStronghold, location)) - spacer = 186 + spacer = 189 R = textColor.RESET C = userStronghold.color inventory = bat.Inventory() @@ -171,7 +171,7 @@ def headerBattalion(bat, userStronghold, serverMap): ' |_|| || |(_||||(/_(_| | | (/_ | (_|(_)||| \_|(_||||(/_ \n' + ' ' + '\n' + (menu.center(spacer, '-')) + '\n' + - (inventory.center(170, '-')) + '\n') + (inventory.center(174, '-')) + '\n') #Define Art: #==================================================================================================================== diff --git a/menu_battalions.py b/menu_battalions.py index bb2746f..cc5557d 100644 --- a/menu_battalions.py +++ b/menu_battalions.py @@ -52,8 +52,6 @@ def BattalionMenu(screen, userStronghold, STRONGHOLD, USER_STRONGHOLD): headerBattalion(currentBattalion, userStronghold, serverMap) GenerateMiniMap(serverMap, currentBattalion.yPos, currentBattalion.xPos) - print() - print("\n Avalible Commands:") print(' ------------------------------------------------------') print(' {1}: Go Back') diff --git a/menu_garrison.py b/menu_garrison.py index edffff8..5408ddf 100644 --- a/menu_garrison.py +++ b/menu_garrison.py @@ -15,7 +15,7 @@ def GarrisonMenu(screen, userStronghold): userFiefCount = 0 - print(str("\n " + textColor.UNDERLINE + "Nearby Fiefdoms" + textColor.RESET).ljust(RESOURCE_SPACING, FILL_SYMBOL) + "| " + textColor.UNDERLINE + "Resources" + textColor.RESET + "\n") + print(str("\n " + textColor.UNDERLINE + "Your Fiefdoms" + textColor.RESET).ljust(RESOURCE_SPACING, FILL_SYMBOL) + "| " + textColor.UNDERLINE + "Resources" + textColor.RESET + "\n") for filename in os.listdir('fiefs'): with open(os.path.join('fiefs', filename), 'r') as f: @@ -32,7 +32,7 @@ def GarrisonMenu(screen, userStronghold): userFiefCount = userFiefCount + 1 print(ownedFiefdomInfo.ljust(RESOURCE_SPACING, FILL_SYMBOL) + fiefdomResources) - print('\n') + print('') print(" Avalible Commands:") print(' ------------------------------------------------------') print(' {1}: Return to Stronghold') diff --git a/worldmap.py b/worldmap.py index e7fd5e6..eea74c5 100644 --- a/worldmap.py +++ b/worldmap.py @@ -2843,7 +2843,7 @@ def GetFiefByCoordinates(yPos, xPos): tempName = Fiefdom() tempName.name = filename[:-4] tempName.read() - if int(tempName.yCoordinate) == yPos and int(tempName.xCoordinate) == xPos: + if int(tempName.yCoordinate) == int(yPos) and int(tempName.xCoordinate) == int(xPos): return tempName #-------------------------------------------------------------------------------------------------------------- # [GetStrongholdByCoordinates] @@ -2857,9 +2857,7 @@ def GetStrongholdByCoordinates(yPos, xPos): tempName = Stronghold() tempName.name = filename[:-4] tempName.read() - if int(tempName.yCoordinate) == yPos and int(tempName.xCoordinate) == xPos: - print(" Found " + str(tempName.name) + "'s Stronghold!") - nothing = input(" continue...") + if int(tempName.yCoordinate) == int(yPos) and int(tempName.xCoordinate) == int(xPos): return tempName #-------------------------------------------------------------------------------------------------------------- @@ -2882,7 +2880,7 @@ def GetLocation(mapClass, yPos, xPos): tempStronghold = Stronghold() tempStronghold = GetStrongholdByCoordinates(yPos, xPos) if isinstance(tempStronghold, Stronghold): - return str((tempStronghold.color) + str(tempStronghold.name) + "'s Stronghold" + RESET) + return str(StrongholdColor(tempStronghold.color) + str(tempStronghold.name) + "'s Stronghold" + RESET) else: return "" From e603fe8e95df039c60f07cfb254228c63af9ec7b Mon Sep 17 00:00:00 2001 From: Steelwing723 Date: Mon, 24 Jan 2022 17:41:17 -0600 Subject: [PATCH 5/9] Disband --- armies.py | 6 ++++-- globals.py | 10 +++++++--- menu_battalions.py | 8 ++++++++ 3 files changed, 19 insertions(+), 5 deletions(-) diff --git a/armies.py b/armies.py index c82cfb6..dd28a7f 100644 --- a/armies.py +++ b/armies.py @@ -117,8 +117,10 @@ def GetBattalion(self, index): # parameters: self, index # Removes Battalion at index from the battalions list. #================================================================================== - def RemoveBattalion(self, index): - self.battalions.pop(index) + def RemoveBattalion(self, bat): + for i in range(len(self.battalions)): + if bat == self.battalions[i]: + self.battalions.pop(i) self.write() #================================================================================== diff --git a/globals.py b/globals.py index dae3f6f..e4ebe98 100644 --- a/globals.py +++ b/globals.py @@ -2340,19 +2340,23 @@ def CreateNewBattalion(station): return "battalions" if serverArmies.ExistingName(name): print("\n Battalion name already taken!") - nothing = input(" Press enter to continue") + nothing = input(" Press enter to continue : ") return "battalions" print("") numTroops = GetAnswer(str(" How many troops will you assign to " + WARNING + str(name) + RESET + "? [min " + str(BATTALION_MIN) + "]: "), ">", BATTALION_MIN, BATTALION_MAX) if int(numTroops) > int(station.defenders): print(" You don't have enough troops for this battalion!\n") - nothing = input(" Press enter to continue") + nothing = input(" Press enter to continue : ") return "battalions" print("") serverArmies.AddBattalion(str(name), str(commander), str(numTroops), str(attLevel), str(speed), str(stamina), str(rations), str(xPos), str(yPos), 0, 0, 0, 0, 0) serverArmies.write() - nothing = input(" Press enter to continue") + + station.defenders = int(station.defenders) - int(numTroops) + station.write() + + nothing = input(" Press enter to continue : ") return "battalions" else: diff --git a/menu_battalions.py b/menu_battalions.py index cc5557d..c99bbb8 100644 --- a/menu_battalions.py +++ b/menu_battalions.py @@ -55,12 +55,20 @@ def BattalionMenu(screen, userStronghold, STRONGHOLD, USER_STRONGHOLD): print("\n Avalible Commands:") print(' ------------------------------------------------------') print(' {1}: Go Back') + if location != "": + print(' {4}: Disband (' + LIME + 'Units are added to this location' + RESET + ')') print(' ------------------------------------------------------') print('') command = input(" Enter your command: ") if str(command) == '1': return "battalions" + elif str(command) == '4': + userStronghold.defenders = int(userStronghold.defenders) + int(currentBattalion.numTroops) + serverArmies.RemoveBattalion(currentBattalion) + userStronghold.write() + userStronghold.read() + return "battalions" else: return "battalions" From bdf277662f47a8044ccf817f4eae808c7bac4dcf Mon Sep 17 00:00:00 2001 From: Steelwing723 Date: Mon, 24 Jan 2022 20:08:06 -0600 Subject: [PATCH 6/9] Header Update --- art.py | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/art.py b/art.py index 1341455..f7a347a 100644 --- a/art.py +++ b/art.py @@ -26,7 +26,7 @@ def header(username): R = textColor.RESET Y = textColor.YELLOW D = textColor.DARK_RED - M = textColor.DARK_MAGENTA + M = StrongholdColor(headerStronghold.color) G = textColor.DARK_GREEN E = textColor.DARK_GRAY @@ -52,7 +52,7 @@ def headerHomeStronghold(username): R = textColor.RESET Y = textColor.YELLOW D = textColor.DARK_RED - M = textColor.DARK_MAGENTA + M = StrongholdColor(headerStronghold.color) G = textColor.DARK_GREEN E = textColor.DARK_GRAY @@ -82,7 +82,7 @@ def headerWithSoldiers(username): R = textColor.RESET Y = textColor.YELLOW D = textColor.DARK_RED - M = textColor.DARK_MAGENTA + M = StrongholdColor(headerStronghold.color) G = textColor.DARK_GREEN E = textColor.DARK_GRAY @@ -135,13 +135,16 @@ def headerSuperStripped(): #This is an alternate header for displaying fief totals instead of stronghold totals. #Need to update other header at some point to show totals, perhaps? def headerFief(fief): + headerStronghold = Stronghold() + headerStronghold.name = fief.ruler + headerStronghold.read() R = textColor.RESET Y = textColor.YELLOW D = textColor.DARK_RED - M = textColor.DARK_MAGENTA + M = StrongholdColor(headerStronghold.color) G = textColor.DARK_GREEN E = textColor.DARK_GRAY - C = biomeColor(fief.biome) + C = BiomeColor(fief.biome) line5 = str(" :: " + C + str(fief.name) + R + " :: | Ruler: " + M + str(fief.ruler) + R + " Gold: " + Y + str(fief.gold) + R + " Food: " + D + str(fief.food) + R + " Wood: " + G + str(fief.wood) + R + " Stone: " + E + str(fief.stone) + R + " Ore: " + M + str(fief.ore) + R + " | ") From d7cf13c071809a57694685d0846d2e231fcef9c3 Mon Sep 17 00:00:00 2001 From: Steelwing723 Date: Wed, 26 Jan 2022 15:59:45 -0600 Subject: [PATCH 7/9] Battalion Menu Stuff --- armies.py | 53 +++++++- art.py | 46 +------ colors.py | 62 +++++++++- globals.py | 77 +++++++++++- menu_battalions.py | 154 ++++++++++++++++++++++- passages.py | 5 + worldmap.py | 301 +++++++++++++++++++++++++++++++++++++++++---- 7 files changed, 630 insertions(+), 68 deletions(-) diff --git a/armies.py b/armies.py index dd28a7f..48b6fe3 100644 --- a/armies.py +++ b/armies.py @@ -93,6 +93,27 @@ def GetBattalions(self): batts.append(self.battalions[i].ListDetails()) return batts + #================================================================================== + # [GetBattalionData] + # parameters: self + # Gets a list of battalion coordinates + #================================================================================== + def GetBattalionData(self): + coords = [] + for i in range(len(self.battalions)): + coords.append((self.battalions[i].yPos, self.battalions[i].xPos, self.battalions[i].commander, self.battalions[i].name)) + return coords + + #================================================================================== + # [GetCommanderByLocation] + # parameters: self + # Gets a list of battalions + #================================================================================== + def GetCommanderByLocation(self, y, x): + for i in range(len(self.battalions)): + if int(self.battalions[i].yPos) == int(y) and int(self.battalions[i].xPos) == int(x): + return self.battalions[i].commander + #================================================================================== # [GetBattalionObjects] # parameters: self @@ -123,6 +144,37 @@ def RemoveBattalion(self, bat): self.battalions.pop(i) self.write() + #================================================================================== + # [RemoveBattalion] + # parameters: self, index + # Removes Battalion at index from the battalions list. + #================================================================================== + def SetBattalionCoords(self, bat, direction): + for i in range(len(self.battalions)): + if bat == self.battalions[i]: + if direction == 'n': + self.battalions[i].yPos = str(int(self.battalions[i].yPos) + 1) + elif direction == 'ne': + self.battalions[i].yPos = str(int(self.battalions[i].yPos) + 1) + self.battalions[i].xPos = str(int(self.battalions[i].xPos) + 1) + elif direction == 'e': + self.battalions[i].xPos = str(int(self.battalions[i].xPos) + 1) + elif direction == 'se': + self.battalions[i].yPos = str(int(self.battalions[i].yPos) - 1) + self.battalions[i].xPos = str(int(self.battalions[i].xPos) + 1) + elif direction == 's': + self.battalions[i].yPos = str(int(self.battalions[i].yPos) - 1) + elif direction == 'sw': + self.battalions[i].yPos = str(int(self.battalions[i].yPos) - 1) + self.battalions[i].xPos = str(int(self.battalions[i].xPos) - 1) + elif direction == 'w': + self.battalions[i].xPos = str(int(self.battalions[i].xPos) - 1) + elif direction == 'nw': + self.battalions[i].yPos = str(int(self.battalions[i].yPos) + 1) + self.battalions[i].xPos = str(int(self.battalions[i].xPos) - 1) + + self.write() + #================================================================================== # [write] #================================================================================== @@ -275,4 +327,3 @@ def PrintOre(self): return str(C_ORE + str(self.invOre) + RESET) - diff --git a/art.py b/art.py index f7a347a..59e81a5 100644 --- a/art.py +++ b/art.py @@ -24,15 +24,11 @@ def header(username): headerStronghold.name = username headerStronghold.read() R = textColor.RESET - Y = textColor.YELLOW - D = textColor.DARK_RED M = StrongholdColor(headerStronghold.color) - G = textColor.DARK_GREEN - E = textColor.DARK_GRAY # line5 = str(" Player: " + str(headerStronghold.name) + " Gold: " + str(headerStronghold.gold) + " Warriors: " + str(headerStronghold.defenders) + " Thieves: " + str(headerStronghold.thieves) + ' ') - line5 = str(" Player: " + M + str(headerStronghold.name) + R + " Gold: " + Y + str(headerStronghold.gold) + R + " Warriors: " + COLOR_WARRIOR + str(headerStronghold.defenders) + RESET + " Thieves: " + COLOR_THIEF + str(headerStronghold.thieves) + RESET + ' ') - line6 = str(" Food: " + D + str(headerStronghold.food) + R + " Wood: " + G + str(headerStronghold.wood) + R + " Stone: " + E + str(headerStronghold.stone) + R + " Ore: " + M + str(headerStronghold.ore) + R + " ") + line5 = str(" Player: " + M + str(headerStronghold.name) + R + " Gold: " + C_GOLD + str(headerStronghold.gold) + R + " Warriors: " + COLOR_WARRIOR + str(headerStronghold.defenders) + R + " Thieves: " + COLOR_THIEF + str(headerStronghold.thieves) + R + ' ') + line6 = str(" Food: " + C_FOOD + str(headerStronghold.food) + R + " Wood: " + C_WOOD + str(headerStronghold.wood) + R + " Stone: " + C_STONE + str(headerStronghold.stone) + R + " Ore: " + C_ORE + str(headerStronghold.ore) + R + " ") print('\n' + ' __ _ __ \n' + @@ -50,15 +46,11 @@ def headerHomeStronghold(username): headerStronghold.name = username headerStronghold.read() R = textColor.RESET - Y = textColor.YELLOW - D = textColor.DARK_RED M = StrongholdColor(headerStronghold.color) - G = textColor.DARK_GREEN - E = textColor.DARK_GRAY # line5 = str(" Player: " + str(headerStronghold.name) + " Gold: " + str(headerStronghold.gold) + " Warriors: " + str(headerStronghold.defenders) + " Thieves: " + str(headerStronghold.thieves) + ' ') - line5 = str(" Player: " + M + str(headerStronghold.name) + R + " Gold: " + Y + str(headerStronghold.gold) + R + " Warriors: " + COLOR_WARRIOR + str(headerStronghold.defenders) + RESET + " Thieves: " + COLOR_THIEF + str(headerStronghold.thieves) + RESET + ' ') - line6 = str(" Food: " + D + str(headerStronghold.food) + R + " Wood: " + G + str(headerStronghold.wood) + R + " Stone: " + E + str(headerStronghold.stone) + R + " Ore: " + M + str(headerStronghold.ore) + R + " ") + line5 = str(" Player: " + M + str(headerStronghold.name) + R + " Gold: " + C_GOLD + str(headerStronghold.gold) + R + " Warriors: " + COLOR_WARRIOR + str(headerStronghold.defenders) + R + " Thieves: " + COLOR_THIEF + str(headerStronghold.thieves) + R + ' ') + line6 = str(" Food: " + C_FOOD + str(headerStronghold.food) + R + " Wood: " + C_WOOD + str(headerStronghold.wood) + R + " Stone: " + C_STONE + str(headerStronghold.stone) + R + " Ore: " + C_ORE + str(headerStronghold.ore) + R + " ") print('\n' + ' __ _ __ \n' + @@ -80,13 +72,9 @@ def headerWithSoldiers(username): headerStronghold.name = username headerStronghold.read() R = textColor.RESET - Y = textColor.YELLOW - D = textColor.DARK_RED M = StrongholdColor(headerStronghold.color) - G = textColor.DARK_GREEN - E = textColor.DARK_GRAY - line5 = str(" Player: " + M + str(headerStronghold.name) + R + " Gold: " + Y + str(headerStronghold.gold) + R + " Warriors: " + D + str(headerStronghold.defenders) + G + "Thieves: " + str(headerStronghold.thieves) + ' ') + line5 = str(" Player: " + M + str(headerStronghold.name) + R + " Gold: " + C_GOLD + str(headerStronghold.gold) + R + " Warriors: " + COLOR_WARRIOR + str(headerStronghold.defenders) + R + "Thieves: " + COLOR_THIEF + str(headerStronghold.thieves) + R + ' ') print('\n' + ' __ _ __ \n' + @@ -100,14 +88,6 @@ def headerWithSoldiers(username): #headerStripped() should be called when you don't need to display a full resource list def headerStripped(): - - R = textColor.RESET - Y = textColor.YELLOW - D = textColor.DARK_RED - M = textColor.DARK_MAGENTA - G = textColor.DARK_GREEN - E = textColor.DARK_GRAY - print('\n' + ' __ _ __ \n' + ' | |__ __ _ __ _ _| |_ o _ _|_ _| _ __ /__ _ __ _ \n' + @@ -118,14 +98,6 @@ def headerStripped(): #headerSuperStripped() should be called when you don't need to display a full resource list def headerSuperStripped(): - - R = textColor.RESET - Y = textColor.YELLOW - D = textColor.DARK_RED - M = textColor.DARK_MAGENTA - G = textColor.DARK_GREEN - E = textColor.DARK_GRAY - print('\n' + ' __ _ __ \n' + ' | |__ __ _ __ _ _| |_ o _ _|_ _| _ __ /__ _ __ _ \n' + @@ -139,14 +111,10 @@ def headerFief(fief): headerStronghold.name = fief.ruler headerStronghold.read() R = textColor.RESET - Y = textColor.YELLOW - D = textColor.DARK_RED M = StrongholdColor(headerStronghold.color) - G = textColor.DARK_GREEN - E = textColor.DARK_GRAY C = BiomeColor(fief.biome) - line5 = str(" :: " + C + str(fief.name) + R + " :: | Ruler: " + M + str(fief.ruler) + R + " Gold: " + Y + str(fief.gold) + R + " Food: " + D + str(fief.food) + R + " Wood: " + G + str(fief.wood) + R + " Stone: " + E + str(fief.stone) + R + " Ore: " + M + str(fief.ore) + R + " | ") + line5 = str(" :: " + C + str(fief.name) + R + " :: | Ruler: " + M + str(fief.ruler) + R + " Gold: " + C_GOLD + str(fief.gold) + R + " Food: " + C_FOOD + str(fief.food) + R + " Wood: " + C_WOOD + str(fief.wood) + R + " Stone: " + C_STONE + str(fief.stone) + R + " Ore: " + C_ORE + str(fief.ore) + R + " | ") print('\n' + ' __ _ __ \n' + @@ -165,8 +133,6 @@ def headerBattalion(bat, userStronghold, serverMap): else: menu = str(bat.MenuBarWithLocation(userStronghold, location)) spacer = 189 - R = textColor.RESET - C = userStronghold.color inventory = bat.Inventory() print('\n' + ' __ _ __ \n' + diff --git a/colors.py b/colors.py index eec6e0f..cc55398 100644 --- a/colors.py +++ b/colors.py @@ -36,6 +36,8 @@ class textColor: #More, lazier color definitions. #Some of the original colors were changed in this last update. #I've commented them out instead of removing them entirely -SW +BLACK = '\033[30m' +WHITE = '\u001b[37;1m' RED = '\033[91m' ORANGE = "\u001b[38;5;208m" PINK = "\033[38;5;213m" @@ -77,6 +79,27 @@ class textColor: INTENSE_PURPLE = "\033[0;95m" CYAN_BACKGROUND = "\033[0;106m" +#===================== +# BG Colors +#===================== +BLACK_BG = "\u001b[40m" +RED_BG = '\033[48;5;1m' +GREEN_BG = '\033[48;5;35m' +MAGENTA_BG = "\033[48;5;5m" +BLUE_BG = "\033[48;5;27m" +YELLOW_BG = '\033[48;5;3m' +CYAN_BG = "\033[48;5;6m" +DARK_GRAY_BG = '\033[48;5;240m' +PURPLE_BG = "\033[48;5;57m" +ORANGE_BG = "\u001b[48;5;208m" +TEAL_BG = "\033[48;5;30m" +PINK_BG = "\033[48;5;213m" +BROWN_BG = "\u001b[48;5;94m" +MINT_BG = "\033[48;5;157m" +SALMON_BG = "\033[48;5;203m" +LAVENDER_BG = "\033[48;5;140m" +WHITE_BG = "\033[48;5;15m" + #===================== # Stronghold Colors #===================== @@ -153,7 +176,44 @@ def StrongholdColor(color): if color == 'lavender': return LAVENDER - +#=====================#=====================#===================== +# [BattalionIconColor] +# parameter: color +# returns: a color code combo based on the passed color variable +#=====================#=====================#===================== +def BattalionIconColor(color): + if color == 'red': + return RED_BG + WHITE + if color == 'green': + return GREEN_BG + BLACK + if color == 'magenta': + return MAGENTA_BG + WHITE + if color == 'white': + return WHITE_BG + BLACK + if color == 'blue': + return BLUE_BG + WHITE + if color == 'yellow': + return YELLOW_BG + BLACK + if color == 'cyan': + return CYAN_BG + BLACK + if color == 'gray': + return DARK_GRAY_BG + WHITE + if color == 'purple': + return PURPLE_BG + WHITE + if color == 'orange': + return ORANGE_BG + BLACK + if color == 'teal': + return TEAL_BG + WHITE + if color == 'pink': + return PINK_BG + BLACK + if color == 'brown': + return BROWN_BG + WHITE + if color == 'mint': + return MINT_BG + BLACK + if color == 'salmon': + return SALMON_BG + WHITE + if color == 'lavender': + return LAVENDER_BG + BLACK #define biome globals: WATER = '~' diff --git a/globals.py b/globals.py index e4ebe98..d19a9ac 100644 --- a/globals.py +++ b/globals.py @@ -221,6 +221,14 @@ #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ #======================================================================================================== +#======================================================================================================== +# Wait +# parameter: username +# returns: True/False +# Prevents the use of certain usernames that may interfere with menu operations. +#======================================================================================================== +def Wait(): + wait = input("\n Press Enter to continue : ") #======================================================================================================== # FirstLaunch @@ -2366,6 +2374,73 @@ def CreateNewBattalion(station): print("\n You don't have enough warriors at this location to make a battalion!\n") nothing = input(" Press enter to continue : ") return "battalions" - + return "battalions" + +#================================================================================== +# [CheckBiome] +# parameter: surroundings, direction, haveRaft +#================================================================================== +def CheckBiome(biome, direction, haveRaft): + #If the way is blocked by water: + # if biome == WATER: + # print(" A body of " + IC_WATER + "water" + RESET + " blocks your path to the " + direction) + # return "" + # if biome == RIVER[0]: + # print(" A Southwest-bound " + IC_RIVER + "river" + RESET + " blocks your path to the " + direction) + # return "" + # if biome == RIVER[1]: + # print(" A South-bound " + IC_RIVER + "river" + RESET + " blocks your path to the " + direction) + # return "" + # if biome == RIVER[2]: + # print(" A Southeast-bound " + IC_RIVER + "river" + RESET + " blocks your path to the " + direction) + # return "" + + #For testing purposes, add a "raft" attribute: + if biome == WATER: + print(" You raft through the " + IC_WATER + "water" + RESET + " to the " + direction) + return "" + if biome == RIVER[0]: + print(" You raft over the Southwest-bound " + IC_RIVER + "river" + RESET + " to the " + direction) + return "" + if biome == RIVER[1]: + print(" You raft over the South-bound " + IC_RIVER + "river" + RESET + " to the " + direction) + return "" + if biome == RIVER[2]: + print(" You raft over the Southeast-bound " + IC_RIVER + "river" + RESET + " to the " + direction) + return "" + if biome == MOUNTAIN: + print(" You travel over the " + IC_MOUNTAIN + "mountain" + RESET + " to the " + direction) + return "" + if biome == FOREST: + print(" You travel through the " + IC_FOREST + "forest" + RESET + " to the " + direction) + return "" + if biome == PLAINS: + print(" You travel through the " + IC_PLAINS + "plains" + RESET + " to the " + direction) + return "" + if biome == FIEF: + print(" You travel to the " + IC_FIEF + "fief" + RESET + " to the " + direction) + if biome == STRONGHOLD: + print(" You travel to the " + IC_STRONGHOLD + "stronghold" + RESET + " to the " + direction) + return "" + +#================================================================================== +# [MoveBattalion] +# parameter: station, battalion +# Moves the battalion based on direction +#================================================================================== +def MoveBattalion(station, battalion, direction): + os.system("clear") + headerBattalion(battalion, station, serverMap) + raft = True #Change this later + surroundings = ScanSurroundings(serverMap.worldMap, battalion.xPos, battalion.yPos) + #[dN, dNE, dE, dSE, dS, dSW, dW, dNW] + if direction == 'n': + LoadingAnimation(surroundings[0]) + check = CheckBiome(surroundings[0], direction, raft) + + + serverArmies.SetBattalionCoords(battalion, direction) + + diff --git a/menu_battalions.py b/menu_battalions.py index c99bbb8..82acd1c 100644 --- a/menu_battalions.py +++ b/menu_battalions.py @@ -1,8 +1,13 @@ from globals import * from armies import * +BatMenu = False + +# Not set up to handle Fiefs just yet! def BattalionMenu(screen, userStronghold, STRONGHOLD, USER_STRONGHOLD): currentBattalion = 0 + xPos = 0 + yPos = 0 if screen == "battalions": os.system("clear") header(userStronghold.name) @@ -29,7 +34,9 @@ def BattalionMenu(screen, userStronghold, STRONGHOLD, USER_STRONGHOLD): print("\n Avalible Commands:") print(' ------------------------------------------------------') print(' {R}: Return to Stronghold') - print(' {C}: Create Battalion') + if int(userStronghold.defenders) >= 100: + print(' {C}: Create Battalion') + print(' {V}: View World Map') print(' ' + CYAN + '{Enter a number above to view that battalion}: ' + RESET) print(' ------------------------------------------------------') print('') @@ -37,10 +44,17 @@ def BattalionMenu(screen, userStronghold, STRONGHOLD, USER_STRONGHOLD): command = str(command.lower()) + if int(userStronghold.defenders) >= 100: + if str(command) == 'c': + return CreateNewBattalion(userStronghold) + if str(command) == 'r': return "stronghold" - elif str(command) == 'c': - return CreateNewBattalion(userStronghold) + if str(command) == 'v': + BatMenu = False + xPos = int(userStronghold.xCoordinate) + yPos = int(userStronghold.yCoordinate) + screen = "battalionMap" elif IsPositiveIntEqualOrLessThan(command, count): currentBattalion = yourBattalions[int(command) - 1] screen = "commandBattalion" @@ -55,16 +69,30 @@ def BattalionMenu(screen, userStronghold, STRONGHOLD, USER_STRONGHOLD): print("\n Avalible Commands:") print(' ------------------------------------------------------') print(' {1}: Go Back') + print(' {2}: Move Out') + print(' {3}: View World Map') if location != "": - print(' {4}: Disband (' + LIME + 'Units are added to this location' + RESET + ')') + print(' {4}: Disband (' + LIME + 'Units and Inventory are added to this location' + RESET + ')') print(' ------------------------------------------------------') print('') command = input(" Enter your command: ") if str(command) == '1': return "battalions" + elif str(command) == '2': + screen = "battalionNavigation" + elif str(command) == '3': + BatMenu = True + xPos = int(currentBattalion.xPos) + yPos = int(currentBattalion.yPos) + screen = "battalionMap" elif str(command) == '4': userStronghold.defenders = int(userStronghold.defenders) + int(currentBattalion.numTroops) + userStronghold.gold = int(userStronghold.gold) + int(currentBattalion.invGold) + userStronghold.food = int(userStronghold.food) + int(currentBattalion.invFood) + userStronghold.wood = int(userStronghold.wood) + int(currentBattalion.invWood) + userStronghold.stone = int(userStronghold.stone) + int(currentBattalion.invStone) + userStronghold.ore = int(userStronghold.ore) + int(currentBattalion.invOre) serverArmies.RemoveBattalion(currentBattalion) userStronghold.write() userStronghold.read() @@ -72,4 +100,122 @@ def BattalionMenu(screen, userStronghold, STRONGHOLD, USER_STRONGHOLD): else: return "battalions" + if screen == "battalionMap": + os.system("clear") + if BatMenu: + headerBattalion(currentBattalion, userStronghold, serverMap) + else: + header(userStronghold.name) + GenerateBattalionMap(serverMap, userStronghold, serverArmies, yPos, xPos) + + print("\n Avalible Commands:") + print(' ------------------------------------------------------') + print(' {1}: Go Back') + print(' {2}: List Fiefs and Strongholds') + print(' ------------------------------------------------------') + print('') + command = input(" Enter your command: ") + + if str(command) == '1': + if BatMenu: + return "commandBattalion" + else: + return "battalions" + elif str(command) == '2': + screen = "battalionsMap+" + else: + return "battalionMap" + + if screen == "battalionMap+": + os.system("clear") + if BatMenu: + headerBattalion(currentBattalion, userStronghold, serverMap) + else: + header(userStronghold.name) + GenerateBattalionMapWithLocations(serverMap, userStronghold, serverArmies, yPos, xPos) + + print("\n Avalible Commands:") + print(' ------------------------------------------------------') + print(' {1}: Go Back') + print(' {2}: List Battalions Only') + print(' ------------------------------------------------------') + print('') + command = input(" Enter your command: ") + + if str(command) == '1': + if BatMenu: + return "commandBattalion" + else: + return "battalions" + elif str(command) == '2': + return "battalionsMap" + else: + return "battalionMap+" + + if screen == "battalionNavigation": + os.system("clear") + headerBattalion(currentBattalion, userStronghold, serverMap) + + GenerateMiniMap(serverMap, currentBattalion.yPos, currentBattalion.xPos) + + print("\n Directions:") + print(' -------------') + if int(currentBattalion.xPos) > 0 and int(currentBattalion.xPos) < MAP_WIDTH and int(currentBattalion.yPos) > 0 and int(currentBattalion.yPos) < MAP_HEIGHT: + directions = ['n', 'ne', 'e', 'se', 's', 'sw', 'w', 'nw'] + print(' {NW} {N} {NE}') + print(' {W} {E}') + print(' {SW} {S} {SE}') + elif int(currentBattalion.xPos) == 0 and int(currentBattalion.yPos) > 0 and int(currentBattalion.yPos) < MAP_HEIGHT: + directions = ['n', 'ne', 'e', 'se', 's'] + print(' {X} {N} {NE}') + print(' {X} {E}') + print(' {X} {S} {SE}') + elif int(currentBattalion.xPos) == MAP_WIDTH and int(currentBattalion.yPos) > 0 and int(currentBattalion.yPos) < MAP_HEIGHT: + directions = ['n', 's', 'sw', 'w', 'nw'] + print(' {NW} {N} {X}') + print(' {W} {X}') + print(' {SW} {S} {X}') + elif int(currentBattalion.xPos) > 0 and int(currentBattalion.xPos) < MAP_WIDTH and int(currentBattalion.yPos) == 0: + directions = ['e', 'se', 's', 'sw', 'w'] + print(' {X} {X} {X}') + print(' {W} {E}') + print(' {SW} {S} {SE}') + elif int(currentBattalion.xPos) > 0 and int(currentBattalion.xPos) < MAP_WIDTH and int(currentBattalion.yPos) == MAP_HEIGHT: + directions = ['n', 'ne', 'e', 'w', 'nw'] + print(' {NW} {N} {NE}') + print(' {W} {E}') + print(' {X} {X} {X}') + elif int(currentBattalion.xPos) == MAP_WIDTH and int(currentBattalion.yPos) == MAP_HEIGHT: + directions = ['n', 'w', 'nw'] + print(' {NW} {N} {X}') + print(' {W} {X}') + print(' {X} {X} {X}') + elif int(currentBattalion.xPos) == 0 and int(currentBattalion.yPos) == 0: + directions = ['e', 'se', 's'] + print(' {X} {X} {X}') + print(' {X} {E}') + print(' {X} {S} {SE}') + elif int(currentBattalion.xPos) == MAP_WIDTH and int(currentBattalion.yPos) == 0: + directions = ['s', 'sw', 'w'] + print(' {X} {X} {X}') + print(' {W} {X}') + print(' {SW} {S} {X}') + elif int(currentBattalion.xPos) == 0 and int(currentBattalion.yPos) == MAP_HEIGHT: + directions = ['n', 'ne', 'e'] + print(' {X} {N} {NE}') + print(' {X} {E}') + print(' {X} {X} {X}') + print(' -------------') + print('') + command = input(" Input which direction you would like to go, or hit enter to cancel: ") + + command = str(command.lower()) + + if command in directions: + MoveBattalion(userStronghold, currentBattalion, command) + else: + return "commandBattalion" + + + return screen \ No newline at end of file diff --git a/passages.py b/passages.py index 4e06635..5b0b621 100644 --- a/passages.py +++ b/passages.py @@ -86,6 +86,11 @@ def ReactionTimeEvent(): print(speedColor + "\n Response Time: " + str(formattedTime) + " seconds" + RESET) +def LoadingAnimation(biome): + waitTime = 0.1 + C = BiomeColor(biome) + for i in range(10): + print(str(C + "." + RESET).ljust(10, " "), sep='', end=' ', flush=True); time.sleep(waitTime) def ReactionTimeEvent2(): spacer = " " diff --git a/worldmap.py b/worldmap.py index eea74c5..c723aad 100644 --- a/worldmap.py +++ b/worldmap.py @@ -18,6 +18,7 @@ DEFAULT_WEIGHT = 10 #A common weight total WEIGHT_INTENSITY = 5 #Determines how focused the map will be RANDOM_INTENSITY = 20 #Determines how chaotic the map will be +MAP_SPACER = ' ' #Old River Variables #I'll get rid of these later RIVER_MAP_SCANS = 1 #Determines how many times the map is ran through when placing rivers @@ -56,6 +57,7 @@ UNEXPLORED = '0' LOCATION = '@' RANDOM = '*' +BATTALION = 'B' #Map Icon Color IC_WATER = BLUE @@ -412,25 +414,25 @@ def PrintColorMapWithFiefs(wMap, userName): symbol = wMap[i][j] if j == 0: if symbol == UNEXPLORED: - print(' ' + IC_UNEXPLORED + symbol + RESET, end=" ") + print(MAP_SPACER + IC_UNEXPLORED + symbol + RESET, end=" ") elif symbol == EMPTY: - print(' ' + symbol, end=" ") + print(MAP_SPACER + symbol, end=" ") elif symbol == WATER: - print(' ' + IC_WATER + symbol + RESET, end=" ") + print(MAP_SPACER + IC_WATER + symbol + RESET, end=" ") elif symbol == RIVER[0] or symbol == RIVER[1] or symbol == RIVER[2]: - print(' ' + IC_RIVER + symbol + RESET, end=" ") + print(MAP_SPACER + IC_RIVER + symbol + RESET, end=" ") elif symbol == FOREST: - print(' ' + IC_FOREST + symbol + RESET, end=" ") + print(MAP_SPACER + IC_FOREST + symbol + RESET, end=" ") elif symbol == PLAINS: - print(' ' + IC_PLAINS + symbol + RESET, end=" ") + print(MAP_SPACER + IC_PLAINS + symbol + RESET, end=" ") elif symbol == MOUNTAIN: - print(' ' + IC_MOUNTAIN + symbol + RESET, end=" ") + print(MAP_SPACER + IC_MOUNTAIN + symbol + RESET, end=" ") elif symbol == FIEF: - print(' ' + GetFiefByOwner(i, j, userName) + RESET, end=" ") + print(MAP_SPACER + GetFiefByOwner(i, j, userName) + RESET, end=" ") elif symbol == STRONGHOLD: - print(' ' + IC_STRONGHOLD + symbol + RESET, end=" ") + print(MAP_SPACER + IC_STRONGHOLD + symbol + RESET, end=" ") elif symbol == LOCATION: - print(' ' + IC_LOCATION + symbol + RESET, end=" ") + print(MAP_SPACER + IC_LOCATION + symbol + RESET, end=" ") elif j == MAP_WIDTH - 1: if symbol == UNEXPLORED: print(IC_UNEXPLORED + symbol + RESET, *fiefsInRow, *strongholdsInRow, end=" ") @@ -2762,27 +2764,27 @@ def PrintWorldMapWithLocation(wMap, userName, yPos, xPos): symbol = wMap[i][j] if j == 0: if j == int(xPos) and i == int(yPos): - print(' ' + IC_LOCATION + LOCATION + RESET, end=" ") + print(MAP_SPACER + IC_LOCATION + LOCATION + RESET, end=" ") elif symbol == UNEXPLORED: - print(' ' + IC_UNEXPLORED + symbol + RESET, end=" ") + print(MAP_SPACER + IC_UNEXPLORED + symbol + RESET, end=" ") elif symbol == EMPTY: - print(' ' + symbol, end=" ") + print(MAP_SPACER + symbol, end=" ") elif symbol == WATER: - print(' ' + IC_WATER + symbol + RESET, end=" ") + print(MAP_SPACER + IC_WATER + symbol + RESET, end=" ") elif symbol == RIVER[0] or symbol == RIVER[1] or symbol == RIVER[2]: - print(' ' + IC_RIVER + symbol + RESET, end=" ") + print(MAP_SPACER + IC_RIVER + symbol + RESET, end=" ") elif symbol == FOREST: - print(' ' + IC_FOREST + symbol + RESET, end=" ") + print(MAP_SPACER + IC_FOREST + symbol + RESET, end=" ") elif symbol == PLAINS: - print(' ' + IC_PLAINS + symbol + RESET, end=" ") + print(MAP_SPACER + IC_PLAINS + symbol + RESET, end=" ") elif symbol == MOUNTAIN: - print(' ' + IC_MOUNTAIN + symbol + RESET, end=" ") + print(MAP_SPACER + IC_MOUNTAIN + symbol + RESET, end=" ") elif symbol == FIEF: - print(' ' + GetFiefByOwner(i, j, userName) + RESET, end=" ") + print(MAP_SPACER + GetFiefByOwner(i, j, userName) + RESET, end=" ") elif symbol == STRONGHOLD: - print(' ' + IC_STRONGHOLD + symbol + RESET, end=" ") + print(MAP_SPACER + IC_STRONGHOLD + symbol + RESET, end=" ") elif symbol == LOCATION: - print(' ' + IC_LOCATION + symbol + RESET, end=" ") + print(MAP_SPACER + IC_LOCATION + symbol + RESET, end=" ") elif j == MAP_WIDTH - 1: if j == int(xPos) and i == int(yPos): print(IC_LOCATION + LOCATION + RESET, *fiefsInRow, *strongholdsInRow, end=" ") @@ -2887,4 +2889,261 @@ def GetLocation(mapClass, yPos, xPos): else: return "" +#-------------------------------------------------------------------------------------------------------------- +# [BattalionAtCoords] +# Parameters: y, x, coords +# Returns: list depending on rather there is a battalion at the passed coordinates +#-------------------------------------------------------------------------------------------------------------- +def BattalionAtCoords(y, x, coords): + for i in range(len(coords)): + if int(y) == int(coords[i][0]) and int(x) == int(coords[i][1]): + return coords[i] + return "" + +#-------------------------------------------------------------------------------------------------------------- +# [GetBattalionRow] +# Parameters: y, coords +# Returns: list of battalion names +#-------------------------------------------------------------------------------------------------------------- +def GetBattalionRow(y, coords): + battalionRow = [] + foundOne = False + for i in range(len(coords)): + if int(y) == int(coords[i][0]): + battalionRow.append(str("| " + BattalionIconColor(coords[i][4]) + coords[i][3] + RESET)) + foundOne = True + return battalionRow + +#-------------------------------------------------------------------------------------------------------------- +# [PrintWorldMapWithBattalionsAndLocations] +# Parameters: wMap, userName, coords, yPos, xPos +# +# Iterates through a WorldMap and prints a color version. Also prints fiefs along side +# Prints location on the map given passed coordinates +# Prints colored Battalion icons over other locations (besides current location) +#-------------------------------------------------------------------------------------------------------------- +def PrintWorldMapWithBattalionsAndLocations(wMap, userName, coords, yPos, xPos): + for i in range(MAP_HEIGHT): + fiefsInRow = GetFiefRow(i, userName) + strongholdsInRow = GetStrongholdRow(i, userName) + battalionsInRow = GetBattalionRow(i, coords) + for j in range(MAP_WIDTH): + battalion = "" + symbol = wMap[i][j] + if battalionsInRow != "": + battalion = BattalionAtCoords(i, j, coords) + if j == 0: + if j == int(xPos) and i == int(yPos): + print(MAP_SPACER + IC_LOCATION + LOCATION + RESET, end=" ") + elif battalion != "": + print(MAP_SPACER + BattalionIconColor(battalion[4]) + BATTALION + RESET, end=" ") + elif symbol == UNEXPLORED: + print(MAP_SPACER + IC_UNEXPLORED + symbol + RESET, end=" ") + elif symbol == EMPTY: + print(MAP_SPACER + symbol, end=" ") + elif symbol == WATER: + print(MAP_SPACER + IC_WATER + symbol + RESET, end=" ") + elif symbol == RIVER[0] or symbol == RIVER[1] or symbol == RIVER[2]: + print(MAP_SPACER + IC_RIVER + symbol + RESET, end=" ") + elif symbol == FOREST: + print(MAP_SPACER + IC_FOREST + symbol + RESET, end=" ") + elif symbol == PLAINS: + print(MAP_SPACER + IC_PLAINS + symbol + RESET, end=" ") + elif symbol == MOUNTAIN: + print(MAP_SPACER + IC_MOUNTAIN + symbol + RESET, end=" ") + elif symbol == FIEF: + print(MAP_SPACER + GetFiefByOwner(i, j, userName) + RESET, end=" ") + elif symbol == STRONGHOLD: + print(MAP_SPACER + IC_STRONGHOLD + symbol + RESET, end=" ") + elif symbol == LOCATION: + print(MAP_SPACER + IC_LOCATION + symbol + RESET, end=" ") + elif j == MAP_WIDTH - 1: + if j == int(xPos) and i == int(yPos): + print(IC_LOCATION + LOCATION + RESET, *fiefsInRow, *strongholdsInRow, *battalionsInRow, end=" ") + elif battalion != "": + print(BattalionIconColor(battalion[4]) + BATTALION + RESET, *fiefsInRow, *strongholdsInRow, *battalionsInRow, end=" ") + elif symbol == UNEXPLORED: + print(IC_UNEXPLORED + symbol + RESET, *fiefsInRow, *strongholdsInRow, *battalionsInRow, end=" ") + elif symbol == EMPTY: + print(symbol, *fiefsInRow, *strongholdsInRow, *battalionsInRow, end=" ") + elif symbol == WATER: + print(IC_WATER + symbol + RESET, *fiefsInRow, *strongholdsInRow, *battalionsInRow, end=" ") + elif symbol == RIVER[0] or symbol == RIVER[1] or symbol == RIVER[2]: + print(IC_RIVER + symbol + RESET, *fiefsInRow, *strongholdsInRow, *battalionsInRow, end=" ") + elif symbol == FOREST: + print(IC_FOREST + symbol + RESET, *fiefsInRow, *strongholdsInRow, *battalionsInRow, end=" ") + elif symbol == PLAINS: + print(IC_PLAINS + symbol + RESET, *fiefsInRow, *strongholdsInRow, *battalionsInRow, end=" ") + elif symbol == MOUNTAIN: + print(IC_MOUNTAIN + symbol + RESET, *fiefsInRow, *strongholdsInRow, *battalionsInRow, end=" ") + elif symbol == FIEF: + print(GetFiefByOwner(i, j, userName) + RESET, *fiefsInRow, *strongholdsInRow, *battalionsInRow, end=" ") + elif symbol == STRONGHOLD: + print(IC_STRONGHOLD + symbol + RESET, *fiefsInRow, *strongholdsInRow, *battalionsInRow, end=" ") + elif symbol == LOCATION: + print(IC_LOCATION + symbol + RESET, *fiefsInRow, *strongholdsInRow, *battalionsInRow, end=" ") + else: + if j == int(xPos) and i == int(yPos): + print(IC_LOCATION + LOCATION + RESET, end=" ") + elif battalion != "": + print(BattalionIconColor(battalion[4]) + BATTALION + RESET, end=" ") + elif symbol == UNEXPLORED: + print(IC_UNEXPLORED + symbol + RESET, end=" ") + elif symbol == EMPTY: + print(symbol, end=" ") + elif symbol == WATER: + print(IC_WATER + symbol + RESET, end=" ") + elif symbol == RIVER[0] or symbol == RIVER[1] or symbol == RIVER[2]: + print(IC_RIVER + symbol + RESET, end=" ") + elif symbol == FOREST: + print(IC_FOREST + symbol + RESET, end=" ") + elif symbol == PLAINS: + print(IC_PLAINS + symbol + RESET, end=" ") + elif symbol == MOUNTAIN: + print(IC_MOUNTAIN + symbol + RESET, end=" ") + elif symbol == FIEF: + print(GetFiefByOwner(i, j, userName) + RESET, end=" ") + elif symbol == STRONGHOLD: + print(IC_STRONGHOLD + symbol + RESET, end=" ") + elif symbol == LOCATION: + print(IC_LOCATION + symbol + RESET, end=" ") + print('') + +#-------------------------------------------------------------------------------------------------------------- +# [PrintWorldMapWithBattalions] +# Parameters: wMap, userName, coords, yPos, xPos +# +# Iterates through a WorldMap and prints a color version. Also prints fiefs along side +# Prints location on the map given passed coordinates +# Prints colored Battalion icons over other locations (besides current location) +#-------------------------------------------------------------------------------------------------------------- +def PrintWorldMapWithBattalions(wMap, userName, coords, yPos, xPos): + for i in range(MAP_HEIGHT): + battalionsInRow = GetBattalionRow(i, coords) + for j in range(MAP_WIDTH): + battalion = "" + symbol = wMap[i][j] + if battalionsInRow != "": + battalion = BattalionAtCoords(i, j, coords) + if j == 0: + if j == int(xPos) and i == int(yPos): + print(MAP_SPACER + IC_LOCATION + LOCATION + RESET, end=" ") + elif battalion != "": + print(MAP_SPACER + BattalionIconColor(battalion[4]) + BATTALION + RESET, end=" ") + elif symbol == UNEXPLORED: + print(MAP_SPACER + IC_UNEXPLORED + symbol + RESET, end=" ") + elif symbol == EMPTY: + print(MAP_SPACER + symbol, end=" ") + elif symbol == WATER: + print(MAP_SPACER + IC_WATER + symbol + RESET, end=" ") + elif symbol == RIVER[0] or symbol == RIVER[1] or symbol == RIVER[2]: + print(MAP_SPACER + IC_RIVER + symbol + RESET, end=" ") + elif symbol == FOREST: + print(MAP_SPACER + IC_FOREST + symbol + RESET, end=" ") + elif symbol == PLAINS: + print(MAP_SPACER + IC_PLAINS + symbol + RESET, end=" ") + elif symbol == MOUNTAIN: + print(MAP_SPACER + IC_MOUNTAIN + symbol + RESET, end=" ") + elif symbol == FIEF: + print(MAP_SPACER + GetFiefByOwner(i, j, userName) + RESET, end=" ") + elif symbol == STRONGHOLD: + print(MAP_SPACER + IC_STRONGHOLD + symbol + RESET, end=" ") + elif symbol == LOCATION: + print(MAP_SPACER + IC_LOCATION + symbol + RESET, end=" ") + elif j == MAP_WIDTH - 1: + if j == int(xPos) and i == int(yPos): + print(IC_LOCATION + LOCATION + RESET, *battalionsInRow, end=" ") + elif battalion != "": + print(BattalionIconColor(battalion[4]) + BATTALION + RESET, *battalionsInRow, end=" ") + elif symbol == UNEXPLORED: + print(IC_UNEXPLORED + symbol + RESET, *battalionsInRow, end=" ") + elif symbol == EMPTY: + print(symbol, *battalionsInRow, end=" ") + elif symbol == WATER: + print(IC_WATER + symbol + RESET, *battalionsInRow, end=" ") + elif symbol == RIVER[0] or symbol == RIVER[1] or symbol == RIVER[2]: + print(IC_RIVER + symbol + RESET, *battalionsInRow, end=" ") + elif symbol == FOREST: + print(IC_FOREST + symbol + RESET, *battalionsInRow, end=" ") + elif symbol == PLAINS: + print(IC_PLAINS + symbol + RESET, *battalionsInRow, end=" ") + elif symbol == MOUNTAIN: + print(IC_MOUNTAIN + symbol + RESET, *battalionsInRow, end=" ") + elif symbol == FIEF: + print(GetFiefByOwner(i, j, userName) + RESET, *battalionsInRow, end=" ") + elif symbol == STRONGHOLD: + print(IC_STRONGHOLD + symbol + RESET, *battalionsInRow, end=" ") + elif symbol == LOCATION: + print(IC_LOCATION + symbol + RESET, *battalionsInRow, end=" ") + else: + if j == int(xPos) and i == int(yPos): + print(IC_LOCATION + LOCATION + RESET, end=" ") + elif battalion != "": + print(BattalionIconColor(battalion[4]) + BATTALION + RESET, end=" ") + elif symbol == UNEXPLORED: + print(IC_UNEXPLORED + symbol + RESET, end=" ") + elif symbol == EMPTY: + print(symbol, end=" ") + elif symbol == WATER: + print(IC_WATER + symbol + RESET, end=" ") + elif symbol == RIVER[0] or symbol == RIVER[1] or symbol == RIVER[2]: + print(IC_RIVER + symbol + RESET, end=" ") + elif symbol == FOREST: + print(IC_FOREST + symbol + RESET, end=" ") + elif symbol == PLAINS: + print(IC_PLAINS + symbol + RESET, end=" ") + elif symbol == MOUNTAIN: + print(IC_MOUNTAIN + symbol + RESET, end=" ") + elif symbol == FIEF: + print(GetFiefByOwner(i, j, userName) + RESET, end=" ") + elif symbol == STRONGHOLD: + print(IC_STRONGHOLD + symbol + RESET, end=" ") + elif symbol == LOCATION: + print(IC_LOCATION + symbol + RESET, end=" ") + print('') + +#-------------------------------------------------------------------------------------------------------------- +# [AppendStrongholdColors] +# parameters: coords +# Adds stronghold color values to each tuple +#-------------------------------------------------------------------------------------------------------------- +def AppendStrongholdColors(coords): + for filename in os.listdir('strongholds'): + with open(os.path.join('strongholds', filename), 'r') as f: + tempName = filename[:-4] + tempName = Stronghold() + tempName.name = filename[:-4] + tempName.read() + for i in range(len(coords)): + if str(coords[i][2]) == str(tempName.name): + tempList = list(coords[i]) + tempList.append(str(tempName.color)) + tempList = tuple(tempList) + coords[i] = tempList + return coords + +#-------------------------------------------------------------------------------------------------------------- +# [GenerateBattalionMap] +# parameters: mapClass, armyClass, yPos, xPos +# Creates and prints a world map with battalion markers +#-------------------------------------------------------------------------------------------------------------- +def GenerateBattalionMap(mapClass, strongholdClass, armyClass, yPos, xPos): + armyClass.read() + strongholdClass.read() + coords = armyClass.GetBattalionData() + coords = AppendStrongholdColors(coords) + PrintWorldMapWithBattalions(mapClass.worldMap, strongholdClass.name, coords, yPos, xPos) + +#-------------------------------------------------------------------------------------------------------------- +# [GenerateBattalionMapWithLocations] +# parameters: mapClass, armyClass, yPos, xPos +# Creates and prints a world map with battalion markers +#-------------------------------------------------------------------------------------------------------------- +def GenerateBattalionMapWithLocations(mapClass, strongholdClass, armyClass, yPos, xPos): + armyClass.read() + strongholdClass.read() + coords = armyClass.GetBattalionData() + coords = AppendStrongholdColors(coords) + PrintWorldMapWithBattalionsAndLocations(mapClass.worldMap, strongholdClass.name, coords, yPos, xPos) + #eof \ No newline at end of file From fa4f4d6e2fc7ff425180d53febd067121ae70272 Mon Sep 17 00:00:00 2001 From: Steelwing723 Date: Wed, 26 Jan 2022 17:42:37 -0600 Subject: [PATCH 8/9] Movable Battalions --- armies.py | 22 +++++--- art.py | 6 +-- globals.py | 122 +++++++++++++++++++++++++++++++++++++-------- menu_battalions.py | 88 +++++++++----------------------- 4 files changed, 143 insertions(+), 95 deletions(-) diff --git a/armies.py b/armies.py index 48b6fe3..d7c1a88 100644 --- a/armies.py +++ b/armies.py @@ -133,6 +133,16 @@ def GetBattalionObjects(self): def GetBattalion(self, index): return self.battalions[index] + #================================================================================== + # [GetBattalionByName] + # parameters: self, name + # Returns a Battalion object at passed index + #================================================================================== + def GetBattalion(self, name): + for i in range(len(self.battalions)): + if self.battalions[i].name == name: + return self.battalions[i] + #================================================================================== # [RemoveBattalion] # parameters: self, index @@ -153,24 +163,24 @@ def SetBattalionCoords(self, bat, direction): for i in range(len(self.battalions)): if bat == self.battalions[i]: if direction == 'n': - self.battalions[i].yPos = str(int(self.battalions[i].yPos) + 1) + self.battalions[i].yPos = str(int(self.battalions[i].yPos) - 1) elif direction == 'ne': - self.battalions[i].yPos = str(int(self.battalions[i].yPos) + 1) + self.battalions[i].yPos = str(int(self.battalions[i].yPos) - 1) self.battalions[i].xPos = str(int(self.battalions[i].xPos) + 1) elif direction == 'e': self.battalions[i].xPos = str(int(self.battalions[i].xPos) + 1) elif direction == 'se': - self.battalions[i].yPos = str(int(self.battalions[i].yPos) - 1) + self.battalions[i].yPos = str(int(self.battalions[i].yPos) + 1) self.battalions[i].xPos = str(int(self.battalions[i].xPos) + 1) elif direction == 's': - self.battalions[i].yPos = str(int(self.battalions[i].yPos) - 1) + self.battalions[i].yPos = str(int(self.battalions[i].yPos) + 1) elif direction == 'sw': - self.battalions[i].yPos = str(int(self.battalions[i].yPos) - 1) + self.battalions[i].yPos = str(int(self.battalions[i].yPos) + 1) self.battalions[i].xPos = str(int(self.battalions[i].xPos) - 1) elif direction == 'w': self.battalions[i].xPos = str(int(self.battalions[i].xPos) - 1) elif direction == 'nw': - self.battalions[i].yPos = str(int(self.battalions[i].yPos) + 1) + self.battalions[i].yPos = str(int(self.battalions[i].yPos) - 1) self.battalions[i].xPos = str(int(self.battalions[i].xPos) - 1) self.write() diff --git a/art.py b/art.py index 59e81a5..dcca6bd 100644 --- a/art.py +++ b/art.py @@ -126,10 +126,10 @@ def headerFief(fief): #This is a header for displaying Battalion information. def headerBattalion(bat, userStronghold, serverMap): - location = GetLocation(serverMap, bat.yPos, bat.xPos) + location = GetLocation(serverMap, int(bat.yPos), int(bat.xPos)) if location == "": menu = str(bat.MenuBar(userStronghold)) - spacer = 196 + spacer = 210 else: menu = str(bat.MenuBarWithLocation(userStronghold, location)) spacer = 189 @@ -140,7 +140,7 @@ def headerBattalion(bat, userStronghold, serverMap): ' |_|| || |(_||||(/_(_| | | (/_ | (_|(_)||| \_|(_||||(/_ \n' + ' ' + '\n' + (menu.center(spacer, '-')) + '\n' + - (inventory.center(174, '-')) + '\n') + (inventory.center(184, '-')) + '\n') #Define Art: #==================================================================================================================== diff --git a/globals.py b/globals.py index d19a9ac..71a4062 100644 --- a/globals.py +++ b/globals.py @@ -2398,31 +2398,31 @@ def CheckBiome(biome, direction, haveRaft): # return "" #For testing purposes, add a "raft" attribute: - if biome == WATER: - print(" You raft through the " + IC_WATER + "water" + RESET + " to the " + direction) + if str(biome) == WATER: + print(" Your troops raft through the " + IC_WATER + "water" + RESET + " to the " + str(direction)) return "" - if biome == RIVER[0]: - print(" You raft over the Southwest-bound " + IC_RIVER + "river" + RESET + " to the " + direction) + if str(biome) == RIVER[0]: + print(" Your troops raft over the Southwest-bound " + IC_RIVER + "river" + RESET + " to the " + str(direction)) return "" - if biome == RIVER[1]: - print(" You raft over the South-bound " + IC_RIVER + "river" + RESET + " to the " + direction) + if str(biome) == RIVER[1]: + print(" Your troops raft over the South-bound " + IC_RIVER + "river" + RESET + " to the " + str(direction)) return "" - if biome == RIVER[2]: - print(" You raft over the Southeast-bound " + IC_RIVER + "river" + RESET + " to the " + direction) + if str(biome) == RIVER[2]: + print(" Your troops raft over the Southeast-bound " + IC_RIVER + "river" + RESET + " to the " + str(direction)) return "" - if biome == MOUNTAIN: - print(" You travel over the " + IC_MOUNTAIN + "mountain" + RESET + " to the " + direction) + if str(biome) == MOUNTAIN: + print(" Your troops travel over the " + IC_MOUNTAIN + "mountain" + RESET + " to the " + str(direction)) return "" - if biome == FOREST: - print(" You travel through the " + IC_FOREST + "forest" + RESET + " to the " + direction) + if str(biome) == FOREST: + print(" Your troops travel through the " + IC_FOREST + "forest" + RESET + " to the " + str(direction)) return "" - if biome == PLAINS: - print(" You travel through the " + IC_PLAINS + "plains" + RESET + " to the " + direction) + if str(biome) == PLAINS: + print(" Your troops travel through the " + IC_PLAINS + "plains" + RESET + " to the " + str(direction)) return "" - if biome == FIEF: - print(" You travel to the " + IC_FIEF + "fief" + RESET + " to the " + direction) - if biome == STRONGHOLD: - print(" You travel to the " + IC_STRONGHOLD + "stronghold" + RESET + " to the " + direction) + if str(biome) == FIEF: + print(" Your troops travel to the " + IC_FIEF + "fief" + RESET + " to the " + str(direction)) + if str(biome) == STRONGHOLD: + print(" Your troops travel to the " + IC_STRONGHOLD + "stronghold" + RESET + " to the " + str(direction)) return "" #================================================================================== @@ -2434,13 +2434,91 @@ def MoveBattalion(station, battalion, direction): os.system("clear") headerBattalion(battalion, station, serverMap) raft = True #Change this later - surroundings = ScanSurroundings(serverMap.worldMap, battalion.xPos, battalion.yPos) + surroundings = ScanSurroundings(serverMap.worldMap, int(battalion.xPos), int(battalion.yPos)) #[dN, dNE, dE, dSE, dS, dSW, dW, dNW] + # print(*surroundings) if direction == 'n': - LoadingAnimation(surroundings[0]) + direction = 'north' check = CheckBiome(surroundings[0], direction, raft) - - + if direction == 'ne': + direction = 'northeast' + check = CheckBiome(surroundings[1], direction, raft) + if direction == 'e': + direction = 'east' + check = CheckBiome(surroundings[2], direction, raft) + if direction == 'se': + direction = 'southeast' + check = CheckBiome(surroundings[3], direction, raft) + if direction == 's': + direction = 'south' + check = CheckBiome(surroundings[4], direction, raft) + if direction == 'sw': + direction = 'southwest' + check = CheckBiome(surroundings[5], direction, raft) + if direction == 'w': + direction = 'west' + check = CheckBiome(surroundings[6], direction, raft) + if direction == 'nw': + direction = 'northwest' + check = CheckBiome(surroundings[7], direction, raft) + + Wait() + + #Later use 'check' here to make sure a raft exists or something serverArmies.SetBattalionCoords(battalion, direction) +#================================================================================== +# [AvailableDirections] +# parameter: battalion +# returns: list of directions based on map constraints +#================================================================================== +def AvailableDirections(currentBattalion): + if int(currentBattalion.xPos) > 0 and int(currentBattalion.xPos) < MAP_WIDTH and int(currentBattalion.yPos) > 0 and int(currentBattalion.yPos) < MAP_HEIGHT: + directions = ['n', 'ne', 'e', 'se', 's', 'sw', 'w', 'nw'] + print(' {NW} {N} {NE}') + print(' {W} {E}') + print(' {SW} {S} {SE}') + elif int(currentBattalion.xPos) == 0 and int(currentBattalion.yPos) > 0 and int(currentBattalion.yPos) < MAP_HEIGHT: + directions = ['n', 'ne', 'e', 'se', 's'] + print(' {X} {N} {NE}') + print(' {X} {E}') + print(' {X} {S} {SE}') + elif int(currentBattalion.xPos) == MAP_WIDTH and int(currentBattalion.yPos) > 0 and int(currentBattalion.yPos) < MAP_HEIGHT: + directions = ['n', 's', 'sw', 'w', 'nw'] + print(' {NW} {N} {X}') + print(' {W} {X}') + print(' {SW} {S} {X}') + elif int(currentBattalion.xPos) > 0 and int(currentBattalion.xPos) < MAP_WIDTH and int(currentBattalion.yPos) == 0: + directions = ['e', 'se', 's', 'sw', 'w'] + print(' {X} {X} {X}') + print(' {W} {E}') + print(' {SW} {S} {SE}') + elif int(currentBattalion.xPos) > 0 and int(currentBattalion.xPos) < MAP_WIDTH and int(currentBattalion.yPos) == MAP_HEIGHT: + directions = ['n', 'ne', 'e', 'w', 'nw'] + print(' {NW} {N} {NE}') + print(' {W} {E}') + print(' {X} {X} {X}') + elif int(currentBattalion.xPos) == MAP_WIDTH and int(currentBattalion.yPos) == MAP_HEIGHT: + directions = ['n', 'w', 'nw'] + print(' {NW} {N} {X}') + print(' {W} {X}') + print(' {X} {X} {X}') + elif int(currentBattalion.xPos) == 0 and int(currentBattalion.yPos) == 0: + directions = ['e', 'se', 's'] + print(' {X} {X} {X}') + print(' {X} {E}') + print(' {X} {S} {SE}') + elif int(currentBattalion.xPos) == MAP_WIDTH and int(currentBattalion.yPos) == 0: + directions = ['s', 'sw', 'w'] + print(' {X} {X} {X}') + print(' {W} {X}') + print(' {SW} {S} {X}') + elif int(currentBattalion.xPos) == 0 and int(currentBattalion.yPos) == MAP_HEIGHT: + directions = ['n', 'ne', 'e'] + print(' {X} {N} {NE}') + print(' {X} {E}') + print(' {X} {X} {X}') + + return directions + diff --git a/menu_battalions.py b/menu_battalions.py index 82acd1c..7724b03 100644 --- a/menu_battalions.py +++ b/menu_battalions.py @@ -2,10 +2,13 @@ from armies import * BatMenu = False +CurrentBattalion = 0 # Not set up to handle Fiefs just yet! def BattalionMenu(screen, userStronghold, STRONGHOLD, USER_STRONGHOLD): - currentBattalion = 0 + global CurrentBattalion + if CurrentBattalion != 0: + CurrentBattalion = serverArmies.GetBattalion(CurrentBattalion.name) xPos = 0 yPos = 0 if screen == "battalions": @@ -56,15 +59,15 @@ def BattalionMenu(screen, userStronghold, STRONGHOLD, USER_STRONGHOLD): yPos = int(userStronghold.yCoordinate) screen = "battalionMap" elif IsPositiveIntEqualOrLessThan(command, count): - currentBattalion = yourBattalions[int(command) - 1] + CurrentBattalion = yourBattalions[int(command) - 1] screen = "commandBattalion" else: return "battalions" if screen == "commandBattalion": os.system("clear") - headerBattalion(currentBattalion, userStronghold, serverMap) - GenerateMiniMap(serverMap, currentBattalion.yPos, currentBattalion.xPos) + headerBattalion(CurrentBattalion, userStronghold, serverMap) + GenerateMiniMap(serverMap, CurrentBattalion.yPos, CurrentBattalion.xPos) print("\n Avalible Commands:") print(' ------------------------------------------------------') @@ -83,17 +86,17 @@ def BattalionMenu(screen, userStronghold, STRONGHOLD, USER_STRONGHOLD): screen = "battalionNavigation" elif str(command) == '3': BatMenu = True - xPos = int(currentBattalion.xPos) - yPos = int(currentBattalion.yPos) + xPos = int(CurrentBattalion.xPos) + yPos = int(CurrentBattalion.yPos) screen = "battalionMap" elif str(command) == '4': - userStronghold.defenders = int(userStronghold.defenders) + int(currentBattalion.numTroops) - userStronghold.gold = int(userStronghold.gold) + int(currentBattalion.invGold) - userStronghold.food = int(userStronghold.food) + int(currentBattalion.invFood) - userStronghold.wood = int(userStronghold.wood) + int(currentBattalion.invWood) - userStronghold.stone = int(userStronghold.stone) + int(currentBattalion.invStone) - userStronghold.ore = int(userStronghold.ore) + int(currentBattalion.invOre) - serverArmies.RemoveBattalion(currentBattalion) + userStronghold.defenders = int(userStronghold.defenders) + int(CurrentBattalion.numTroops) + userStronghold.gold = int(userStronghold.gold) + int(CurrentBattalion.invGold) + userStronghold.food = int(userStronghold.food) + int(CurrentBattalion.invFood) + userStronghold.wood = int(userStronghold.wood) + int(CurrentBattalion.invWood) + userStronghold.stone = int(userStronghold.stone) + int(CurrentBattalion.invStone) + userStronghold.ore = int(userStronghold.ore) + int(CurrentBattalion.invOre) + serverArmies.RemoveBattalion(CurrentBattalion) userStronghold.write() userStronghold.read() return "battalions" @@ -103,7 +106,7 @@ def BattalionMenu(screen, userStronghold, STRONGHOLD, USER_STRONGHOLD): if screen == "battalionMap": os.system("clear") if BatMenu: - headerBattalion(currentBattalion, userStronghold, serverMap) + headerBattalion(CurrentBattalion, userStronghold, serverMap) else: header(userStronghold.name) GenerateBattalionMap(serverMap, userStronghold, serverArmies, yPos, xPos) @@ -129,7 +132,7 @@ def BattalionMenu(screen, userStronghold, STRONGHOLD, USER_STRONGHOLD): if screen == "battalionMap+": os.system("clear") if BatMenu: - headerBattalion(currentBattalion, userStronghold, serverMap) + headerBattalion(CurrentBattalion, userStronghold, serverMap) else: header(userStronghold.name) GenerateBattalionMapWithLocations(serverMap, userStronghold, serverArmies, yPos, xPos) @@ -154,57 +157,13 @@ def BattalionMenu(screen, userStronghold, STRONGHOLD, USER_STRONGHOLD): if screen == "battalionNavigation": os.system("clear") - headerBattalion(currentBattalion, userStronghold, serverMap) + headerBattalion(CurrentBattalion, userStronghold, serverMap) - GenerateMiniMap(serverMap, currentBattalion.yPos, currentBattalion.xPos) + GenerateMiniMap(serverMap, CurrentBattalion.yPos, CurrentBattalion.xPos) print("\n Directions:") print(' -------------') - if int(currentBattalion.xPos) > 0 and int(currentBattalion.xPos) < MAP_WIDTH and int(currentBattalion.yPos) > 0 and int(currentBattalion.yPos) < MAP_HEIGHT: - directions = ['n', 'ne', 'e', 'se', 's', 'sw', 'w', 'nw'] - print(' {NW} {N} {NE}') - print(' {W} {E}') - print(' {SW} {S} {SE}') - elif int(currentBattalion.xPos) == 0 and int(currentBattalion.yPos) > 0 and int(currentBattalion.yPos) < MAP_HEIGHT: - directions = ['n', 'ne', 'e', 'se', 's'] - print(' {X} {N} {NE}') - print(' {X} {E}') - print(' {X} {S} {SE}') - elif int(currentBattalion.xPos) == MAP_WIDTH and int(currentBattalion.yPos) > 0 and int(currentBattalion.yPos) < MAP_HEIGHT: - directions = ['n', 's', 'sw', 'w', 'nw'] - print(' {NW} {N} {X}') - print(' {W} {X}') - print(' {SW} {S} {X}') - elif int(currentBattalion.xPos) > 0 and int(currentBattalion.xPos) < MAP_WIDTH and int(currentBattalion.yPos) == 0: - directions = ['e', 'se', 's', 'sw', 'w'] - print(' {X} {X} {X}') - print(' {W} {E}') - print(' {SW} {S} {SE}') - elif int(currentBattalion.xPos) > 0 and int(currentBattalion.xPos) < MAP_WIDTH and int(currentBattalion.yPos) == MAP_HEIGHT: - directions = ['n', 'ne', 'e', 'w', 'nw'] - print(' {NW} {N} {NE}') - print(' {W} {E}') - print(' {X} {X} {X}') - elif int(currentBattalion.xPos) == MAP_WIDTH and int(currentBattalion.yPos) == MAP_HEIGHT: - directions = ['n', 'w', 'nw'] - print(' {NW} {N} {X}') - print(' {W} {X}') - print(' {X} {X} {X}') - elif int(currentBattalion.xPos) == 0 and int(currentBattalion.yPos) == 0: - directions = ['e', 'se', 's'] - print(' {X} {X} {X}') - print(' {X} {E}') - print(' {X} {S} {SE}') - elif int(currentBattalion.xPos) == MAP_WIDTH and int(currentBattalion.yPos) == 0: - directions = ['s', 'sw', 'w'] - print(' {X} {X} {X}') - print(' {W} {X}') - print(' {SW} {S} {X}') - elif int(currentBattalion.xPos) == 0 and int(currentBattalion.yPos) == MAP_HEIGHT: - directions = ['n', 'ne', 'e'] - print(' {X} {N} {NE}') - print(' {X} {E}') - print(' {X} {X} {X}') + directions = AvailableDirections(CurrentBattalion) print(' -------------') print('') command = input(" Input which direction you would like to go, or hit enter to cancel: ") @@ -212,9 +171,10 @@ def BattalionMenu(screen, userStronghold, STRONGHOLD, USER_STRONGHOLD): command = str(command.lower()) if command in directions: - MoveBattalion(userStronghold, currentBattalion, command) + MoveBattalion(userStronghold, CurrentBattalion, command) + return "battalionNavigation" else: - return "commandBattalion" + return "battalions" From 9b9d2a747b97c5a08e689750176a4d06749acf04 Mon Sep 17 00:00:00 2001 From: Steelwing723 Date: Thu, 27 Jan 2022 10:45:33 -0600 Subject: [PATCH 9/9] Movement --- art.py | 4 ++-- globals.py | 24 +++++++------------- menu_battalions.py | 55 ++++++++++++++++++++++++++++++++-------------- worldmap.py | 12 +++++----- 4 files changed, 54 insertions(+), 41 deletions(-) diff --git a/art.py b/art.py index dcca6bd..56bcf3a 100644 --- a/art.py +++ b/art.py @@ -127,11 +127,11 @@ def headerFief(fief): #This is a header for displaying Battalion information. def headerBattalion(bat, userStronghold, serverMap): location = GetLocation(serverMap, int(bat.yPos), int(bat.xPos)) - if location == "": + if location[0] == "": menu = str(bat.MenuBar(userStronghold)) spacer = 210 else: - menu = str(bat.MenuBarWithLocation(userStronghold, location)) + menu = str(bat.MenuBarWithLocation(userStronghold, location[0])) spacer = 189 inventory = bat.Inventory() print('\n' + diff --git a/globals.py b/globals.py index 71a4062..d23e4b4 100644 --- a/globals.py +++ b/globals.py @@ -2438,29 +2438,21 @@ def MoveBattalion(station, battalion, direction): #[dN, dNE, dE, dSE, dS, dSW, dW, dNW] # print(*surroundings) if direction == 'n': - direction = 'north' - check = CheckBiome(surroundings[0], direction, raft) + check = CheckBiome(surroundings[0], 'north', raft) if direction == 'ne': - direction = 'northeast' - check = CheckBiome(surroundings[1], direction, raft) + check = CheckBiome(surroundings[1], 'northeast', raft) if direction == 'e': - direction = 'east' - check = CheckBiome(surroundings[2], direction, raft) + check = CheckBiome(surroundings[2], 'east', raft) if direction == 'se': - direction = 'southeast' - check = CheckBiome(surroundings[3], direction, raft) + check = CheckBiome(surroundings[3], 'southeast', raft) if direction == 's': - direction = 'south' - check = CheckBiome(surroundings[4], direction, raft) + check = CheckBiome(surroundings[4], 'south', raft) if direction == 'sw': - direction = 'southwest' - check = CheckBiome(surroundings[5], direction, raft) + check = CheckBiome(surroundings[5], 'southwest', raft) if direction == 'w': - direction = 'west' - check = CheckBiome(surroundings[6], direction, raft) + check = CheckBiome(surroundings[6], 'west', raft) if direction == 'nw': - direction = 'northwest' - check = CheckBiome(surroundings[7], direction, raft) + check = CheckBiome(surroundings[7], 'northwest', raft) Wait() diff --git a/menu_battalions.py b/menu_battalions.py index 7724b03..233db03 100644 --- a/menu_battalions.py +++ b/menu_battalions.py @@ -7,8 +7,8 @@ # Not set up to handle Fiefs just yet! def BattalionMenu(screen, userStronghold, STRONGHOLD, USER_STRONGHOLD): global CurrentBattalion - if CurrentBattalion != 0: - CurrentBattalion = serverArmies.GetBattalion(CurrentBattalion.name) + global BatMenu + xPos = 0 yPos = 0 if screen == "battalions": @@ -29,10 +29,10 @@ def BattalionMenu(screen, userStronghold, STRONGHOLD, USER_STRONGHOLD): yourBattalions.append(battalions[i]) leftNumber = str(CYAN + " {" + str(count) + "}" + RESET).rjust(17, " ") location = GetLocation(serverMap, battalions[i].yPos, battalions[i].xPos) - if location == "": + if location[0] == "": print(str(leftNumber) + " " + str(battalions[i].MenuBar(userStronghold))) else: - print(str(leftNumber) + " " + str(battalions[i].MenuBarWithLocation(userStronghold, location))) + print(str(leftNumber) + " " + str(battalions[i].MenuBarWithLocation(userStronghold, location[0]))) print("\n Avalible Commands:") print(' ------------------------------------------------------') @@ -66,15 +66,18 @@ def BattalionMenu(screen, userStronghold, STRONGHOLD, USER_STRONGHOLD): if screen == "commandBattalion": os.system("clear") + if CurrentBattalion != 0: + print(str(CurrentBattalion)) + CurrentBattalion = serverArmies.GetBattalion(CurrentBattalion.name) headerBattalion(CurrentBattalion, userStronghold, serverMap) GenerateMiniMap(serverMap, CurrentBattalion.yPos, CurrentBattalion.xPos) - + print(location[0]) print("\n Avalible Commands:") print(' ------------------------------------------------------') print(' {1}: Go Back') print(' {2}: Move Out') print(' {3}: View World Map') - if location != "": + if location[0] != "": print(' {4}: Disband (' + LIME + 'Units and Inventory are added to this location' + RESET + ')') print(' ------------------------------------------------------') print('') @@ -90,15 +93,33 @@ def BattalionMenu(screen, userStronghold, STRONGHOLD, USER_STRONGHOLD): yPos = int(CurrentBattalion.yPos) screen = "battalionMap" elif str(command) == '4': - userStronghold.defenders = int(userStronghold.defenders) + int(CurrentBattalion.numTroops) - userStronghold.gold = int(userStronghold.gold) + int(CurrentBattalion.invGold) - userStronghold.food = int(userStronghold.food) + int(CurrentBattalion.invFood) - userStronghold.wood = int(userStronghold.wood) + int(CurrentBattalion.invWood) - userStronghold.stone = int(userStronghold.stone) + int(CurrentBattalion.invStone) - userStronghold.ore = int(userStronghold.ore) + int(CurrentBattalion.invOre) - serverArmies.RemoveBattalion(CurrentBattalion) - userStronghold.write() - userStronghold.read() + # DetermineLocation(location) + + if str(location[1]) == 'stronghold': + userStronghold.defenders = int(userStronghold.defenders) + int(CurrentBattalion.numTroops) + userStronghold.gold = int(userStronghold.gold) + int(CurrentBattalion.invGold) + userStronghold.food = int(userStronghold.food) + int(CurrentBattalion.invFood) + userStronghold.wood = int(userStronghold.wood) + int(CurrentBattalion.invWood) + userStronghold.stone = int(userStronghold.stone) + int(CurrentBattalion.invStone) + userStronghold.ore = int(userStronghold.ore) + int(CurrentBattalion.invOre) + serverArmies.RemoveBattalion(CurrentBattalion) + userStronghold.write() + userStronghold.read() + else: + tempFief = Fiefdom() + tempFief.name = str(location[2]) + tempFief.read() + print(str(tempFief.name)) + tempFief.defenders = int(tempFief.defenders) + int(CurrentBattalion.numTroops) + tempFief.gold = int(tempFief.gold) + int(CurrentBattalion.invGold) + tempFief.food = int(tempFief.food) + int(CurrentBattalion.invFood) + tempFief.wood = int(tempFief.wood) + int(CurrentBattalion.invWood) + tempFief.stone = int(tempFief.stone) + int(CurrentBattalion.invStone) + tempFief.ore = int(tempFief.ore) + int(CurrentBattalion.invOre) + serverArmies.RemoveBattalion(CurrentBattalion) + tempFief.write() + tempFief.read() + return "battalions" else: return "battalions" @@ -125,7 +146,7 @@ def BattalionMenu(screen, userStronghold, STRONGHOLD, USER_STRONGHOLD): else: return "battalions" elif str(command) == '2': - screen = "battalionsMap+" + screen = "battalionMap+" else: return "battalionMap" @@ -151,7 +172,7 @@ def BattalionMenu(screen, userStronghold, STRONGHOLD, USER_STRONGHOLD): else: return "battalions" elif str(command) == '2': - return "battalionsMap" + return "battalionMap" else: return "battalionMap+" diff --git a/worldmap.py b/worldmap.py index c723aad..ef027c7 100644 --- a/worldmap.py +++ b/worldmap.py @@ -2874,20 +2874,20 @@ def GetLocation(mapClass, yPos, xPos): tempFief = Fiefdom() tempFief = GetFiefByCoordinates(yPos, xPos) if isinstance(tempFief, Fiefdom): - return str(BiomeColor(tempFief.biome) + str(tempFief.name) + RESET) + return (str(BiomeColor(tempFief.biome) + str(tempFief.name) + RESET), "fief", str(tempFief.name)) else: - return "" + return ("", "", "") elif str(mapClass.worldMap[int(yPos)][int(xPos)]) == STRONGHOLD: tempStronghold = Stronghold() tempStronghold = GetStrongholdByCoordinates(yPos, xPos) if isinstance(tempStronghold, Stronghold): - return str(StrongholdColor(tempStronghold.color) + str(tempStronghold.name) + "'s Stronghold" + RESET) + return (str(StrongholdColor(tempStronghold.color) + str(tempStronghold.name) + "'s Stronghold" + RESET), "stronghold", str(tempStronghold.name)) else: - return "" + return ("", "", "") else: - return "" + return ("", "", "") #-------------------------------------------------------------------------------------------------------------- # [BattalionAtCoords] @@ -3137,7 +3137,7 @@ def GenerateBattalionMap(mapClass, strongholdClass, armyClass, yPos, xPos): #-------------------------------------------------------------------------------------------------------------- # [GenerateBattalionMapWithLocations] # parameters: mapClass, armyClass, yPos, xPos -# Creates and prints a world map with battalion markers +# Creates and prints a world map with battalion markers and fief/stronghold locations #-------------------------------------------------------------------------------------------------------------- def GenerateBattalionMapWithLocations(mapClass, strongholdClass, armyClass, yPos, xPos): armyClass.read()