IN3D / Pokemon

Recreation of pokemon, in C#.
0 stars 0 forks source link

Create base classes for items #3

Closed IN3D closed 10 years ago

IN3D commented 10 years ago

Begin creating the base classes for items, potions, status healing items, and battle items (xAttack, xDefense, etc.)

BradMackey commented 10 years ago

Just thinking the other day, to separate the xAttacks and xDefenses should that be two different classes formed off the base, or is there a way to use the battleItems Class but separate the outcome of the two ex: battleItem01 (xAttack) puts out "Pokemon's attack was raised by 2" and then have battleItem03 (xDefense) put out "Pokemon's defense was raised by 2". I was thinking a possible If Else but I wasn't sure if that would work/tried to use it and failed.

IN3D commented 10 years ago

Potions/battle items/etc are all going to have a stat that they effect. which would be an integer value (the index of the stat in the stats array). However, all of the x items only last the duration of the battle. Considering that there isn't any battle functionality in place yet, it would be silly to try and implement them so early.

There's nothing wrong with putting in a // TODO: comment explaining what needs to be done when there isn't an implementation for what you need to do (you can look through the Pokemon.cs file and see I've left quite a few of them). For items like potions however, I would suggest something like...

public class Potion : ItemBase
{
    string Name { get; set; }
    int TargetStat { get; set; }
    int Power { get; set; }

    // Constructor
    public Potion(string name, int targetStat, int power)
    {
        this.Name = name;
        this.TargetStat = targetStat;
        this.Power = power;
    }

    // Methods
    public void use(Pokemon target)
    {
        if ((target.stats[TargetStat] + value) > target.MaxHP)
        {
            target.stats[TargetStat] = target.MaxHP;
        }
        else
        {
            target.stats[TargetStat] += value;
        }
    }
}

public class BattleItems : ItemBase
{
    string Name { get; set; }
    int TargetStat { get; set; }
    int Power { get; set; }

    // Constructor
    public BattleItem(string name, int targetStat, int power)
    {
        this.Name = name;
        this.TargetStat = targetStat;
        this.Power = power;
    }

    // Methods
    public void use(Pokemon target)
    {
        // NOTE: battles not implemented, what follows is pseudo code
        // TODO: modify when pokemon battles are implemented.

        battle.modfiers[TargetStat] *= value;
    }
}

it's kind of pseudo code, but you can see how the same values are used across classes. If you wanted to implement a test for the battle items, so that you don't write a class for each stat you could do...

public void debugItemInfo(Pokemon target)
{
    Console.WriteLine(target.Name + "'s " + target.stats[TargetStat].Name + "was increased by an multiplier of " + value + "!");
}

While I don't currently have names matching up with the stats, down the line that would work, in it's place you could just do if...else if statements. like

if(TargetStat == 0)
{
    Console.WriteLine("WHAT HAVE YOU DONE?! There is no xHP!?");
}
else if(TargetStat == 1)
{
    Console.WriteLine(target.Name + "'s Attack was raised by a multiplier of " + value + "!");
}
// and so on...
// finally, remember to wrap up ever if with an else
else
{
    // just in case, to catch errors.
    Console.WriteLine("Something went very wrong, could not parse TargetStat correctly");
}

Let me know if there's anything else and I'll be happy to help.