Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ''' Python code by ken Adams
- The structure of Kenβs game: There are five rooms. Going clockwise, we start in the lounge and enter the kitchen,
- dining hall, and bathroom and then back to the lounge. There is a circular shaped veranda that has doors to the kitchen
- (direction SE) and the lounge (direction SW). The player has the option to move to any adjacent room. The game starts
- in the veranda, there is nobody there. There is one character in each of the other rooms, two are friends and two are enemies.
- The player has a sports bag containing three items. Each friend has an item. When the player visits a room containing a friend
- he may swap an item in the bag for the one that the friend has. Each enemy character has a weakness item and if fought with
- this item will be defeated. When the player visits a room with an enemy character in it, the player may fight the enemy.
- The player is asked what item to use for the fight and that item must be in the bag, and be the weakness of the enemy,
- otherwise the player loses. If the player has the item and it is the weakness of the enemy character the player wins victory
- so two victories wins the game. The player has two lives, defeat cost a life so two defeats loses the game.
- The first time there is a meeting the player can decide not to fight an enemy (so can pass by and pick up a weapon by
- swapping with a friend). The second time the player must fight. The moves from room to room are limited (say to 12) so
- the player can also lose if too many moves have already been played. One item in the bag is a weakness of one of the enemies.
- See pastebin for code:
- Kens Game main: https://pastebin.com/NHu4SGA0
- Room object: https://pastebin.com/Mn1HecX6
- Character object: https://pastebin.com/m6WJQNn5
- Item object: https://pastebin.com/GAirfZ5B
- Acknowledgement, much of this code was produced by: the Raspberry Pi Foundation: Object-oriented Programming in Python,
- a FutureLearn Course. The structure of this particular game was crafted by Ken Adams whilst taking the course.
- '''
- from room import Room
- from character import Enemy, Friend
- from item import Bag
- lives = 2
- victories = 0
- moves = 12
- #########################Sports Bag set up##################
- sports = Bag("sports")
- sports.contents = ["banana", "potato", "fish"]
- sports.set_description("\nYour sports bag is large and black with contents:")
- sports.describe()
- #############setting up the characters###################
- dave = Enemy("Dave", "A smelly zombie")
- dave.set_conversation("Brrlgrh... rgrhl... brains...")
- dave.set_weakness("cheese")
- lilif = Enemy("Lilif", "A giant frog")
- lilif.set_conversation("whop whop whop Ah!")
- lilif.set_weakness("banana")
- charles = Friend("Charles", "A friendly octapus")
- charles.set_conversation("let me hug you with my tenticles")
- charles.set_has_item("cheese")
- joy = Friend("joy", "A wise oul")
- joy.set_conversation("hoot I know so much")
- joy.set_has_item("hat")
- #dave.describe()#lilif.describe()#charles.describe()#joy.describe()
- #############################swap#########################
- def SwapItems(myItem, Friend): # finction to exchange an item in the bag with a friends item
- tempItem = Friend.has_item
- Friend.has_item = myItem
- sports.contents.append(tempItem)
- for itemNo in range(len(sports.contents)):
- if sports.contents[itemNo] == myItem:
- tempNo = itemNo
- del sports.contents[tempNo]
- ####code for testing:#print("Charles has " + charles.has_item)#SwapItems("banana",charles)
- #print("Charles has " + charles.has_item)#print(sports.contents)
- #######################setup rooms##############################
- veranda = Room("Veranda")
- veranda.set_description("The Veranda is outside with pot plants and a swinging chair")
- kitchen = Room("Kitchen")
- kitchen.set_description("The kitchen: is a dank and dirty room buzzing with flies.")
- kitchen.set_character(charles)
- dining = Room("Dining")
- dining.set_description(" The dining room is a bright room with lots of chairs and tables.")
- dining.set_character(dave)
- bathroom = Room("bathroom")
- bathroom.set_description("The bathroom is a large bath and a toilet,frosted windows")
- bathroom.set_character(joy)
- lounge = Room("Lounge")
- lounge.set_description("The lounge has confortable chairs and nice pictures")
- lounge.set_character(lilif)
- #veranda.describe()#kitchen.describe()#dining.describe()#bathroom.describe()#lounge.describe()
- #linking the rooms
- veranda.link_room(kitchen, "south-east")
- veranda.link_room(lounge, "south-west")
- kitchen.link_room(veranda, "north-west")
- kitchen.link_room(dining, "south")
- kitchen.link_room(lounge, "west")
- dining.link_room(kitchen, "north")
- dining.link_room(bathroom, "west")
- bathroom.link_room(lounge, "north")
- bathroom.link_room(dining, "east")
- lounge.link_room(bathroom, "south")
- lounge.link_room(kitchen, "east")
- lounge.link_room(veranda, "north-east")
- ####code for testing#print(lounge.linked_rooms['east'].name)#if 'east' in lounge.linked_rooms.keys():
- #print("yes")#veranda.get_details()#kitchen.get_details()#dining.get_details()#bathroom.get_details()
- #lounge.get_details()
- ##############################while loop###############################
- current_room = veranda
- direction = ""
- #The wile loop has three sections controled by insinstance functions, The character in a room is either a Friend (if),
- #Enemy (elif) or nobody there 'None' (else)
- while moves >0:
- print(" you have " + str(moves) +" moves left ")
- current_room.get_details()
- #######################################################Friend#########################
- if isinstance(current_room.character, Friend):
- current_room.character.describe()
- decide = input("Do you want to swap items with your friend, say Y or N ? " )
- if decide == "Y":
- swapit = input("what item will you swap? ")
- if swapit in sports.contents:
- SwapItems(swapit,current_room.character )
- print("Now you have ")
- print(sports.contents)
- else:
- print("sorry you don't have that item, so no swap.")
- else:
- print(" OK no swap ")
- direction=input("What directionn will you move next? ")
- current_room =current_room.move(direction)
- ###################################################################Enemy######################
- elif isinstance(current_room.character, Enemy):
- current_room.character.describe()
- if current_room.character.noFights == 0:
- decide= input("Do you want to fight Y/N? " )
- if decide == "Y":
- weapon = input("choose your weapon? ")
- if weapon in sports.contents and current_room.character.weakness == weapon:
- victories += 1
- if victories == 2:
- print("congratulations you won the game ")
- moves = 0
- else:
- current_room.character = None
- direction = input(" You have " + str(victories) + " victories what direction next ")
- current_room =current_room.move(direction)
- else:
- print("You don't have " + weapon + " so You loose ")
- lives -= 1
- if lives == 0:
- print("You loose the game ")
- moves = 0
- else:
- direction = input(" You have " + str(lives) + " lives left what direction next? ")
- current_room =current_room.move(direction)
- else:
- current_room.character.noFights = 1
- direction=input("OK see you next time, what directionn will you move? ")
- current_room =current_room.move(direction)
- else:
- weapon = input("you have to fight me now, choose your weapon ")
- if weapon in sports.contents and current_room.character.weakness == weapon:
- victories += 1
- if victories == 2:
- print("congratulations you won the game ")
- moves = 0
- else:
- current_room.character = None
- direction = input(" You have " + str(victories) + " victories what direction next ")
- current_room =current_room.move(direction)
- else:
- print("You loose ")
- lives -= 1
- if lives == 0:
- print("You loose the game ")
- moves = 0
- else:
- direction = input(" You have " + str(lives) + " lives left what direction next ")
- current_room =current_room.move(direction)
- ################################################################None########################
- else:
- direction=input("nobody is here so in what directionn will you move? ")
- current_room =current_room.move(direction)
- moves -= 1
- if moves == 0:
- print("Too many moves so you loose the game ")
- print("bye from game ")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement