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

Shop() run down

 This class is responsible for running the shop and creating the Item() objects. Constructor: def __init__ ( self ): self .items = [] f = open ( "items.csv" ) fReader = csv.reader(f) for line in fReader: if line == []: continue self .items.append(Item(line[ 2 ] , line[ 0 ] , int (line[ 1 ]) , int (line[ 3 ]))) f.close() When the class is called the class list items are filled with Item() objects created by opening items.csv and taking the data in there to instantiate the items. Then we close the file. WhoIsShopping(): def whoIsShopping ( self , squad : list ): counter = 0 choices = [] print ( "Who is shopping?" ) for member in squad: if member.level > 0 : print ( str (counter) + ": " + member.displayName) choices.append(counter) counter += 1 selection = inputAndCheck( "Selection: " , choices) return squad[selection] T...

Explorer() progress

I decided to start with the explorer() method because of how central it is to the program. I quickly realized I'd need new functions for accessing specific pieces of data from the CVSs, so I made a few for detecting what region the part is in, another for fetching the region name and fetching the region z coordinate. Here is what explorer looks like now. def explorer (): global x global y global z global chapter global region global regionDisplay global Lori global Lauren global Julius global Marcus menu = GameMenu() characters = [Lori , Lauren , Julius , Marcus] menu.update(characters) selections = [ 4 , 5 ] #Code goes here print (regionDisplay + ":" ) print (regionDiscribe(region)) # need and area scanner for detecting nearby locations if regionCheck(x+ 1 , y , z) >= 0 and \ (fetchRegionZ(regionCheck(x+ 1 , y , z))-fetchRegionZ(region) <= 5 and fetchRegionZ(region)-fetchRegionZ(regionCheck...

Flow Charts are Born

Flow charts weren't that difficult to make. I honestly already had a decent idea of how my program would run, so this was really taking what was on my mind and putting it into a graphic. For those who don't know, I'm using a common key for software design for all of the flow charts: Source:  https://www.zenflowchart.com/flowchart-symbols First I have the simplest of my flow charts: theInstaller.py Flow chart. Then I made the Flow chart for theMain.py: Finally, I decided to include 2 flow charts for the important subprocess in the game: Explore() and runCombat(). For all of these, I used color codes to help subdivide the pieces of the code into their smaller loops or different paths. I'll be using these flow charts a lot to point out where exactly I'm at in the game as I go along with this blog.