私は最初のサーバー クライアント アプリケーションを作成しているので、あなたの助けが必要です。
クライアントは、いくつかのゲームをプレイできるようになった後、自分自身を認証する必要があります。
したがって、USER クラスと PLAYER クラスがあります。USER は登録されているすべてのユーザーを包括し、PLAYER はゲームをプレイするユーザーを包括します (PLAYER_GAME1、PLAYER_GAME2 などがあります)。
USERの内部には、名前、姓、IDなど
のプロパティがあります.PLAYERの内部には、ユーザーのプロパティとポイント、ゲーム内の時間などが必要です.
実際:
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*
}
}
名前を取得するには、次のことを行う必要があります。
PLAYER p= new PLAYER(new USER(...));
string name=p.user.name;
私はよりスマートに USER の PLAYER サブクラスを作成すると思います。ユーザーがゲームをプレイしたい場合は、クラスのユーザーをプレーヤーのプロパティで「拡張」する必要があるので、次のようにします。
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*
}
}
名前を取得するには、次のようにします。
PLAYER p= new PLAYER();
p=exixtingUser;
string name=p.name;
SUBCLASS=MAINCLASS が不可能であることはわかっています。