Skip to main content

Item() rundown

 The item() class holds the information of the item and also runs the item effect when it gets used. Constructor def __init__ ( self , command , name , cost , usage): self .effect = command self .name = name self .cost = cost self .usage = usage The effect holds the string name of the effect for the item,  usage holds the value of the Effect . The rest are self-explanatory. EffectHandler() def effectHandler ( self , user: PlayableCharacter , equip= True ): #learned how to specify type of parameter. if equip: if self .effect == "Def" : user.defense = user.defense + self .usage elif self .effect == "AtkPhy" or self .effect == "AtkMag" : user.attack = user.attack + self .usage else : if self .effect == "hp" : user = self .healing(user) return user This handles the effects of the item when it is used. If equip is true then it will check for the equip...

Ready for lift off! With top down desgin!

With my flow charts and my corrected UML in hand, I went on in to create all the functions with default returns and values to get myself set up. The reason I've done this is that I want to practice top design. I heard about it from my Java Programing professor and thought to implement it here just to see what it's like to break down problems into smaller steps beforehand and set up a framework so that it's easy to test things. So let's dive into it!
    First things first, I created a monster object called "thatMonster" to use for testing purposes. It will be removed later down the line. Then I followed up with an outline in the main line of what methods will be called.
# Main Line Commands
inputAndCheck("how would you like to boot? 0 New game or integer of save you are booting", [0])
bootSave(currentAwnser)
input(type(Lori.level))
generateCharacters()
os.system("cls")
input("we made it!!!")
if chapter == 0:
input("Opening")
chapter += 1
Lauren.level += 1
generateCharacters()
while chapter < 24:
# the main game
explorer()
input("credits")
chapter += 1
while chapter < 27:
# the post game
explorer()
input("credits and close")
input("Extra Data:" + str(x) + " " + str(y) + " " + str(z))
Explorer() was also added to theMain.py. along with a few default values that tick up the chapter and location.
def explorer():
global x
global y
global z
global chapter
#Code goes here

#defualt iterations. temporary.
x += 1
y += 1
chapter += 1
Character and its sub-classes were already made, so I went to work on the Shop class next. It has a constructor (subject to change) and the currently mostly empty buy(). I also made a CSV import which I might add to the constructor so it can open the items file and fill the items list.
class Shop(object):
items = []
def __init__(self):

#Defualt for now
self.items.append("Items go here")

def buy(self, item):

#Defualt for now
self.items.remove("Items go here")
Then came the GameMenu Class, with 2 lists for hp, names, and max hp. As well as some very rudimentary stuff for displayPC() and displayGameMenu().
from PlayableCharacter import PlayableCharacter

class GameMenu(object):
PClist = []
# PChp List will use [current, total]
PChpList = []

def __init__(self):

#Defualt for now
self.PClist.append("Character Object")
self.PChpList.append(["current", "total"])

def displayPC(self, PlayableCharacter):

#Defualt for now
print(PlayableCharacter.displayName)


def displayGameMenu(self):

#defualt for now
for pc in self.PClist:
print(pc)
The big one, Combat class, was up to bat next. It's a little messy right now, so this will probably be the first one I work on.  I made 2 lists instead of the one I had planed before because the initiativeRoll() will need to reorganize the lists and I think it'll be easier with 2 lists. skillHandler does literally nothing as of now, so it needs lots of development to get it running. Turn() needs to be worked on heavily as well, but fortunately, baseAttack() doesn't need much more work.
from Character import Character
from PlayableCharacter import PlayableCharacter
from Monster import Monster
import random


class Combat(object):

def __init__(self):
self.order = []
self.listing = []

def skillHandler(self, skill):

# defualt for now
input("Skill!")

def intiativeRoll(self, Combatant):

# defualt for now
self.listing.append([Combatant.displayName, random.random()])
self.order.append([Combatant.displayName, Combatant])

def combatEndCheck(self):

# default for now
if len(self.order) == 0:
input("Combat is over!")

def baseAttack(self, attacker, defender):
targetingNum = random.random() * 100

# defualt for now
if targetingNum > 50:
defender.currentHealth = defender.currentHealth - (attacker.attack -
defender.defense)

def turn(self, Ally):

# defualt for now
self.baseAttack(Ally, self.order[0][1])
Finally, the Location Class was made. It's fairly small and self-explanatory. hopefully, it stays that way.
import csv

class Location(object):

def __init__(self, Name= "Display", x= 0, y= 0, z= 0):
self.displayName = Name
self.x = x
self.y = y
self.z = z
self.storyFlag
After all that work, theMain.py was run and here was our output:

how would you like to boot? 0 New game or integer of save you are booting0
success: Type Correct
Success: Valid Awnser
0
<class 'int'>
we are in
<class 'list'>
['750', '250', '0', '0', '1', '0', '0', '0']
1
<class 'int'>
we made it
we made it
1
<class 'str'>
['Stamina', 'Slash', 'Sweeping Slash', 'Second Wind', 'Guard Up']
['1', '10', '5', '5', '1']
[0, 0, 1, 5, 2]
almost
almost
almost
we made it!!!
Opening
we made it
we made it
1
<class 'str'>
['Stamina', 'Slash', 'Sweeping Slash', 'Second Wind', 'Guard Up']
['1', '10', '5', '5', '1']
[0, 0, 1, 5, 2, 0, 0, 1, 5, 2]
we made it
we made it
1
<class 'str'>
['Light Arrows', 'Smiting Arrow', 'Restoring Arrow', 'Focus Light', 'Quick Hands']
['1', '10', '7', '2', '5']
[0, 1, 1, 1, 0]
almost
almost
credits
credits and close
Extra Data:775 275 0

Process finished with exit code 0

I'm definitely removing all those loading inputs soon.

Comments

Popular posts from this blog

Item() rundown

 The item() class holds the information of the item and also runs the item effect when it gets used. Constructor def __init__ ( self , command , name , cost , usage): self .effect = command self .name = name self .cost = cost self .usage = usage The effect holds the string name of the effect for the item,  usage holds the value of the Effect . The rest are self-explanatory. EffectHandler() def effectHandler ( self , user: PlayableCharacter , equip= True ): #learned how to specify type of parameter. if equip: if self .effect == "Def" : user.defense = user.defense + self .usage elif self .effect == "AtkPhy" or self .effect == "AtkMag" : user.attack = user.attack + self .usage else : if self .effect == "hp" : user = self .healing(user) return user This handles the effects of the item when it is used. If equip is true then it will check for the equip...

UML Diagram and Object Oriented Programing.

Currently, the game uses only global variables and the methods in theMain.py to open and load data. It's become cumbersome to constantly call on the global variables for all my methods and I've realized that I'll be limited in the number of monsters I have if I only use global variables for everything. So this has led me to decide to shift to using Object-oriented programing to run my game. Thus I've prepared a UML diagram to show you all my classes, and subclasses, as well as their interactions, methods, and variables.      theMain.py will function as my main line where all classes and methods will be called as well as have some very important functions built into it. That's they it is connected to almost all the other classes. It'll take care of exploration, descriptions, story tracking, starting the game, ending the game, encounter rates, and gold.      GameMenu will be treated as a static class that has information displayed for the game menu as well as...

Combat() completion! Fights exist now!

Combat() has been completed and the game now is starting to feel like a game. It was a lot of work, but I will be honest I was distracted by holiday events and starting University and that's why it took so long to complete. There is so much to go over with Combat() that I'll be making separate posts for each piece of the Combat class with breakdowns on what they do and how. Here I'll post the results and an implementation overview. Comba() as of now: class Combat( object ): def __init__ ( self , continueStatus = True ): self .order = [] self .listing = {} self .continueStatus = continueStatus self .taunt = [] self .defRaise = [] self .atkRaise = [] self .protected = [] self .exp = 0 def combatantOrganizer ( self ): organizedOrder = [] theStringOrder = [] NumOrder = [] for listing in self .order: NumOrder.append(listing[ 1 ]) NumOrder.sort() for...