Disclaimer: This article is a blogger original article, follow the CC 4.0 BY-SA copyright agreement, reproduced, please attach the original source link and this statement.
Grasshoppers - end game # 1 [Difficulty: 0]:
Answer 1:
class Hero {
public string Name {get; set;}
public float Health {get; set;} = 100;
public float Damage {get; set;} = 5;
public int Experience {get; set;} = 0;
public string Position {get; set;} = "00";
public Hero(string name = "Hero") {
this.Name = name;
}
}
Answer 2:
public class Hero
{
public string Name { get; }
public string Position { get; } = "00";
public float Health { get; } = 100;
public float Damage { get; } = 5;
public int Experience { get; } = 0;
public Hero(string name = "Hero")
{
Name = name;
}
}
Answer 3:
public class Hero
{
public string Name { get; }
public string Position { get; }
public float Health { get; }
public float Damage { get; }
public int Experience { get; }
public Hero(string name = "Hero")
{
this.Name = name;
this.Position = "00";
this.Health = 100.0f;
this.Damage = 5.0f;
this.Experience = 0;
}
}
Answer 4:
public class Hero
{
public string Name;
public string Position;
public float Health;
public float Damage;
public int Experience;
public Hero(string name = "Hero", string pos = "00", float hlt = 100, float dam = 5, int exp = 0)
{
Name = name;
Position = pos;
Health = hlt;
Damage = dam;
Experience = exp;
}
}
Answer 5:
class Hero
{
public string Name;
public Hero(string name = "Hero")
{
this.Name = name;
}
//public string Name { get; set; } = "Hero";
public string Position { get; set; } = "00";
public float Health { get; set; } = 100;
public float Damage { get; set; } = 5;
public int Experience { get; set; } = 0;
}
A6:
public class Hero
{
public string Name;
public string Position;
public float Health;
public float Damage;
public int Experience;
public Hero()
{
Name = "Hero";
Position = "00";
Health = 100;
Damage = 5;
Experience = 0;
}
public Hero(string name)
{
Name = name;
}
}
A7:
public class Hero
{
public string Name, Position = "00";
public float Health = 100, Damage = 5;
public int Experience = 0;
public Hero(string s = "Hero")
{
Name = s;
}
}
A8:
public class Hero {
public string Name { get; private set; }
public string Position { get; private set; }
public float Health { get; private set; }
public float Damage { get; private set; }
public int Experience { get; private set; }
public Hero( string name = "Hero" ) {
Name = name;
Position = "00";
Health = 100;
Damage = 5;
Experience = 0;
}
}
A9:
// It's dangerous to go alone... create a Hero class to accompany you on your quest!
public class Hero{
public string Name;
public string Position;
public float Health;
public float Damage;
public int Experience;
public Hero(){
this.Name = "Hero";
this.Position = "00";
this.Health = 100;
this.Damage = 5;
this.Experience = 0;
}
public Hero(string name){
this.Name = name;
this.Position = "00";
this.Health = 100;
this.Damage = 5;
this.Experience = 0;
}
}
Answers 10:
public class Hero
{
public string Name;
public string Position = "00";
public float Health = 100;
public float Damage = 5;
public int Experience = 0;
public Hero(string name = "Hero")
=> this.Name = name;
}