diff --git a/armies.py b/armies.py index 6a9de7d..d7c1a88 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,38 @@ 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 + # 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 @@ -87,13 +133,56 @@ def GetBattalions(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 # 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() + + #================================================================================== + # [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() #================================================================================== @@ -101,9 +190,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: + with open(armiesFile, 'w') as f: f.write(str("[")) for i in range(len(self.battalions)): f.write(str("[")) @@ -115,32 +203,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) + "')") - 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") - 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) + "')") + 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,10 +230,10 @@ 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!') + # print('Could not read armies file!') pass class Battalion: @@ -178,8 +246,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 +262,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 +278,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) + loc = str(" | " + 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 3e6d309..56bcf3a 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 @@ -24,15 +24,11 @@ def header(username): headerStronghold.name = username headerStronghold.read() R = textColor.RESET - Y = textColor.YELLOW - D = textColor.DARK_RED - M = textColor.DARK_MAGENTA - G = textColor.DARK_GREEN - E = textColor.DARK_GRAY + M = StrongholdColor(headerStronghold.color) # 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' + @@ -40,7 +36,7 @@ def header(username): ' |_|| || |(_||||(/_(_| | | (/_ | (_|(_)||| \_|(_||||(/_ \n' + ' ' + '\n' + - (line5.center(138, '-')) + '\n' + + (line5.center(156, '-')) + '\n' + (line6.center(155, ' ')) + '\n') # (ANNOUNCEMENT.center(119, '-')) + ' ') @@ -50,15 +46,11 @@ def headerHomeStronghold(username): headerStronghold.name = username headerStronghold.read() R = textColor.RESET - Y = textColor.YELLOW - D = textColor.DARK_RED - M = textColor.DARK_MAGENTA - G = textColor.DARK_GREEN - E = textColor.DARK_GRAY + M = StrongholdColor(headerStronghold.color) # 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' + @@ -66,7 +58,7 @@ def headerHomeStronghold(username): ' |_|| || |(_||||(/_(_| | | (/_ | (_|(_)||| \_|(_||||(/_ \n' + ' ' + '\n' + - (line5.center(138, '-')) + '\n' + + (line5.center(156, '-')) + '\n' + (line6.center(155, ' ')) + '\n' + (ANNOUNCEMENT.center(120, '-')) + ' ') @@ -80,13 +72,9 @@ def headerWithSoldiers(username): headerStronghold.name = username headerStronghold.read() R = textColor.RESET - Y = textColor.YELLOW - D = textColor.DARK_RED - M = textColor.DARK_MAGENTA - G = textColor.DARK_GREEN - E = textColor.DARK_GRAY + M = StrongholdColor(headerStronghold.color) - 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' + @@ -135,15 +107,14 @@ 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 - G = textColor.DARK_GREEN - E = textColor.DARK_GRAY - C = biomeColor(fief.biome) + M = StrongholdColor(headerStronghold.color) + 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' + @@ -153,6 +124,24 @@ 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, int(bat.yPos), int(bat.xPos)) + if location[0] == "": + menu = str(bat.MenuBar(userStronghold)) + spacer = 210 + else: + menu = str(bat.MenuBarWithLocation(userStronghold, location[0])) + spacer = 189 + inventory = bat.Inventory() + print('\n' + +' __ _ __ \n' + +' | |__ __ _ __ _ _| |_ o _ _|_ _| _ __ /__ _ __ _ \n' + +' |_|| || |(_||||(/_(_| | | (/_ | (_|(_)||| \_|(_||||(/_ \n' + +' ' + '\n' + + (menu.center(spacer, '-')) + '\n' + + (inventory.center(184, '-')) + '\n') + #Define Art: #==================================================================================================================== # Splash Screen Art @@ -262,7 +251,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/classes.py b/classes.py index dcb08c7..42d2b91 100644 --- a/classes.py +++ b/classes.py @@ -39,24 +39,6 @@ def biomeColor(biome): return textColor.GREEN elif biome == PLAINS: return textColor.YELLOW - -def strongholdColor(color): - if color == 'red': - return textColor.RED - if color == 'green': - return textColor.GREEN - if color == 'magenta': - return textColor.MAGENTA - if color == 'white': - return textColor.BOLD - if color == 'blue': - return textColor.BLUE - if color == 'yellow': - return textColor.YELLOW - if color == 'cyan': - return textColor.CYAN - if color == 'gray': - return textColor.DARK_GRAY #the fiefdom class holds variables that define a player's stats class Fiefdom: diff --git a/colors.py b/colors.py index 72ac358..cc55398 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,10 @@ 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 +BLACK = '\033[30m' +WHITE = '\u001b[37;1m' RED = '\033[91m' ORANGE = "\u001b[38;5;208m" PINK = "\033[38;5;213m" @@ -67,29 +76,49 @@ 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" +#===================== +# 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 +#===================== +# 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 @@ -106,4 +135,98 @@ 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 + +#=====================#=====================#===================== +# [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 = '~' +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..d23e4b4 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 @@ -214,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 @@ -248,12 +263,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 +2220,297 @@ 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() + + station.defenders = int(station.defenders) - int(numTroops) + station.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" + + +#================================================================================== +# [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 str(biome) == WATER: + print(" Your troops raft through the " + IC_WATER + "water" + RESET + " to the " + str(direction)) + return "" + if str(biome) == RIVER[0]: + print(" Your troops raft over the Southwest-bound " + IC_RIVER + "river" + RESET + " to the " + str(direction)) + return "" + if str(biome) == RIVER[1]: + print(" Your troops raft over the South-bound " + IC_RIVER + "river" + RESET + " to the " + str(direction)) + return "" + if str(biome) == RIVER[2]: + print(" Your troops raft over the Southeast-bound " + IC_RIVER + "river" + RESET + " to the " + str(direction)) + return "" + if str(biome) == MOUNTAIN: + print(" Your troops travel over the " + IC_MOUNTAIN + "mountain" + RESET + " to the " + str(direction)) + return "" + if str(biome) == FOREST: + print(" Your troops travel through the " + IC_FOREST + "forest" + RESET + " to the " + str(direction)) + return "" + if str(biome) == PLAINS: + print(" Your troops travel through the " + IC_PLAINS + "plains" + RESET + " to the " + str(direction)) + return "" + 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 "" + +#================================================================================== +# [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, int(battalion.xPos), int(battalion.yPos)) + #[dN, dNE, dE, dSE, dS, dSW, dW, dNW] + # print(*surroundings) + if direction == 'n': + check = CheckBiome(surroundings[0], 'north', raft) + if direction == 'ne': + check = CheckBiome(surroundings[1], 'northeast', raft) + if direction == 'e': + check = CheckBiome(surroundings[2], 'east', raft) + if direction == 'se': + check = CheckBiome(surroundings[3], 'southeast', raft) + if direction == 's': + check = CheckBiome(surroundings[4], 'south', raft) + if direction == 'sw': + check = CheckBiome(surroundings[5], 'southwest', raft) + if direction == 'w': + check = CheckBiome(surroundings[6], 'west', raft) + if direction == 'nw': + check = CheckBiome(surroundings[7], 'northwest', 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 5fa9bb0..233db03 100644 --- a/menu_battalions.py +++ b/menu_battalions.py @@ -1,36 +1,202 @@ from globals import * from armies import * +BatMenu = False +CurrentBattalion = 0 + +# Not set up to handle Fiefs just yet! def BattalionMenu(screen, userStronghold, STRONGHOLD, USER_STRONGHOLD): + global CurrentBattalion + global BatMenu + + xPos = 0 + yPos = 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[0] == "": + print(str(leftNumber) + " " + str(battalions[i].MenuBar(userStronghold))) + else: + print(str(leftNumber) + " " + str(battalions[i].MenuBarWithLocation(userStronghold, location[0]))) print("\n Avalible Commands:") print(' ------------------------------------------------------') print(' {R}: Return to Stronghold') - print(' {Enter a number above to view the offer}: ') + 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('') command = input(" Enter your command: ") command = str(command.lower()) + if int(userStronghold.defenders) >= 100: + if str(command) == 'c': + return CreateNewBattalion(userStronghold) + if str(command) == 'r': - screen = "stronghold" + return "stronghold" + 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" + else: + return "battalions" + + 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[0] != "": + 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': + # 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" + + 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 = "battalionMap+" + 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 "battalionMap" + else: + return "battalionMap+" + + if screen == "battalionNavigation": + os.system("clear") + headerBattalion(CurrentBattalion, userStronghold, serverMap) + + GenerateMiniMap(serverMap, CurrentBattalion.yPos, CurrentBattalion.xPos) + + print("\n Directions:") + print(' -------------') + directions = AvailableDirections(CurrentBattalion) + 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) + return "battalionNavigation" else: - screen = "market" + return "battalions" + + return screen \ 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_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/menu_upgradesAndCustomizations.py b/menu_upgradesAndCustomizations.py index 23d784f..ee0b91e 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" 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 b7b2086..ef027c7 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=" ") @@ -2520,4 +2522,628 @@ 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(MAP_SPACER + IC_LOCATION + LOCATION + 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, 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) == int(yPos) and int(tempName.xCoordinate) == int(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) == int(yPos) and int(tempName.xCoordinate) == int(xPos): + 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), "fief", str(tempFief.name)) + else: + 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), "stronghold", str(tempStronghold.name)) + else: + return ("", "", "") + + 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 and fief/stronghold locations +#-------------------------------------------------------------------------------------------------------------- +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