I'm currently learning C# and I was asked to make a game like monopoly on C and another version on C#. But there's some stuff I don't really understand on C# mainly because it's an object oriented language. So the question is, to manage the players I created a struct on the C version.
typedef struct regist
{
int number;
char name[50];
int money;
int position;
int inGame;
} Player;
Player players[8];
and to get any data of the struct I just do:
players[5].name = "Joe";
Now, my problem with C# is I managed to create the "struct". First I created a struct. Then I tried to make it with a list of structs. Then I just decided to make new instances of a class for every player. I was told it was the best way so I did it. So I have on my player class:
public class Players
{
int number;
string name;
int money;
int position;
bool inGame;
}
and on my form1:
private void newGameButton_Click(object sender, EventArgs e) { setNames(); getNames(); }
public void setNames()
{
Players player1 = new Players();
player1.name= textBox1.Text;
Players player2 = new Players();
player2.name = textBox2.Text;
Players player3 = new Players();
player3.name = textBox3.Text;
Players player4 = new Players();
player4.name = textBox4.Text;
}
now what I don't know how to do is:
public string getNames(){
return Players[2].name;
}
How can I achieve this? I also tried with lists but it wouldn't let me do it the way I wanted and also, I want to be able to use this same instances in others classes, I hope that is possible... Thank you.