import random class MetroidState: def __init__(self): self.itemsCollected = { "Maru Mari": False, "Bombs": False, "Long Beam": False, "Ice Beam": False, "Wave Beam": False, "High Jump Boots": False, "Varia": False, "Screw Attack": False } self.samusHas = { "Maru Mari": False, "Bombs": False, "Long Beam": False, "Ice Beam": False, "Wave Beam": False, "High Jump Boots": False, "Varia": False, "Screw Attack": False } self.missileTanks = { 1: False, 2: False, 3: False, 4: False, 5: False, 6: False, 7: False, 8: False, 9: False, 10: False, 11: False, 12: False, 13: False, 14: False, 15: False, 16: False, 17: False, 18: False, 19: False, 20: False, 21: False } self.energyTanks = { 1: False, 2: False, 3: False, 4: False, 5: False, 6: False, 7: False, 8: False } self.zebetitesDestroyed = { 1: False, 2: False, 3: False, 4: False, 5: False } self.doors = { "Brinstar": { 1: False, 2: False, 3: False, 4: False, 5: False }, "Norfair": { 1: False, 2: False, 3: False, 4: False }, "Kraid": { 1: False, 2: False, 3: False, 4: False, 5: False }, "Ridley": { 1: False, 2: False }, "Tourian": { 1: False, 2: False, 3: False } } self.kraidKilled = False self.ridleyKilled = False self.motherBrainKilled = False self.kraidStatue = False self.ridleyStatue = False self.swimsuit = False self.missileCount = 0 self.gameAge = 0 self.locations = ["Brinstar", "Norfair", "Kraid's Lair", "Ridley's Lair", "Tourian"] self.startLocation = 0 def toggleItem(self, itm): if itm in self.itemsCollected.keys(): self.itemsCollected[itm] = not self.itemsCollected[itm] self.samusHas[itm] = not self.samusHas[itm] else: print("Couldn't find item: {}".format(str(itm))) def toggleMissileTank(self, num): try: num = int(num) except: print("{} is not a number".format(num)) return if num in self.missileTanks.keys(): self.missileTanks[num] = not self.missileTanks[num] else: print("Couldn't find missile tank: {}".format(num)) def toggleEnergyTank(self, num): try: num = int(num) except: print("{} is not a number".format(num)) return if num in self.energyTanks.keys(): self.energyTanks[num] = not self.energyTanks[num] else: print("Couldn't find energy tank: {}".format(num)) def toggleZebetite(self, num): try: num = int(num) except: print("{} is not a number".format(num)) return if num in self.zebetitesDestroyed.keys(): self.zebetitesDestroyed[num] = not self.zebetitesDestroyed[num] else: print("Couldn't find Zebetite: {}".format(num)) def toggleKraid(self): self.kraidKilled = not self.kraidKilled self.kraidStatue = self.kraidKilled def toggleKraidStatue(self): self.kraidStatue = not self.kraidStatue if self.kraidKilled and not self.kraidStatue: print("WARNING: Kraid has been killed but his statue has not been raised.") def toggleRidley(self): self.ridleyKilled = not self.ridleyKilled self.ridleyStatue = self.ridleyKilled def toggleRidleyStatue(self): self.ridleyStatue = not self.ridleyStatue if self.ridleyKilled and not self.ridleyStatue: print("WARNING: Ridley has been killed but his statue has not been raised.") def toggleMotherBrain(self): self.motherBrainKilled = not self.motherBrainKilled def toggleDoor(self, area, door): try: area = str(area) door = int(door) except: print("Area must be string, door must be a positive integer") return if area in self.doors.keys() and int(door) in self.doors[area].keys(): self.doors[area][door] = not self.doors[area][door] else: print("Couldn't find door {} in area {}".format(door, area)) def toggleSwimsuit(self): self.swimsuit = not self.swimsuit def newLocation(self, loc): try: loc = str(loc) except: print("Location must be a string") return if loc in self.locations: self.startLocation = self.locations.index(loc) else: print("Couldn't find location: {}".format(loc)) def collectedItems(self): o = [] for k,v in self.itemsCollected.items(): if v == True: o.append(k) if len(o) == 0: return "None" else: return ", ".join(o) def collectedMissiles(self): o = [] for k, v in self.missileTanks.items(): if v == True: o.append(k) if len(o) == 0: return "None" else: return ", ".join([str(b) for b in o]) def collectedEtanks(self): o = [] for k, v in self.energyTanks.items(): if v == True: o.append(k) if len(o) == 0: return "None" else: return ", ".join([str(b) for b in o]) def killedZebetites(self): o = [] for k, v in self.zebetitesDestroyed.items(): if v == True: o.append(k) if len(o) == 0: return "None" else: return ", ".join([str(b) for b in o]) def killedBosses(self): o = [] if self.kraidKilled: o.append("Kraid") if self.ridleyKilled: o.append("Ridley") if self.motherBrainKilled: o.append("Mother Brain") if len(o) == 0: return "None" else: return ", ".join(o) def raisedStatues(self): o = [] if self.kraidStatue: o.append("Kraid") if self.ridleyStatue: o.append("Ridley") if len(o) == 0: return "None" else: return ", ".join(o) def inBailey(self): if self.swimsuit: return "Yes" else: return "No" def toString(self): ic = "Items Collected: {}".format(self.collectedItems()) mt = "Missile Tanks Collected: {}".format(self.collectedMissiles()) et = "Energy Tanks Collected: {}".format(self.collectedEtanks()) zb = "Zebetites Killed: {}".format(self.killedZebetites()) kb = "Bosses Killed: {}".format(self.killedBosses()) rs = "Statues Raised: {}".format(self.raisedStatues()) sw = "Swimsuit?: {}".format(self.inBailey()) sl = "Start Location: {}".format(self.locations[self.startLocation]) dr = "" return "\n".join([ic, mt, et, zb, kb, rs, sw, sl, dr]) def randomize(self): # Items if random.randint(0,1) == 1: self.toggleItem("Maru Mari") if random.randint(0,1) == 1: self.toggleItem("Bombs") if random.randint(0,1) == 1: self.toggleItem("Varia") if random.randint(0,1) == 1: self.toggleItem("High Jump Boots") if random.randint(0,1) == 1: self.toggleItem("Screw Attack") if random.randint(0,1) == 1: self.toggleItem("Long Beam") beam = random.randint(0,2) if beam == 1: self.toggleItem("Ice Beam") elif beam == 2: self.toggleItem("Wave Beam") # Missile Tanks for i in range(21): if random.randint(0,1) == 1: self.toggleMissileTank(i+1) # Energy Tanks for i in range(8): if random.randint(0,1) == 1: self.toggleEnergyTank(i+1) # Zebetites for i in range(5): if random.randint(0,1) == 1: self.toggleZebetite(i+1) # Bosses killed if random.randint(0,1) == 1: self.toggleKraid() if random.randint(0,1) == 1: self.toggleRidley() if random.randint(0,1) == 1: self.toggleMotherBrain() # Statues raised if not self.kraidKilled and random.randint(0,1) == 1: self.toggleKraidStatue() if not self.ridleyKilled and random.randint(0,1) == 1: self.toggleRidleyStatue() # Swimsuit if random.randint(0,2) == 2: self.toggleSwimsuit() # Start Location self.startLocation = random.randint(0,4) def main(): gs = MetroidState() gs.randomize() print(gs.toString()) if __name__ == "__main__": main()