import random
import math
MaxLevel=100
# Defining Arrays and Dictionaries...
thingsToDo={
"1":"Go to the field to hunt monsters",
"2":"Get some rest"
}
levelHP={}
for i in range(1,MaxLevel+1):
levelHP[str(i)]=100+i*20
levelMP={}
for i in range(1,MaxLevel+1):
levelMP[str(i)]=40+10*i
requestedEXP={}
for i in range(2,MaxLevel):
requestedEXP[str(i)]=20+10*i
# Defining Classes...
class Entity(object):
day=1
def __init__(self,name):
self.name=name
self.level=1
self.HP=100
self.MP=50
self.EXP=0
def setHP(self, HP):
self.HP=HP
def setMP(self, MP):
self.MP=MP
def addHP(self, amountHP):
self.HP+=amountHP
if amountHP<=0:
print("HP decreased by %d!!"%amountHP)
else:
print("HP increased by %d!!"%amountHP)
def addMP(self, amountMP):
self.MP+=amountMP
if amountMP<=0:
print("MP decreased by %d!!"%amountMP)
else:
print("MP increased by %d!!"%amountMP)
def addEXP(self, amountEXP):
self.EXP+=amountEXP
if amountEXP<=0:
print("EXP decreased by %d!!"%amountEXP)
else:
print("EXP increased by %d!!"%amountEXP)
# Defining functions...
def beginningMent():
print("-- Custom RPG V 1.0 --")
print("First, We need to make your own character")
def makingCharacter():
print("Input your character's name")
userName=input("Type here... =")
print("Your name is %s. Let the game begin..."%(userName))
print("A Character instance has been created...")
return Entity(userName)
def printDay(player):
print(" ")
print("-- Day %d --"%player.day)
def printStatus(player):
print("LEVEL : %d"%player.level)
print("HP : %d"%player.HP)
print("MP : %d"%player.MP)
print("EXP : %d out of %d"%(player.EXP, requestedEXP[str(player.level+1)]))
def chooseSelection():
for key, value in thingsToDo.items():
print(key,value)
userInput=input("Input the proper code")
print("You've selected %s."%(userInput))
for key, value in thingsToDo.items():
if userInput==key:
return key
print("You've selected a wrong code")
print("Try again")
chooseSelection()
def branch(code, player):
if code=="1":
hunt(player)
elif code=="2":
rest(player)
def getFullHP(player):
stringifiedLevel=str(player.level)
amountOfFullHP=levelHP[stringifiedLevel]
player.setHP(amountOfFullHP)
def getFullMP(player):
stringifiedLevel=str(player.level)
amountOfFullMP=levelMP[stringifiedLevel]
player.setMP(amountOfFullMP)
def hunt(player):
print("%s is going to the field to hunt some monsters"%player.name)
for encounter in range(1,random.randint(3,5)):
multiplyer=1
if player.HP<10:
print("Your HP is too low!")
print("You are going home")
player.day+=1
return
if player.MP<10:
print("Your MP is too low!")
print("Your power has been decreased!")
multiplyer=0.8
print("-- Encounter %d --"%encounter)
print("A group of wild rats have appeared!!")
winRate=random.randint(0,math.floor(5*multiplyer))
if winRate==0:
print("You have beaten by the wild rats!! What a shame!")
player.addHP(random.randint(-30,-10))
player.addMP(random.randint(-10,-5))
break
else:
print("You have defeated the wild rats!! Congrats!")
player.addHP(random.randint(-30,-10))
player.addMP(random.randint(-10,-5))
player.addEXP(random.randint(10,20))
print("The hunting has finished!!")
player.day+=1
def rest(player):
print("You got some rest!!")
print("Your HP restored!")
print("Your MP restored!")
getFullHP(player)
getFullMP(player)
player.day+=1
def checkLevel(player):
if player.EXP>=requestedEXP[str(player.level+1)]:
print("You've leveled up!!")
print("from %d to %d"%(player.level,player.level+1))
player.level+=1
player.EXP=0
def checkPlayerStatus(player):
if player.HP<0:
print("You have fatigued!!")
print("You can't do anything today!")
rest(player)
# Main part...
beginningMent()
player=makingCharacter()
while(True):
printDay(player)
checkLevel(player)
checkPlayerStatus(player)
printStatus(player)
selection=chooseSelection()
branch(selection, player)