oop - c# object function calling -


so starting learn c# , running problems... trying create bestiary console rpg game, , have ran wall. in monsters class, have class constructor monster objects, , have function print out data in bestiary style.

public void mprint()        {            console.writeline(name);            console.writeline("class: " + mclass);            console.writeline("hp: " + healthmax);            console.writeline("atk: " + atk);            console.writeline("exp drop: " + expdrop);            console.writeline("description: ");            console.writeline(description);        } 

then have void asking imput , uses switch statement put down chain , desired entry:

 switch (monsterchoice)            {                case 1:                    rat.mprint();                    break;                default:                    console.writeline();                    console.writeline("make sure using number next name of monster choose.");                    console.readkey();                    bestiarybeast();                    break;            }        } 

eventually chain has rat print function. question define rat rat.mprint work here. appreciated.

early days... takes me back.

assuming in console application

class program {     static void main()     {         monster rat = new monster("a", "b");         list<monster> monsters = new list<monster> { rat };         foreach (var monster in monsters)         {             monster.mprint();         }     } } 

this create rat object , populate it. add monsters list , print out monsters.

good luck


Comments

Popular posts from this blog

html - Outlook 2010 Anchor (url/address/link) -

javascript - Why does running this loop 9 times take 100x longer than running it 8 times? -

Getting gateway time-out Rails app with Nginx + Puma running on Digital Ocean -