I'm making the first server-client application and i need your help.
The client must autenticate itself and after it can play some games.
So I've got USER and PLAYER classes: USER comprends all user registered and PLAYER comprends user that play game (there are PLAYER_GAME1,PLAYER_GAME2, etc..).
Inside USER i've proprieties like name, surname, id and etc.
Inside PLAYER i need have the proprieties of the user plus point, time in game, etc.
Actually:
public class USER
{
public string name, surname, ID, password, IP;
WALLET wallet;
bool login;
datetime lastAccess;
TcpClient socket;
Thread receiveMessages;//this receive message for log-in
...*other 30 proprieties*
public USER(string n,string s,string _id,string pw)
{
*inizialize all variables*
}
}
public class PLAYER
{
public USER user;
Thread receiveMessages;
int points;
bool online;
...*other proprieties*
public PLAYER(USER u)
{
user=u;
*inizialize all variables*
}
}
so for getting name i have to do:
PLAYER p= new PLAYER(new USER(...));
string name=p.user.name;
I think is more smart make PLAYER subclass of USER and when user want play games i "expand" the class user with the proprieties of player so i need do :
public class USER
{
protected string name, surname, ID, password, IP;
WALLET wallet;
bool login;
datetime lastAccess;
TcpClient socket;
Thread receiveMessages;//this receive message for meneage the game
...*other 30 proprieties*
public USER(string n,string s,string _id,string pw)
{
*inizialize all variables*
}
}
public class PLAYER : USER
{
Thread receiveMessages;
...*other proprieties*
public PLAYER():base()// here, what could i do?
{
*inizialize all PLAYER variables*
}
}
so for getting name i would do:
PLAYER p= new PLAYER();
p=exixtingUser;
string name=p.name;
I know that SUBCLASS=MAINCLASS is impossible so how could i do it?