Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

My portion of the assignment #5

Open
wants to merge 11 commits into
base: edge
Choose a base branch
from
24 changes: 13 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,21 @@ A game about a lost crew of pirates exploring the ocean, trying to find their ho
It is designed to be easily extendable, for use in a classroom context. The main extension points are 1) explorable islands and other locations and 2) events. When adding new islands and events, the student will most likely also want to add new 1) monsters and combats and/or 2) items.

To add an event:
1) Make a new .py file in the events/ folder with the handling for your event
2) Add the file name to \_\_init__.py
4) Add the event to an event pool.

1. Make a new .py file in the events/ folder with the handling for your event
2. Add the file name to \_\_init\_\_.py
3. Add the event to an event pool.
Example: To add the event to the world event pool
1) Import the event into world.py
2) Append at least one instance of the event to the events list.
See commit d580f65807d524dabbe84bf49ffd1de524f26e64 for an example
1. Import the event into world.py
2. Append at least one instance of the event to the events list.
See commit d580f65807d524dabbe84bf49ffd1de524f26e64 for an example

To add an explorable location:
1) Make a new .py file in the locations/ folder with the handling for your island
1) Since islands are more complicated than events, you will likely need a template to work from. You can make a copy of the provided example island to get started (make sure to choose a good file and class name!).
2) Add the file name to \_\_init__.py
4) Add the island to the island_list list.
5) You will also need to regularly test your island, I suggest adjusting the test island (testland) in world.py to be an instance of your island. The testland is always directly south of the starting point.

1. Make a new .py file in the locations/ folder with the handling for your island
1. Since islands are more complicated than events, you will likely need a template to work from. You can make a copy of the provided example island to get started (make sure to choose a good file and class name!).
2. Add the file name to \_\_init\_\_.py
3. Add the island to the island_list list.
4. You will also need to regularly test your island, I suggest adjusting the test island (testland) in world.py to be an instance of your island. The testland is always directly south of the starting point.

Each sublocation in an explorable location like an island has its own event pool, so you will also likely want to add events. See island.py and its history for an example.
9 changes: 9 additions & 0 deletions game/combat.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,3 +87,12 @@ def __init__ (self, name):
attacks["punch 2"] = ["punches",random.randrange(35,51), (1,10)]
#7 to 19 hp, bite attack, 65 to 85 speed (100 is "normal")
super().__init__(name, random.randrange(7,20), attacks, 75 + random.randrange(-10,11))

class CrazedPirate(Monster):
def __init__ (self, name):
attacks = {}
attacks["broken bottle swing"] = ["swings broken bottle",random.randrange(35,51), (5,15)]
attacks["punch 1"] = ["punches",random.randrange(35,51), (1,10)]
attacks["punch 2"] = ["punches",random.randrange(35,51), (1,10)]
#10 to 20 hp, broken bottle swing attack, 65 to 85 speed (100 is "normal")
super().__init__(name, random.randrange(10,21), attacks, 75 + random.randrange(-10,11))
3 changes: 2 additions & 1 deletion game/events/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@
"man_eating_monkeys",
"nothing",
"sickness",
"seagull"]
"seagull",
"piranhas"]
1 change: 0 additions & 1 deletion game/events/fish.py

This file was deleted.

52 changes: 52 additions & 0 deletions game/events/piranhas.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
from game import event
from game.player import Player
from game.context import Context
import game.config as config
import random

class EthanPiranha (Context, event.Event):
'''Encounter with jumping piranhas. Uses the parser to decide what to do about it.'''
def __init__(self):
super().__init__()
self.name = "piranha visitor"
self.piranhas = random.randint(1,5)
self.verbs['kick'] = self
self.verbs['help'] = self
self.result = {}
self.go = False

def process_verb(self, verb, cmd_list, nouns):
if (verb == "kick"):
self.go = True
r = random.randint(1,10)
if (r < 5):
self.result["message"] = "the piranhas are kicked off."
if (self.piranhas > 1):
self.piranhas = self.piranhas - 1
else:
c = random.choice(config.the_player.get_pirates())
if (c.isLucky() == True):
self.result["message"] = "luckily, the piranhas are kicked off."
else:
self.result["message"] = c.get_name() + " is hurt by the piranhas."
if (c.inflict_damage(self.piranhas, "Hurt by piranhas")):
self.result["message"] = ".. " + c.get_name() + " is hurt by the piranhas!"

elif (verb == "help"):
print("the piranhas will pester you until you kick them off")
self.go = False
else:
print("it seems the only option here is to kick")
self.go = False

def process(self, world):
self.go = False
self.result = {}
self.result["newevents"] = [self]
self.result["message"] = "default message"

while (self.go == False):
print(str(self.piranhas) + " piranhas have jumped onto the ship, what do you want to do?")
Player.get_interaction([self])

return self.result
2 changes: 1 addition & 1 deletion game/items.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,4 +84,4 @@ def __init__(self):
self.charges = 1
self.skill = "guns"
self.verb = "shoot"
self.verb2 = "shoots"
self.verb2 = "shoots"
171 changes: 171 additions & 0 deletions game/locations/JungleTemple.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,171 @@
from game import location
import game.config as config
from game.display import announce
from game.events import *
from game.items import Item
import random

class GoldenClaymore(Item):
def __init__(self):
super().__init__("golden-claymore", 1000) #Note: price is in shillings (a silver coin, 20 per pound)
self.damage = (50,80)
self.skill = "swords"
self.verb = "slash"
self.verb2 = "slashes"

class EthanJungleTemple(location.Location):

def __init__ (self, x, y, w):
super().__init__(x, y, w)
self.name = "temple"
self.symbol = 'j'
self.visitable = True
self.starting_location = JungleEntrance(self)
self.locations = {}
self.locations["entrence"] = JungleEntrance(self)
self.locations["temple"] = JungleTemple(self)
self.locations["riddle_1"] = RiddleOne(self)
self.locations["riddle_2"] = RiddleTwo(self)
self.locations["riddle_3"] = RiddleThree(self)
self.locations["treasure"] = Treasure(self)

def enter(self, ship):
announce ("You have arrived at a dense, mysterious jungle island.")

def visit(self):
config.the_player.location = self.starting_location
config.the_player.location.enter()
super().visit()

class JungleEntrance(location.SubLocation):
def __init__(self, m):
super().__init__(m)
self.name = "jungleEntrance"
self.verbs['enter'] = self
self.verbs['leave'] = self

def enter(self):
announce ("You stand at the edge of a dense jungle. You can see a mysterious temple deeper inside.\nYou can enter it.")

def process_verb (self, verb, cmd_list, nouns):
if (verb == "leave"):
announce ("You return to your ship.")
config.the_player.next_loc = config.the_player.ship
config.the_player.visiting = False
if (verb == "enter"):
config.the_player.go = True
config.the_player.next_loc = self.main_location.locations["temple"]


class JungleTemple(location.SubLocation):
def __init__(self, m):
super().__init__(m)
self.name = "jungleTemple"
self.verbs['south'] = self
self.verbs['enter'] = self

def enter(self):
announce ("You step into the ancient temple, feeling a sense of reverence and mystery.\nYou see a series of rooms with riddles to solve.")
# Add riddles to solve here, if you get them right, you go to the next room, if you get them wrong, you get attacked by a monster, if you defeat the monster, you go to the next room anyways. At the end, you get a special item, a golden claymore sword

def process_verb (self, verb, cmd_list, nouns):
if (verb == "south"):
announce ("You return to your ship.")
config.the_player.next_loc = config.the_player.ship
config.the_player.visiting = False
if (verb == "enter"):
config.the_player.go = True
config.the_player.next_loc = self.main_location.locations["riddle_1"]

class Riddle(location.SubLocation):
def __init__(self, m, name, question, answers, correct, next_loc):
super().__init__(m)
self.name = name
self.question = question
self.answers = answers
self.correct = correct
self.next_loc = next_loc
self.verbs['answer'] = self
self.verbs['north'] = self

def enter(self):
print (f"\nThe wall reads the following\n\n")
print (f"{self.question}\n")
for key, value in self.answers.items():
print (f"{key}) {value}\n")
print ("\nAnswer with 'answer a' or 'answer b' or 'answer c' or 'answer d'\n")


def process_verb (self, verb, cmd_list, nouns):
if (verb == "answer"):
if cmd_list[1] == self.correct:
announce ("Correct! The door to the next room opens.")
config.the_player.go = True
config.the_player.next_loc = self.main_location.locations[self.next_loc]
else:
game = config.the_player
randomPirate = random.choice(game.get_pirates())
if (randomPirate.isLucky() == True):
announce(f"Incorrect! An arrow shoots from the wall at {randomPirate.get_name()}, but luckely it misses!\n")
else:
randomPirate.inflict_damage(10, " arrow shot.")
announce(f"Incorrect! An arrow shoots from the wall and injures {randomPirate.get_name()}! Try again!\n")

class RiddleOne(Riddle):
def __init__(self, m):
question = "What has keys but can't open locks?"
answers = {
"a": "A piano",
"b": "A computer",
"c": "A book",
"d": "A map"
}
correct = "a"
next_loc = "riddle_2"
super().__init__(m, "riddleOne", question, answers, correct, next_loc)

def enter(self):
print ("The doors all slam around you, there's no turning back now...")
super().enter()

class RiddleTwo(Riddle):
def __init__(self, m):
question = "What has a head, a tail, is brown, and has no legs?"
answers = {
"a": "A snake",
"b": "A horse",
"c": "A penny",
"d": "A banana"
}
correct = "c"
next_loc = "riddle_3"
super().__init__(m, "riddleTwo", question, answers, correct, next_loc)

class RiddleThree(Riddle):
def __init__(self, m):
question = "The more you take, the more you leave behind. What am I?"
answers = {
"a": "A secret",
"b": "Footprints",
"c": "Money",
"d": "Time"
}
correct = "b"
next_loc = "treasure"
super().__init__(m, "riddleThree", question, answers, correct, next_loc)

class Treasure(location.SubLocation):
def __init__(self, m):
super().__init__(m)
self.name = "treasure"
self.verbs['leave'] = self

def enter(self):
announce ("You have solved all the riddles and have reached the treasure room! You see a golden claymore sword in the middle of the room and take it.\nYou can now leave.")
config.the_player.add_to_inventory([GoldenClaymore()])

def process_verb (self, verb, cmd_list, nouns):
if (verb == "leave"):
announce ("You return to your ship.")
config.the_player.next_loc = config.the_player.ship
config.the_player.visiting = False
4 changes: 2 additions & 2 deletions game/locations/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@
"island",
"whirlpool",
"homeport",
"PeacefulIsland"]

"PeacefulIsland",
"JungleTemple"]
11 changes: 7 additions & 4 deletions game/world.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,9 @@ def __init__ (self, s):
self.locs[self.homex][self.homey] = homeport.HomePort (self.homex, self.homey, self)

#Add new islands to this list:
island_list = [island.Island]
island_list = [
island.Island
]
for cur_island in island_list:
placed = False
while placed == False:
Expand All @@ -50,9 +52,9 @@ def __init__ (self, s):
whirl = whirlpool.Whirlpool (self.startx + 1, self.starty, self)
self.locs[self.startx+1][self.starty] = whirl

#Test island: always start off next to a test island. Swap in your island to test yours.
testland = island.Island (self.startx, self.starty+1, self)
self.locs[self.startx][self.starty+1] = testland
# Test island: always start off next to a test island. Swap in your island to test yours.
temple = JungleTemple.EthanJungleTemple (self.startx, self.starty + 1, self)
self.locs[self.startx][self.starty + 1] = temple

# Peaceful island directly to the right of the spawning location.
peacefulIsland = PeacefulIsland.PeacefulIsland(self.startx + 1, self.starty, self)
Expand All @@ -63,6 +65,7 @@ def __init__ (self, s):
self.events.append (nothing.Nothing())
self.events.append (seagull.Seagull())
self.events.append (seagull.Seagull())
self.events.append (piranhas.EthanPiranha())
self.events.append (seagull.Seagull())
self.events.append (sickness.Sickness())
self.events.append (drowned_pirates.DrownedPirates())
Expand Down