Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
210 changes: 202 additions & 8 deletions src/adv.py
Original file line number Diff line number Diff line change
@@ -1,24 +1,56 @@
from player import Player
from room import Room

from potion import Potion
from weapon import Weapon
import random
import os
#declare all weapons
potion0 = Potion("Health potion",3.5,"Adds health to your character","Restoration",'potion');
weapon0 = Weapon("Broken Sword",1,"Broken sword from a failed blacksmith",-1,'weapon');
potion1 = Potion("Mana potion",3,"Adds mana to your character","Restoration",'potion');
weapon1 = Weapon("Necromancers Staff",15,"Staff containing horrible memories",50,'weapon');
potion2 = Potion("Posion potion",2,"Deals damage to enemies","DOT",'potion');
weapon2 = Weapon("Tattered book",5,"Contains magic spells",10,'weapon');
potion3 = Potion("Stamina potion",2,"Adds stamina to your character","Restoration",'potion');
weapon3 = Weapon("Mighty Hammer",25,"Hammer made by dwarves in your backyard",125,'weapon');
# Declare all the rooms

room = {
'outside': Room("Outside Cave Entrance",
"North of you, the cave mount beckons"),
"North of you, the cave mount beckons","outside"
,[" / /"," / \ "," ______/ \______",
"| |","| |",
"| |","| |",
"|__________________|"
],[potion0,potion1]),

'foyer': Room("Foyer", """Dim light filters in from the south. Dusty
passages run north and east."""),
passages run north and east.""",'foyer',
[' ______| |_________',
'| __ ','| |',
'| ________|','| |',
"|_ ___|"," / / ","/ \ "],[weapon0]),

'overlook': Room("Grand Overlook", """A steep cliff appears before you, falling
into the darkness. Ahead to the north, a light flickers in
the distance, but there is no way across the chasm."""),
the distance, but there is no way across the chasm.""",
'overlook',
['_________♀__________',"####################",
"#### ________#######","####| |######",
"####| /#######","#####\ /########",
"######\ /#########","_______| |__________"],[weapon2,weapon1]),

'narrow': Room("Narrow Passage", """The narrow passage bends here from west
to north. The smell of gold permeates the air."""),
to north. The smell of gold permeates the air.""",'narrow',
[' / / ',' / / ',' | |',' | |',' | |','__| |','_____| '],[potion2]),

'treasure': Room("Treasure Chamber", """You've found the long-lost treasure
chamber! Sadly, it has already been completely emptied by
earlier adventurers. The only exit is to the south."""),
earlier adventurers. The only exit is to the south.""",
'treasure',
[' __________________','| § |',
'| § § § |','| § § |',
'| |','| § § |',
'|______ ____§_|',' | |'],[weapon3]),
}


Expand All @@ -36,9 +68,14 @@
#
# Main
#

# Make a new player object that is currently in the 'outside' room.
pName = input('Character\'s name: ')
pSex = input('Character\'s sex: ')
pAge = input('Character\'s age: ')

char = Player(pName,pSex,pAge,"outside");

exit = 0;
# Write a loop that:
#
# * Prints the current room name
Expand All @@ -49,3 +86,160 @@
# Print an error message if the movement isn't allowed.
#
# If the user enters "q", quit the game.


while not exit:
print('you\'re movement is W/A/S/D ',end='\n\n')
print('W=North A=West S=South D=East',end='\n\n')
print('"q", quit the game.',end='\n\n')
print('"e", search room.',end='\n\n')
print('"i", show inventory.',end='\n\n')
#random damage number
randomNum = random.randint(1,101)
#print room name and description
print(room[char.currentRoom()].roomName(), end='\n\n')
print(room[char.currentRoom()].roomDesc(), end='\n\n')
#render map for room
for i in room[char.currentRoom()].roomMap():
print(i)
#player input
movement = input('Where would you like to go : ')
if movement.lower() == 'q':
exit = 1;
#search room
if movement.lower() == 'e':
os.system('cls||clear')
#check if items have been picked up
done = 0
if room[char.currentRoom()].roomItems():
while not done:
print('press "o" to exit item pick up',end='\n\n')
#print all items in room
for x in room[char.currentRoom()].roomItems():
print('item in room:', x.itemName(),end='\n\n')
pickup = input('What item would you like to pickup [get] [item] : ')
#any item picked up?
pickedup = 0
for x in room[char.currentRoom()].roomItems():
pickSplit = pickup.split(' ')
pickSplitItem = " ".join(pickSplit[1:])
#add item to inventory
if pickSplit[0].lower() == 'get':
if pickSplitItem.lower() == x.itemName().lower():
pickedup = 1
os.system('cls||clear')
print('added to your inventory',x.itemName(),x.itemDesc())
char.addItems(x)
room[char.currentRoom()].removeItem(x)
elif not pickSplit[0].lower() == 'o':
os.system('cls||clear')
print('please use [get] [item] syntax',end='\n\n')
break
#exit
if pickup.lower() == 'o':
done = 1
os.system('cls||clear')
if not room[char.currentRoom()].roomItems():
done = 1
os.system('cls||clear')
if not pickedup and not done:
print('item name doesnt exists',end='\n\n')

else:
#if room is empty tell the player
print('room is empty')
#check inventory
if movement.lower() == 'i':
os.system('cls||clear')
#get player items
if char.playerItems():
done = 0
while not done:
action = input('press e to look at inventory, press d to drop items in inventory : ')
if action.lower() == 'e':
done = 1
for x in char.playerItems():
#check item type for output
if x.itemType() == 'weapon':
print('item in your inventory','name:',x.itemName(),
'desc:',x.itemDesc(),"damage:",x.itemDamage())
if x.itemType() == 'potion':
print('item in your inventory','name:',x.itemName(),
'desc:',x.itemDesc(),"effect:",x.itemEffect())
#go to drop menu
if action.lower() == 'd':
while not done:
#list items in inventory
for x in char.playerItems():
print('item in inventory:', x.itemName(),end='\n\n')
print("press 'o' to exit inventory dropping",end='\n\n')
action = input('What item would you like to drop [drop] [item] : ')
dropped = 0
print(action)
#if o exit
if not action.lower() == 'o':
#get items
for x in char.playerItems():
dropSplit = action.split(' ')
dropSplitItem = " ".join(dropSplit[1:])
#drop item from inventory
if dropSplit[0].lower() == 'drop':
print(dropSplitItem.lower())
print(x.itemName().lower())
if dropSplitItem.lower() == x.itemName().lower():
dropped = 1
os.system('cls||clear')
print('dropped from your inventory',x.itemName(),x.itemDesc())
char.dropItem(x)
#incorrect syntax
else:
os.system('cls||clear')
print('please use [drop] [item] syntax',end='\n\n')
break
if action.lower() == 'o':
done = 1
os.system('cls||clear')
if not dropped and not done:
os.system('cls||clear')
print('item name doesnt exists',end='\n\n')

else:
#if inv empty tell the player
print('inventory empty')

'''
movement go north
'''
if movement.lower() == 'w':
os.system('cls||clear')
try:
char.changeRoom(room[char.currentRoom()].n_to.roomId())
except:
print('You hit your face against a wall and take',str(randomNum),'damage',end='\n\n')
'''
movement go west
'''
if movement.lower() == 'a':
os.system('cls||clear')
try:
char.changeRoom(room[char.currentRoom()].w_to.roomId())
except:
print('You hit your face against a wall and take',str(randomNum),'damage',end='\n\n')
'''
movement go south
'''
if movement.lower() == 's':
os.system('cls||clear')
try:
char.changeRoom(room[char.currentRoom()].s_to.roomId())
except:
print('You hit your face against a wall and take',str(randomNum),'damage',end='\n\n')
'''
movement go east
'''
if movement.lower() == 'd':
os.system('cls||clear')
try:
char.changeRoom(room[char.currentRoom()].e_to.roomId())
except:
print('You hit your face against a wall and take',str(randomNum),'damage',end='\n\n')
14 changes: 14 additions & 0 deletions src/item.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
class Item:
def __init__(self,name,weight,desc,type):
self.name = name
self.weight = weight
self.desc = desc
self.type = type
def itemName(self):
return self.name
def itemWeight(self):
return self.weight
def itemDesc(self):
return self.desc
def itemType(self):
return self.type
19 changes: 19 additions & 0 deletions src/player.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,21 @@
# Write a class to hold player information, e.g. what room they are in
# currently.
class Player:
def __init__(self,name,sex,age,room):
self.name = name;
self.sex = sex;
self.age = str(age);
self.room = room;
self.items = [];
def currentRoom(self):
return self.room
def changeRoom(self,room):
self.room = room
def addItems(self,item):
self.items.append(item)
def playerItems(self):
return self.items
def dropItem(self,x):
self.items.remove(x)
def __str__(self):
return 'Name: ' + self.name + ' Age: ' + self.age + ' Sex: ' + self.sex
7 changes: 7 additions & 0 deletions src/potion.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
from item import Item
class Potion(Item):
def __init__(self,name,weight,desc,effect,type):
super().__init__(name, weight,desc,type)
self.effect = effect
def itemEffect(self):
return self.effect
22 changes: 21 additions & 1 deletion src/room.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,22 @@
# Implement a class to hold room information. This should have name and
# description attributes.
# description attributes.
class Room:
def __init__(self,name,desc,id,map,items):
self.name = name
self.desc = desc
self.id = id
self.map = map
self.items = items
def roomName(self):
return self.name
def roomDesc(self):
return self.desc
def roomId(self):
return self.id
def roomMap(self):
return self.map
def roomItems(self):
return self.items
def removeItem(self,x):
self.items.remove(x)
return self.items
7 changes: 7 additions & 0 deletions src/weapon.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
from item import Item
class Weapon(Item):
def __init__(self,name,weight,desc,damage,type):
super().__init__(name, weight,desc,type)
self.damage = damage
def itemDamage(self):
return self.damage