Answer the question
In order to leave comments, you need to log in
How to create a custom data type?
How to create your own data type?
The Equipment class, which describes the properties of the weapon (int damage, string name and its methods). How to write an array of instances of this class to the database? I used json:
{
"player": [
[
{
"name": "sword",
"attack_bonus": 2,
"defence_bonus": 0,
"cost": 10
},
{
"name": "tornado",
"attack_bonus": 5,
"defence_bonus": 0,
"cost": 25
}
]
}
public class Equipment
{
public string name;
public int attack_bonus;
public int defence_bonus;
public int cost;
public Equipment(string name, int attack_bonus, int defence_bonus, int cost)
{
this.name = name;
this.attack_bonus = attack_bonus;
this.defence_bonus = defence_bonus;
this.cost = cost;
}
public int get_attack_bonus()
{
return this.attack_bonus;
}
public int get_defence_bonus()
{
return this.defence_bonus;
}
public int get_cost()
{
return this.cost;
}
public string get_name()
{
return this.name;
}
public string get_descr()
{
string descr = get_name() + " :";
if (get_attack_bonus() != 0)
{
descr += " attack +" + get_attack_bonus();
}
if (get_defence_bonus() != 0)
{
descr += " defence +" + get_defence_bonus();
}
descr += " cost $" + get_cost();
return descr;
}
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question