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