Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <blockquote> <p>Ideally, <code>AngryFarmer</code>, <code>Ugly_Spider</code> and <code>Gollum</code> should all inherit from <code>Monster</code></p> </blockquote> <p>I have learn your problem like the problem in the Tetris game: 1/ You have Monsters like I have Shapes. 2/ Each kind of Monster have it own properties (Health, Magic Point,...) and behaviours (attack, run, cast spell,..) like the Blocks have properties (color, position, state,..) and behaviours (go down, rotate right, rotate left,...)</p> <p>In the scene of the game you want to random a Monster that have the specific properties and behaviours, like I want to random a Shape. If it is your problem you can try my code:</p> <pre><code>public abstract class CMonster { int _HP; int _MP; //..and something like this public int HP { get { return this._HP; } set { this._HP=value;} } public int MP { get { return this._MP; } set { this._MP = value; } } public abstract void Run(); public abstract void Attach(); public abstract void CastSpell(); } public class CUgly_Spider : CMonster { public CUgly_Spider() { this.MP = 100;//your value here this.HP = 100;//your value here } public override void Attach() { //your implemetation here } public override void Run() { //your implemetation here } public override void CastSpell() { //your implemetation here } } public class CGollum : CMonster { public CGollum() { this.MP = 100;//your value here this.HP = 100;//your value here } public override void Attach() { //your implemetation here } public override void Run() { //your implemetation here } public override void CastSpell() { //your implemetation here } } class Test { private void InitTheGame() { CMonster curMonster=null; Random rnd = new Random(); //sample random if ((rnd.Next() % 2) == 0) { curMonster = new CGollum(); } else { curMonster = new CUgly_Spider(); } curMonster.Run();//when (rnd.Next() % 2) == 0 then the Gollum is doing else the Ugly_Spider curMonster.Attach();//when (rnd.Next() % 2) == 0 then the Gollum is doing else the Ugly_Spider curMonster.CastSpell();//when (rnd.Next() % 2) == 0 then the Gollum is doing else the Ugly_Spider } } </code></pre> <p>I hope that can help you.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload