Skip to content

Commit

Permalink
Merge branch 'testing'
Browse files Browse the repository at this point in the history
various fixes
  • Loading branch information
brando56894 committed Jun 28, 2016
2 parents 67543a9 + 4bc2417 commit 4ef6475
Show file tree
Hide file tree
Showing 5 changed files with 153 additions and 40 deletions.
26 changes: 13 additions & 13 deletions actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,18 @@
from random import randint
import os
import monsters
import weapons

def roll_dice(newPlayer):
#TODO: add more roles since some options come up too often, also try to find a better random number generator
#TODO: add more rolls since some options come up too often, also try to find a better random number generator
roll = randint(1,6)
newPlayer.steps += roll
if newPlayer.steps >= 75:
print "Boss fight!"
elif newPlayer.steps >= 150:
print "Final Boss fight!"
clearscreen
if roll == 1:
print "\nYou walked %d pace and..." % roll
else:
print "\nYou walked %d paces and..." % roll
print "\nYou walked %d paces and..." % roll
sleep(1)

if roll == 1:
Expand All @@ -23,21 +26,21 @@ def roll_dice(newPlayer):

elif roll == 2:
clearscreen()
newMonster = monsters.create(50,15,"Big Monster") #creates a monster named 'Big Monster' with 50 HP that deals 15 damage per hit
newMonster = monsters.create(35,15,"Big Monster") #creates a monster named 'Big Monster' with 50 HP that deals 15 damage per hit
newMonster.attack(newPlayer)
del newMonster

elif roll == 3:
clearscreen()
newPlayer.find_weapon() #TODO: make this actually do something
newPlayer.find_weapon()

elif roll == 4:
clearscreen()
newPlayer.find_potions()

elif roll == 5:
clearscreen()
newMonster = monsters.create(25,7,"Small Monster") #creates a monster named 'Small Monster' with 25 HP that deals 7 damage per hit
newMonster = monsters.create(20,7,"Small Monster") #creates a monster named 'Small Monster' with 25 HP that deals 7 damage per hit
newMonster.attack(newPlayer)
del newMonster

Expand All @@ -64,10 +67,7 @@ def visit_shop(newPlayer):
newPlayer.buy_potions()

elif choice == 'w':
#TODO: implement a purchase_weapon() function
print "\nSorry we're currently out of weapons"
sleep(2)
visit_shop()
newPlayer.buy_weapon()

elif choice == 'n':
print "\nWhy did you come here then?!"
Expand All @@ -77,7 +77,7 @@ def visit_shop(newPlayer):
else:
print "Not a valid choice"
sleep(2)
visit_shop()
visit_shop(newPlayer)

def quit_game():
print "\nGood Bye!\n"
Expand Down
10 changes: 7 additions & 3 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
import player
from time import sleep

version = 1.6 #Update each time a new feature is committed!

#enables the debug menu option in the main menu
#DEBUG_MODE = "enabled"
DEBUG_MODE = "disabled"
Expand Down Expand Up @@ -54,9 +56,11 @@ def menu():
sleep(2)

#Starts the game
print "Dungeon Quest v1.1\n"
name = raw_input("Who dares to enter the dungeon? ")
newPlayer = player.create(100, 0, 0, 0, "dagger", name) #creates a new player with 100 health, 0 xp, 0 potions, 0 gold, and a dagger (that currently does nothing)
actions.clearscreen()
print "Dungeon Quest v%.2f" % version
name = raw_input("\nWho dares to enter the dungeon? ")
#name="Brandon"
newPlayer = player.create(name)

while newPlayer.health > 0:
menu()
Expand Down
26 changes: 24 additions & 2 deletions monsters.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#~~monsters.py~~

from time import sleep
from random import randint
import actions

class create(object):
Expand All @@ -19,11 +20,32 @@ def attack (self, newPlayer):
choice = raw_input("\nDo you F)ight it or R)un away? ")
choice = choice.lower()
if choice == "f":
#TODO: create turn-based fighting class
print "\nYou decided to fight it. Bad idea! You took 15 damage."
print "\nYou decided to fight it. Bad idea!"
newPlayer.take_damage(self.damage_dealt)
while self.health > 0:
newPlayer.deal_damage(self)
sleep(1)

#monster still attacks after being killed unless health is checked beforehand
if self.health > 0:
self.deal_damage(newPlayer)
sleep(1)
return newPlayer
else:
print "\nYou decided to run away like a scared child!"
sleep(2)
return newPlayer

def take_damage(self, damage_taken, newPlayer):
self.health -= damage_taken
print "\nThe %s took %d damage! Its health is now at %d" % (self.name,damage_taken,self.health)
if self.health <= 0:
print "\nYou killed the %s!" % self.name
newPlayer.gain_xp()
sleep(2)
return self

def deal_damage(self, newPlayer):
print "\nThe %s attacked and dealt %d damage!" % (self.name, self.damage_dealt)
newPlayer.take_damage(self.damage_dealt)
return newPlayer
121 changes: 99 additions & 22 deletions player.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,34 @@
#
#~~Player Functions~~

from random import randint
import actions
import random
from time import sleep
import actions
import weapons

class create(object):

def __init__(self, health, xp, potions, gold, weapons, name):
self.health = health
self.xp = xp
self.potions = potions
self.gold = gold
self.weapons = weapons
def __init__(self, name):
self.health = 100
self.xp = 0
self.potions = 0
self.gold = 0
self.weapons = []
self.name = name
self.steps = 0
self.current_weapon = "dagger"

self.add_weapon("dagger",5)

def __repr__(self):
return self.name

def find_gold(self):
<<<<<<< HEAD
amount = randint(1,20)
=======
amount = random.randint(1,20)
>>>>>>> testing
self.gold += amount
print "\nYou found %d gold coins, which brings you to a total of %d coins!" % (amount, self.gold)
sleep(2)
Expand Down Expand Up @@ -52,20 +64,14 @@ def use_potion(self):
print "\nSorry you don't have any more potions!"
sleep(2)
return self

def find_weapon(self):
#TODO add dictionary of weapons and their damages
#TODO select a random weapon from that list and add it to the player's inventory'
print "\nYou found a weapon!"
sleep(2)
return self

def list_inventory(self):
actions.clearscreen()
print "\nName: "+self.name
print "Exp. Points: %d" % self.xp
print "Potions Held: %d" % self.potions
print "Gold: %d pieces" % self.gold
print "Weapons: %s" % self.weapons[0:]
sleep(4)

def low_health(self):
Expand All @@ -89,15 +95,86 @@ def set_health(self, newHealth):
def take_damage(self, damage):
self.health -= damage
print "Your health is now at %d" % self.health
if self.health < 0:
print "\nYou were slain! Maybe you should carry more health potions with you next time!"
exit(0)
sleep(2)
return self

def deal_damage(self):
#TODO write class based off of damage of currently wielded weapon
#PreREQ: finish find_weapon()
pass
def deal_damage(self,monster):
if self.current_weapon == "dagger":
monster.take_damage(5, self)

if self.current_weapon == "sword":
monster.take_damage(25, self)

if self.current_weapon == "pistol":
monster.take_damage(60, self)

if self.current_weapon == "rifle":
monster.take_damage(120, self)

def gain_xp(self):
#TODO gain XP when player kills a monster and implement leveling system
#PreREQ finish the fighting system
pass
gained = random.randint(1,35)
self.xp += gained
print "\nYou gained %d XP!" % gained

def find_weapon(self):
weapons = ["sword","pistol","rifle"]
found = random.choice(weapons)
print "\nYou found a %s!" % found
if found == "sword":
damage = 25
elif found == "pistol":
damage = 60
else:
damage = 120
self.add_weapon(found,damage)
sleep(2)
return self

def add_weapon(self,name,damage):
newWeapon = weapons.create(name,damage)
self.weapons.append(newWeapon)
return self

def buy_weapon(self):
print "\nS)word: 25 Gold"
print "P)istol: 60 Gold"
print "R)ifle: 120 Gold"
choice = raw_input("\nWhich one would you like to purchase? ")
choice = choice.lower()
if choice == 's'and self.gold >= 25:
self.gold -= 25
self.add_weapon("sword",25)
print "\nA sword has been added to your inventory."
sleep(2)
elif choice == 'p' and self.gold >= 60:
self.gold -= 60
self.add_weapon("pistol",60)
print "\nA pistol has been added to your inventory."
sleep(2)
elif choice == 'r' and self.gold >= 120:
self.gold -= 120
self.add_weapon("rifle",120)
print "\nA rifle has been added to your inventory."
sleep(2)
else:
print "\nSorry you don't have enough gold for that purchase."
sleep(2)
actions.visit_shop(self)
return (self)

def set_current_weapon(self):
print "\nCurrent Weapon: " + self.current_weapon
choice = raw_input("Use weapon: ")
choice = choice.lower()
if choice == "sword":
self.current_weapon = "sword"
elif choice == "pistol":
self.current_weapon = "pistol"
elif choice == "rifle":
self.current_weapon = "rifle"
else:
self.current_weapon = "dagger"
return self
10 changes: 10 additions & 0 deletions weapons.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/usr/bin/python2
#~~weapons.py~~

class create(object):
def __init__(self,name,damage):
self.damage = damage
self.name = name

def __repr__(self):
return self.name

0 comments on commit 4ef6475

Please sign in to comment.