#!/usr/bin/env python
# Grind Quest v1
# - Written by Coty R Miller (C) 6/FEB/2018
#
# This game is basicly a grid simulator... Because YOU LOVE IT!
#
import random
#from monsters import monsters
#from monsters import monsterStats
#from monsters import MonsterAttacks
#from monsters import monsterItems
#from players import players
#from items import items
class monsterStats():
wubwub = "wubwub"
steaking = "Steaking"
health = {wubwub : 20, steaking : 30}
defense = {wubwub : 0, steaking : 0}
speed = {wubwub : 0, steaking : 2}
attack1Name = {wubwub : "Tackle", steaking : "Tackle"}
attack2Name = {wubwub : "Taunt", steaking : "Swipe"}
class monsters():
list = ["wubwub", "Steaking"]
class monsterStats():
wubwub = "wubwub"
steaking = "Steaking"
health = {wubwub : 20, steaking : 30}
defense = {wubwub : 0, steaking : 0}
speed = {wubwub : 0, steaking : 2}
attack1Name = {wubwub : "Tackle", steaking : "Tackle"}
attack2Name = {wubwub : "Taunt", steaking : "Swipe"}
exp = {wubwub : 15, \
steaking : 20}
class MonsterAttacks():
AttackDMG = {"Tackle" : 5, \
"Taunt" : 1, \
"Swipe" : 6}
AttackMSG = {"Tackle" : "Used Tackle", \
"Taunt" : "Is taunting you with a joke about your mother.", \
"Swipe" : "Swiped yo' face"}
class monsterItems():
carry = {"wubwub" : "Gumdrop", \
"Steaking" : "BakedPotato"}
dropChance = {"wubwub" : 2, \
"Steaking" : 4}
class items():
list = ["Gumdrop", "BakedPotato"]
text = {"Gumdrop" : "Gum drop -- A small candy, restores 10HP and 5PP", \
"BakedPotato" : "Baked Potato -- A crispy looking potato, restores 30HP and 1PP"}
playerInventory = {"Gumdrop" : 1, "BakedPotato" : 0}
itemHeal = {"Gumdrop" : 10, \
"BakedPotato" : 30}
itemPPRestore = {"Gumdrop" : 5, \
"BakedPotato" : 1}
class players():
playerStats = {"Health" : 0 , "Speed" : 0, "Attack" : 0}
monsters = monsters()
monsterStats = monsterStats()
MonsterAttacks = MonsterAttacks()
monsterItems = monsterItems()
players = players()
items = items()
maxHealth = 100
health = 100
speed = 1
defense = 1
attack = 1
level = 1
exp = 0
PowerPoints = 5
level2 = 100
level3 = 250
level4 = 500
level5 = 1000
attacks = ["Slash", "Punch"]
attackPower = {"Slash" : 2, "Punch" : 1}
requiresPP = {"Punch" : 0, "Slash" : 1}
#
# getNumbers() -- Get's only numbers 1-9, returns an 11 if invalid key is pressed.
# passing "Force Numbers" > 0 will cause a loop until a real number is given.
#
def getNumbers(disp, forceNumbers):
b = 11
if(forceNumbers == 0):
a = input(disp)
if(a == "0" or \
a == "1" or \
a == "2" or \
a == "3" or \
a == "4" or \
a == "5" or \
a == "6" or \
a == "7" or \
a == "9"):
b = int(a)
else:
while forceNumbers != 0:
a = input(disp)
if(a == "0" or \
a == "1" or \
a == "2" or \
a == "3" or \
a == "4" or \
a == "5" or \
a == "6" or \
a == "7" or \
a == "9"):
b = int(a)
forceNumbers = 0
else:
print("!!! Enter a valid number !!!")
return b
def giveitems(monster):
itemz = "Nothing"
if 1 == random.randint(1,monsterItems.dropChance[monster]):
itemz = monsterItems.carry[monster]
print(" ")
print(monster, "dropped a", itemz)
print("One", itemz, "added to inventory.")
print(" ")
return itemz
def monsterATK(monster, playerHealth, playerDefense, MHP):
zx = playerHealth
if MHP > 0:
# Attack damage = Defense - (Attack power * Attack multiplier)
Attack = random.randint(1,2)
if Attack == 1:
print(monster, MonsterAttacks.AttackMSG[monsterStats.attack1Name[monster]])
a = MonsterAttacks.AttackDMG[monsterStats.attack1Name[monster]]
b = a-playerDefense
playerHealth = playerHealth-b
elif Attack == 2:
print(monster, MonsterAttacks.AttackMSG[monsterStats.attack2Name[monster]])
a = MonsterAttacks.AttackDMG[monsterStats.attack2Name[monster]]
b = a-playerDefense
playerHealth = playerHealth-b
if playerHealth < 0:
playerHealth = 0
if playerHealth > zx:
playerHealth = zx
playerHealth = playerHealth - 1
print("Your health is now", playerHealth)
return playerHealth
def playerTurn(monsterHealth, monsterDefense, playerAttack, attackList, ATKPWR, plhp, PPE, maxhp):
if health > 0:
move = 1. # Allow the player 1 move.
while(move == 1):
print("1. fight")
print("2. Use item")
selection = getNumbers(": ", 1)
# Handle "FIGHT" selection
if(selection == 1):
print("Attack monster with:")
# Print list of attacks.
for i in range(len(attackList)):
# Does it require power points?
if requiresPP[attackList[i]] == 0:
print(i, ":", attackList[i], "0 PP")
else:
print(i, ":", attackList[i], requiresPP[attackList[i]] ,"of", PPE,"/ 5 PP")
sel = getNumbers(": ", 1)
#
# Check to see if attack request is larger than the array list.
atklst = len(attackList)
if(sel > atklst):
print("~>", sel, " Is not a valid Attack...")
else:
# Attack if no PP/Power Points are needed.
if requiresPP[attackList[sel]] == 0:
# Do the damage...
a = ATKPWR[attackList[sel]]
b = playerAttack * a
b = b-monsterDefense
monsterHealth = monsterHealth-b
else:
# ELSE: We need to make sure we have PP
if PPE >= requiresPP[attackList[sel]]:
a = requiresPP[attackList[sel]]
PPE = PPE - a
# Do the damage...
a = ATKPWR[attackList[sel]]
b = playerAttack * a
b = b-monsterDefense
monsterHealth = monsterHealth-b
else:
print(" ")
print("You attempt to attack, but find you don't have the power...")
print(" ")
# Print damage done
if monsterHealth < 0:
monsterHealth = 0
print("Monster health is now", monsterHealth)
move = 0 # no more moves are left.
#
# Handle "USE ITEM" selection
if(selection == 2):
print("Items in inventory...")
avalableItems = []
for i in range(len(items.list)):
if(items.playerInventory[items.list[i]] != 0):
avalableItems.append(items.list[i])
if(len(avalableItems) > 0):
for i in range(len(avalableItems)):
print(i, "-", items.text[avalableItems[i]])
print(" ")
sel = getNumbers("Use: ", 1)
if(sel <= len(avalableItems)):
d = items.playerInventory[items.list[sel]]
d = d - 1
items.playerInventory[items.list[sel]] = d
# Increse Health Points
e = items.itemHeal[avalableItems[sel]]
plhp = plhp + e
if plhp > maxhp:
plhp = maxhp
#
# Increase Power points.
e = items.itemPPRestore[avalableItems[sel]]
PPE = PPE + e
if PPE > 5:
PPE = 5
move = 0 # no more moves are left.
print("Health increased by: ", items.itemHeal[avalableItems[sel]])
print("Your health is now", plhp)
return monsterHealth, plhp, PPE
def battle(monster, playerHealth, xp, PPE, maxhp):
print("A", monster, "apeard.")
print("Fight!")
# Attack damage = Defense - (Attack power * Attack multiplier)
MHP = monsterStats.health[monster]
MDE = monsterStats.defense[monster]
MSD = monsterStats.speed[monster]
while(playerHealth > 1 and MHP > 1):
if speed > monsterStats.speed[monster]:
MHP, playerHealth, PPE = playerTurn(MHP, MDE, attack, attacks, attackPower, playerHealth, PPE, maxhp)
playerHealth = monsterATK(monster, playerHealth, defense, MHP)
elif monsterStats.speed[monster] > speed:
playerHealth = monsterATK(monster, playerHealth, defense, MHP)
MHP, playerHealth, PPE = playerTurn(MHP, MDE, attack, attacks, attackPower, playerHealth, PPE, maxhp)
else:
WhoAttacksFirst = random.randint(1,2)
if WhoAttacksFirst == 1:
MHP, playerHealth, PPE = playerTurn(MHP, MDE, attack, attacks, attackPower, playerHealth, PPE, maxhp)
playerHealth = monsterATK(monster, playerHealth, defense, MHP)
else:
playerHealth = monsterATK(monster, playerHealth, defense, MHP)
MHP, playerHealth, PPE = playerTurn(MHP, MDE, attack, attacks, attackPower, playerHealth, PPE, maxhp)
# If player is Okay and monster is dead, deliver EXP.
if MHP < 1 and playerHealth > 1:
xp = xp + monsterStats.exp[monster]
return playerHealth, xp, PPE
def adjustSkillPoints(points, maxHP, spd, dff, atk):
while points > 0:
print("Pick a stat to use 1 of your", points, "point(s) on.")
print(" ")
print("1. Max health", maxHP)
print("2. speed ", spd)
print("3. Defense ", dff)
print("4. Attack ", atk)
a = input(":")
if a == "1":
points = points - 1
maxHP = maxHP + 1
print("1 Skill point added to ''Max Health''")
elif a == "2":
points = points - 1
spd = spd + 1
print("1 Skill point added to ''Speed''")
elif a == "3":
points = points - 1
dff = dff + 1
print("1 Skill point added to ''Defense''")
elif a == "4":
points = points - 1
atk = atk + 1
print("1 Skill point added to ''Attack''")
else:
print("! ! ! Choose a valid Stat ! ! !")
return maxHP, spd, dff, atk
def printStatUp(maxHP, hp, spd, dff, atk):
print("1. Max health", maxHP,"+10")
print("2. speed ", spd, "+1")
print("3. Defense ", dff, "+1")
print("4. Attack ", atk, "+1")
maxHP = maxHP + 10
hp = hp + 10
spd = spd + 1
dff = dff + 1
atk = atk + 1
return maxHP, hp, spd, dff, atk
def levelup(exp0, lvl, maxHP, spd, dff, atk, hp):
level2 = 100
level3 = 250
level4 = 500
level5 = 1000
if exp0 > level2 and lvl < 2:
print("You've leveled up to level 2.")
maxHP, hp, spd, dff, atk = printStatUp(maxHP, hp, spd, dff, atk)
adjustSkillPoints(1, maxHP, spd, dff, atk)
lvl = 2
if exp0 > level3 and lvl < 3:
print("You've leveled up to level 3.")
maxHP, hp, spd, dff, atk = printStatUp(maxHP, hp, spd, dff, atk)
adjustSkillPoints(1, maxHP, spd, dff, atk)
lvl = 3
if exp0 > level4 and lvl < 4:
print("You've leveled up to level 4.")
maxHP, hp, spd, dff, atk = printStatUp(maxHP, hp, spd, dff, atk)
adjustSkillPoints(1, maxHP, spd, dff, atk)
lvl = 4
if exp0 > level5 and lvl < 5:
print("You've leveled up to level 5.")
maxHP, hp, spd, dff, atk = printStatUp(maxHP, hp, spd, dff, atk)
adjustSkillPoints(1, maxHP, spd, dff, atk)
lvl = 5
return lvl, maxHP, spd, dff, atk, hp
def printSoftSeperator():
print("- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - ")
def printSeperator():
print("--------------------------------------------------------------------------------")
def printHardSeperator():
print("================================================================================")
print("Ready to play Grind quest!?")
yn = input("[y/n]: ")
if yn == "y":
printHardSeperator()
# Allow player to adjust their initial skil points.
checkPoints = 1
while checkPoints != 0:
maxHealth, speed, defense, attack = adjustSkillPoints(3, maxHealth, speed, defense, attack)
health = maxHealth
printSoftSeperator()
print("1. Max health", maxHealth)
print("2. speed ", speed)
print("3. Defense ", defense)
print("4. Attack ", attack)
print(" ")
print("Are these stats okay?")
checkInput = input("[y/n]: ")
if checkInput == "y":
checkPoints = 0
# reset all skill points if anything other than "y" is pressed:
else:
maxHealth = 100
health = 100
speed = 1
defense = 1
attack = 1
printSeperator()
monstersKilled = 1
health, exp, PowerPoints = battle("wubwub", health, exp, PowerPoints, maxHealth)
# Check if the player recieves an item
a = giveitems("wubwub")
if a != "Nothing":
b = items.playerInventory[a]
b = b + 1
items.playerInventory[a] = b
# Continue grind quest until hero dies.
while health > 1:
printSeperator()
# Randomly pick a battle
monster = monsters.list[random.randint(0, len(monsters.list)-1)]
# Put the monster into battle
health, exp, PowerPoints = battle(monster, health, exp, PowerPoints, maxHealth)
# Before we treat player to any level ups or items, ensure player is alive.
if health > 1:
# Check if the player recieves an item
a = giveitems(monster)
if a != "Nothing":
b = items.playerInventory[a]
b = b + 1
items.playerInventory[a] = b
# Check if the player leveled up.
level, maxHealth, speed, defense, attack, health = levelup(exp, level, maxHealth, speed, defense, attack, health)
monstersKilled = monstersKilled + 1
printHardSeperator()
print("You have died.")
print("Total monsters defeated:", monstersKilled)
print(" ")
print("Final stats:")
print("level ", level)
print("Max health", maxHealth)
print("speed ", speed)
print("Defense ", defense)
print("Attack ", attack)
print("EXP.......", exp)
else:
print("Good bye!")