How should I structure the logic of an object oriented Role-playing game?
Please look at this method in my player class of my game:
public void eatSomethingt(Items eatable)
{
foreach (Items i in items )
{
if (i is Ieatable && i.name == eatable.name) //Give items an
ID in the future
{
Ieatable k = i as Ieatable;
k.eat(this);
items.Remove(i);
break;
}
}
}
Basically this will go through the list of items a player has and compare
them to check if the parameter being passed in is eatable, if it is, check
if the player have one. If it gets into the IF statement then the item
will be removed from the players back-pack(items)
The problem is with the line: k.eat(this) It is sent to this method:
public void eat(Player p)
{
Console.WriteLine(p.Name + " Ate the " + name);
p.life = p.life + amountHealed;
}
This feels slightly 'ping-pong'ish as it's the Fruit class that feeds the
item to the player. As my Fruitclass implements the interface iEatable
(which surely makes sense to do) I have to place an eat method in the
classes that implement it.
No comments:
Post a Comment