import random class NorbertQuest(object): def __init__(self): self.weapon = 0 self.armor = 0 self.level = 1 self.m = random.randrange(50)+1+self.level*5 self.cost = 0 self.xp = 0 self.health = 150 self.ehealth = 100 self.money = 100 self.tnls = [100+level*50] self.wepORshield = 0 self.withdraw = 0 self.deposit = 0 self.bankbalance = 0 def Shop(self): self.weapons[1:"Steel Knuckles",2:"Knife",3:"Sword",4:"Gun",5:"Rocket Launcher"] self.armors[1:"Leather Jacket",2:"Padded Sweater",3:"Iron Arm-shield",4:"Bullet-Proof Jacket",5:"Bomber Squad Armor Plated Suit"] print \ """ What'll it be? Weapons: 1 - Steel Knuckles 50$ 2 - Knife 75$ 3 - Sword 300$ 4 - Gun 800$ 5 - Rocket Launcher 2500$ Armor: 1 - Leather Jacket 50$ 2 - Padded Sweater 75$ 3 - Iron Arm-shield 300$ 4 - Bullet-Proof Jacket 800$ 5 - Bomber Squad Armor Plated Suit Type exit to quit. """ self.wepORshield = raw_input("Do you want weapons or armor?") if self.wepORshield == "weapons": self.atk = input("Which weapon do you want?") if self.atk == 1: self.cost = 50 if self.money >= self.cost: print"You have bought",self.weapons[self.atk] self.money = self.money - self.cost self.weapon = 1 self.mode = "restart" elif self.money < self.cost: print"You don't have enough gold to buy this." raw_input("Press [enter] to exit.") self.mode = "restart" elif self.atk == 2: self.cost = 75 if self.money >= self.cost: print"You have bought",self.weapons[self.atk] self.money = self.money - self.cost self.weapon = 2 self.mode = "restart" elif self.money < self.cost: print"You don't have enough gold to buy this." raw_input("Press [enter] to exit.") self.mode = "restart" elif self.atk == 3: self.cost = 300 if self.money >= self.cost: print"You have bought",self.weapons[self.atk] self.money = self.money - self.cost self.weapon = 3 self.mode = "restart" elif self.money < self.cost: print"You don't have enough gold to buy this." raw_input("Press [enter] to exit.") self.mode = "restart" elif self.atk == 4: self.cost = 800 if self.money >= self.cost: print"You have bought",self.weapons[self.atk] self.money = self.money - self.cost self.weapon = 4 self.mode = "restart" elif self.money < self.cost: print"You don't have enough gold to buy this." raw_input("Press [enter] to exit.") self.mode = "restart" if self.atk == 5: self.cost = 2500 if self.money >= self.cost: print"You have bought",self.weapons[self.atk] self.money = self.money - self.cost self.weapon = 5 self.mode = "restart" elif self.money < self.cost: print"You don't have enough gold to buy this." raw_input("Press [enter] to exit.") self.mode = "restart" elif wepORshield == "shield": if self.shield == 1: self.cost = 50 if self.money >= self.cost: print"You have bought",self.armors[self.shield] self.money = self.money - self.cost self.armor = 1 self.mode = "restart" elif self.money < self.cost: print"You don't have enough gold to buy this." raw_input("Press [enter] to exit.") self.mode = "restart" elif self.shield == 2: self.cost = 75 if self.money >= self.cost: print"You have bought",self.armors[self.shield] self.money = self.money - self.cost self.armor = 2 self.mode = "restart" elif self.money < self.cost: print"You don't have enough gold to buy this." raw_input("Press [enter] to exit.") self.mode = "restart" elif self.shield == 3: self.cost = 300 if self.money >= self.cost: print"You have bought",self.armors[self.shield] self.money = self.money - self.cost self.armor = 3 self.mode = "restart" elif self.money < self.cost: print"You don't have enough gold to buy this." raw_input("Press [enter] to exit.") self.mode = "restart" elif self.shield == 4: self.cost = 800 if self.money >= self.cost: print"You have bought",self.armors[self.shield] self.money = self.money - self.cost self.armor = 4 self.mode = "restart" elif self.money < self.cost: print"You don't have enough gold to buy this." raw_input("Press [enter] to exit.") self.mode = "restart" if self.shield == 5: self.cost = 2500 if self.money >= self.cost: print"You have bought",self.armors[self.shield] self.money = self.money - self.cost self.armor = 5 self.mode = "restart" elif self.money < self.cost: print"You don't have enough gold to buy this." raw_input("Press [enter] to exit.") self.mode = "restart" elif self.atk == "exit": self.mode = "restart" def eAttack(self): self.attacke = random.randrange(12)+self.level*12 return self.attacke def HP(self): self.e = self.eAttack() self.d = self.nDefense() self.health = self.health - (self.e - self.d) print "Enemy hits for",self.e print "You block for",self.d print "Your HP is",self.health def nAttack(self): self.attack = random.randrange(10)+self.level*10 if self.weapon == 1: self.attack = random.randrange(10)+35+self.level*10 elif self.weapon == 2: self.attack = random.randrange(10)+55+self.level*10 elif self.weapon == 3: self.attack = random.randrange(10)+90+self.level*10 elif self.weapon == 4: self.attack = random.randrange(10)+150+self.level*10 elif self.weapon == 5: self.attack = random.randrange(10)+340+self.level*10 return self.attack def nDefense(self): self.armor = random.randrange(5)+self.level*5 if self.armor == 1: self.defense = random.randrange(5)+10+self.level*5 if self.armor == 2: self.defense = random.randrange(5)+25+self.level*5 if self.armor == 3: self.defense = random.randrange(5)+45+self.level*5 if self.armor == 4: self.defense = random.randrange(5)+70+self.level*5 if self.armor == 5: self.defense = random.randrange(5)+125+self.level*5 return self.defense def LVL(self): if 1 <= self.level <= len(self.tnls): self.tnl = self.tnls[self.level-1] if self.tnl <= self.xp: self.level += 1 if self.level > len(self.tnls): self.level = 100 self.xp = 0 print("Your new level is %d! Congratulations!" % self.level) if self.level == 100: print("Congratulations, you beat the Demo!") def EnemyHP(self): self.n = self.nAttack() self.ehealth = self.ehealth - self.n print "You hit for",self.n print "Enemy's HP is",self.ehealth def Bank(self): print"Welcome to the National Bank of NorbertQuest! What will you like to do?" self.bankchoice = raw_input("Do you want to withdraw or deposit? ") if self.bankchoice == "withdraw": print"Your current balance is",bankbalance,"dollars." self.withdraw = raw_input("How much would you like to withdraw? ") if self.withdraw > self.bankbalance: print"You don't have that much money in the bank!" self.mode = "restart" elif self.withdraw <= self.bankbalance: self.bankbalance - self.withdraw = self.money print"Your new bank Balance is",self.bankbalance,"dollars. Thank you." self.mode = "restart" elif self.bankchoice == "deposit": print"Your current balance is",bankbalance,"dollars." self.deposit = raw_input("How much would you like to deposit? ") if self.deposit > self.money: print"You don't have that much money on you!" self.mode = "restart" elif self.deposit <= self.money: self.money - self.deposit = self.bankbalance print"Your new bank Balance is",self.bankbalance,"dollars. Thank you." self.mode = "restart" def Battle(self): self.fight = random.randrange(10)+1 if self.fight == 1: self.monster = "Dragon!" elif self.fight == 2: self.monster = "Rogue Knight!" elif self.fight == 3: self.monster == "Jaguar!" elif self.fight == 4: self.monster = "Orc Lord!" elif self.fight == 5: self.monster = "Goblin!" elif self.fight == 6: self.monster = "Crazy Robot!" elif self.fight == 7: self.monster = "Werewolf!" elif self.fight == 8: self.monster = "Vampire!" elif self.fight == 9: self.monster = "Giant Spider!" elif self.fight == 10: self.monster = "Pirate King!" print "You have encountered a", self.monster, "What will you do?" self.health = 150 + self.level * 100 self.ehealth = 100 + self.level * 125 while self.health > 0 and self.ehealth > 0: self.turn = raw_input("Do you want to attack[1], defend[2] or cast a spell[coming soon]??") if self.turn == 1: print "You're attacking!" self.EnemyHP() self.HP() elif self.turn == 2: print "You're defending!" print "Monster's HP is",self.ehealth print "Your HP is",self.health else: print "Type attack or Defend!" if self.health <= 0: print "You are dead! You lose 50% of the money you have on you!" self.money = self.money/2 elif self.ehealth <= 0: print "You win the battle! You earn",self.m,"$!" self.money = self.money + self.m self.m = random.randrange(50)+1+self.level*5 self.xpGain = random.randrange(25)+self.level+25 self.xp = self.xpGain + self.xp print"You gain",self.xpGain,"Experience Points!" self.LVL() def main(self): while True: print \ """ Welcome to NorbertQuest! Type: - [battle] to hunt monsters - [shop] to buy weapons - [bank] to visit the bank - [badge] to visit the Government Building - [exit] to quit the game """ self.mode = raw_input("What do you want to do?: ") if self.mode == "shop": print"Your current weapon is",self.weapon[self.atk] print"Your current armor is",self.armor[self.shield] print"You have",money,"dollars on you." self.Shop() elif self.mode == "battle": self.Battle() elif self.mode == "badge": if self.level >= 10: print"Your current Government Rank is",self.govrank self.Badge() elif self.level < 10: print"Come back when you're stronger!" self.mode = "restart" elif self.mode == "bank": self.Bank() elif self.mode == "exit": print "If you exit now, all progress will be lost." self.exit = raw_input("Are you sure you want to quit? Yes or no: ") if "yes" in self.exit: break if "no" in self.exit: drlf.mode = "restart" if __name__ == "__main__": n = NorbertQuest() n.main() raw_input("Press [enter] to exit.")
elif self.deposit <= self.money: self.money - self.deposit = self.bankbalance print"Your new bank Balance is",self.bankbalance,"dollars. Thank you." self.mode = "restart"
*** can't assign to operator (NQv1, line 241)
self.money - self.deposit = self.bankbalance
self.bankbalance = self.money - self.deposit
import random class NorbertQuest(object): def __init__(self): self.weapon = 0 self.armor = 0 self.level = 1 self.m = random.randrange(50)+1+self.level*5 self.cost = 0 self.xp = 0 self.health = 150 self.ehealth = 100 self.money = 100 self.tnls = [100+self.level*50] self.wepORshield = 0 self.bankbalance = 0 self.withdraw = 0 self.deposit = 0 def Shop(self): self.weapons[1:"Steel Knuckles",2:"Knife",3:"Sword",4:"Gun",5:"Rocket Launcher"] self.armors[1:"Leather Jacket",2:"Padded Sweater",3:"Iron Arm-shield",4:"Bullet-Proof Jacket",5:"Bomber Squad Armor Plated Suit"] print \ """ What'll it be? Weapons: 1 - Steel Knuckles 50$ 2 - Knife 75$ 3 - Sword 300$ 4 - Gun 800$ 5 - Rocket Launcher 2500$ Armor: 1 - Leather Jacket 50$ 2 - Padded Sweater 75$ 3 - Iron Arm-shield 300$ 4 - Bullet-Proof Jacket 800$ 5 - Bomber Squad Armor Plated Suit Type exit to quit. """ self.wepORshield = raw_input("Do you want weapons or armor?") if self.wepORshield == "weapons": self.atk = input("Which weapon do you want?") if self.atk == 1: self.cost = 50 if self.money >= self.cost: print"You have bought",self.weapons[self.atk] self.money = self.money - self.cost self.weapon = 1 self.mode = "restart" elif self.money < self.cost: print"You don't have enough gold to buy this." raw_input("Press [enter] to exit.") self.mode = "restart" elif self.atk == 2: self.cost = 75 if self.money >= self.cost: print"You have bought",self.weapons[self.atk] self.money = self.money - self.cost self.weapon = 2 self.mode = "restart" elif self.money < self.cost: print"You don't have enough gold to buy this." raw_input("Press [enter] to exit.") self.mode = "restart" elif self.atk == 3: self.cost = 300 if self.money >= self.cost: print"You have bought",self.weapons[self.atk] self.money = self.money - self.cost self.weapon = 3 self.mode = "restart" elif self.money < self.cost: print"You don't have enough gold to buy this." raw_input("Press [enter] to exit.") self.mode = "restart" elif self.atk == 4: self.cost = 800 if self.money >= self.cost: print"You have bought",self.weapons[self.atk] self.money = self.money - self.cost self.weapon = 4 self.mode = "restart" elif self.money < self.cost: print"You don't have enough gold to buy this." raw_input("Press [enter] to exit.") self.mode = "restart" if self.atk == 5: self.cost = 2500 if self.money >= self.cost: print"You have bought",self.weapons[self.atk] self.money = self.money - self.cost self.weapon = 5 self.mode = "restart" elif self.money < self.cost: print"You don't have enough gold to buy this." raw_input("Press [enter] to exit.") self.mode = "restart" elif wepORshield == "shield": if self.shield == 1: self.cost = 50 if self.money >= self.cost: print"You have bought",self.armors[self.shield] self.money = self.money - self.cost self.armor = 1 self.mode = "restart" elif self.money < self.cost: print"You don't have enough gold to buy this." raw_input("Press [enter] to exit.") self.mode = "restart" elif self.shield == 2: self.cost = 75 if self.money >= self.cost: print"You have bought",self.armors[self.shield] self.money = self.money - self.cost self.armor = 2 self.mode = "restart" elif self.money < self.cost: print"You don't have enough gold to buy this." raw_input("Press [enter] to exit.") self.mode = "restart" elif self.shield == 3: self.cost = 300 if self.money >= self.cost: print"You have bought",self.armors[self.shield] self.money = self.money - self.cost self.armor = 3 self.mode = "restart" elif self.money < self.cost: print"You don't have enough gold to buy this." raw_input("Press [enter] to exit.") self.mode = "restart" elif self.shield == 4: self.cost = 800 if self.money >= self.cost: print"You have bought",self.armors[self.shield] self.money = self.money - self.cost self.armor = 4 self.mode = "restart" elif self.money < self.cost: print"You don't have enough gold to buy this." raw_input("Press [enter] to exit.") self.mode = "restart" if self.shield == 5: self.cost = 2500 if self.money >= self.cost: print"You have bought",self.armors[self.shield] self.money = self.money - self.cost self.armor = 5 self.mode = "restart" elif self.money < self.cost: print"You don't have enough gold to buy this." raw_input("Press [enter] to exit.") self.mode = "restart" elif self.atk == "exit": self.mode = "restart" def eAttack(self): self.attacke = random.randrange(12)+self.level*12 return self.attacke def HP(self): self.e = self.eAttack() self.d = self.nDefense() self.health = self.health - (self.e - self.d) print "Enemy hits for",self.e print "You block for",self.d print "Your HP is",self.health def nAttack(self): self.attack = random.randrange(10)+self.level*10 if self.weapon == 1: self.attack = random.randrange(10)+35+self.level*10 elif self.weapon == 2: self.attack = random.randrange(10)+55+self.level*10 elif self.weapon == 3: self.attack = random.randrange(10)+90+self.level*10 elif self.weapon == 4: self.attack = random.randrange(10)+150+self.level*10 elif self.weapon == 5: self.attack = random.randrange(10)+340+self.level*10 return self.attack def nDefense(self): self.armor = random.randrange(5)+self.level*5 if self.armor == 1: self.defense = random.randrange(5)+10+self.level*5 if self.armor == 2: self.defense = random.randrange(5)+25+self.level*5 if self.armor == 3: self.defense = random.randrange(5)+45+self.level*5 if self.armor == 4: self.defense = random.randrange(5)+70+self.level*5 if self.armor == 5: self.defense = random.randrange(5)+125+self.level*5 return self.defense def LVL(self): if 1 <= self.level <= len(self.tnls): self.tnl = self.tnls[self.level-1] if self.tnl <= self.xp: self.level += 1 if self.level > len(self.tnls): self.level = 100 self.xp = 0 print("Your new level is %d! Congratulations!" % self.level) if self.level == 100: print("Congratulations, you beat the Demo!") def EnemyHP(self): self.n = self.nAttack() self.ehealth = self.ehealth - self.n print "You hit for",self.n print "Enemy's HP is",self.ehealth def Bank(self): print"Welcome to the National Bank of NorbertQuest! What will you like to do?" self.bankchoice = raw_input("Do you want to withdraw or deposit? ") if self.bankchoice == "withdraw": print"Your current balance is",self.bankbalance,"dollars." self.withdraw = input("How much would you like to withdraw? ") if self.withdraw > self.bankbalance: print"You don't have that much money in the bank!" self.mode = "restart" elif self.withdraw <= self.bankbalance: self.money = self.bankbalance - self.withdraw self.bankbalance = self.bankbalance - self.withdraw print"Your new bank Balance is",self.bankbalance,"dollars. Thank you." self.mode = "restart" elif self.bankchoice == "deposit": print"Your current balance is",self.bankbalance,"dollars." self.deposit = input("How much would you like to deposit? ") if self.deposit > self.money: print"You don't have that much money on you!" self.mode = "restart" elif self.deposit <= self.money: self.bankbalance = self.money - self.deposit self.money = self.money - self.deposit print"Your new bank Balance is",self.bankbalance,"dollars. Thank you." self.mode = "restart" def Battle(self): self.fight = random.randrange(10)+1 if self.fight == 1: self.monster = "Dragon!" elif self.fight == 2: self.monster = "Rogue Knight!" elif self.fight == 3: self.monster == "Jaguar!" elif self.fight == 4: self.monster = "Orc Lord!" elif self.fight == 5: self.monster = "Goblin!" elif self.fight == 6: self.monster = "Crazy Robot!" elif self.fight == 7: self.monster = "Werewolf!" elif self.fight == 8: self.monster = "Vampire!" elif self.fight == 9: self.monster = "Giant Spider!" elif self.fight == 10: self.monster = "Pirate King!" print "You have encountered a", self.monster, "What will you do?" self.health = 150 + self.level * 100 self.ehealth = 100 + self.level * 125 while self.health > 0 and self.ehealth > 0: self.turn = raw_input("Do you want to attack[1], defend[2] or cast a spell[coming soon]?") if self.turn == 1: print "You're attacking!" self.EnemyHP() self.HP() elif self.turn == 2: print "You're defending!" print "Monster's HP is",self.ehealth print "Your HP is",self.health else: print "Type attack or Defend!" if self.health <= 0: print "You are dead! You lose 50% of the money you have on you!" self.money = self.money/2 elif self.ehealth <= 0: print "You win the battle! You earn",self.m,"$!" self.money = self.money + self.m self.m = random.randrange(50)+1+self.level*10 self.xpGain = random.randrange(25)+1+self.level*25 self.xp = self.xpGain + self.xp print"You gain",self.xpGain,"Experience Points!" self.LVL() def main(self): while True: print \ """ Welcome to NorbertQuest! Type: - [battle] to hunt monsters - [shop] to buy weapons - [bank] to visit the bank - [badge] to visit the Government Building - [exit] to quit the game """ self.mode = raw_input("What do you want to do?: ") if self.mode == "shop": print"Your current weapon is",self.weapon[self.atk] print"Your current armor is",self.armor[self.shield] print"You have",money,"dollars on you." self.Shop() elif self.mode == "battle": self.Battle() elif self.mode == "badge": if self.level >= 10: print"Your current Government Rank is",self.govrank self.Badge() elif self.level < 10: print"Come back when you're stronger!" self.mode = "restart" elif self.mode == "bank": self.Bank() elif self.mode == "exit": print "If you exit now, all progress will be lost." self.exit = raw_input("Are you sure you want to quit? Yes or no: ") if "yes" in self.exit: break if "no" in self.exit: drlf.mode = "restart" if __name__ == "__main__": n = NorbertQuest() n.main() raw_input("Press [enter] to exit.")
elif self.deposit <= self.money: self.bankbalance = self.money - self.deposit self.money = self.money - self.deposit print"Your new bank Balance is",self.bankbalance,"dollars. Thank you." self.mode = "restart"
self.bankbalance = self.bankbalance + self.deposit self.money = self.money - self.deposit
elif self.withdraw <= self.bankbalance: self.money = self.bankbalance - self.withdraw self.bankbalance = self.bankbalance - self.withdraw print"Your new bank Balance is",self.bankbalance,"dollars. Thank you." self.mode = "restart"
self.money = self.money + self.withdraw self.bankbalance = self.bankbalance - self.withdraw
| DaniWeb Message | |
| Cancel Changes | |