generics - C# how to modify a List -


I am creating a console RPG and am quite new to generic. My problem is that I am the monster (enemy list general ), A hero (a hero's list stored in general) wants to attack. The issue I have is making the hero, my monster selects a goal from generic, then modifies the hpcurrent of the monster, it is easy with a monster and hero, but as I expanded the game , I intend to have many types of demons and heroes; That's why I want to use a piece of code for my hero who can pick one item from the normal one and modify the data. The reasons are two generics, because it makes it easy for me to see if all the heroes or monsters are dead.

I will post the code for the monster (it is similar to the hero, these numbers are only different):

  class orc: characters {public orc () {this. Hpcurrent = 12; This.hpmax = 12; This.mpcurrent = 0; This.mpmax = 0; this. Strength = 6; This.defense = 4; This.magicstrength = 0; This.magicdefense = 2; this. Qualification = 4; This.level = 3; This.isaliveBool = True; This.name = "orc"; This.weakness1 = "fire"; This.weakness2 = "need"; This.battlemove = null; This.typeofcharacter = "monster"; }   

The code for the list of monsters is:

  public list & lt; Character & gt; Enemy () {List & lt; Character & gt; Enemy = new list & lt; Character & gt; (); Enemies.Clear (); enemy. Add (new oric) Enemy enemies; }    

You can use something like this: < Pre> public list & lt; Character & gt; Enemy (if _Enemies == faucet) {_Enemies = New list & lt; character & gt; (); _Enemies.Clear (); _Enemies.Add (New Orc ());} Return _Enemies;} Private list & lt; Character & gt; _Enemies;

Then you can use it:

  obj.Enemies [0] .hp + = 25;    

Comments

Popular posts from this blog

mysql - BLOB/TEXT column 'value' used in key specification without a key length -

c# - Using Vici cool Storage with monodroid -

python - referencing a variable in another function? -