Problems left in the previous section:
In the previous section: Silverlight + WCF network chess ultimate solves repeated message prompts (8), we solve repeated messages generated during repeated login.
However, this optimization produces another problem: there is only one instance in the world, and the status needs to be reset when switching the room back and forth or in and out. We will solve this problem in this section.
In the previous section, I left several lines of such annotation code:
// LoginObj. Reset ();
// RoomObj. Reset ();
// IndexObj. Reset ();
This section describes how to implement these three registration methods:
1: implement the loginObje. Reset () method and enter Login. xaml. cs:
Public void Reset ()
{
BtnLogin. IsEnabled = true;
}
In just one line, reset the unavailable button to available.
2: implement the roomObj. Reset () method and go to Room. xaml. cs:
Public void Reset ()
{
Game. Reset ();
App. client. GetRoomListAsync ();
}
The code is concise. The first line is to reset the status of the game room to the initial status, and then retrieve the status of the room again.
Code Decomposition: game. Reset () method. We will add the Reset method to Game. cs to implement the following:
Public void Reset ()
{
If (GameRoomList = null)
{
CreateGameRoom (20 );
}
Foreach (gamoom item in GameRoomList)
{
If (item. BlackPlayer! = Null | item. RedPlayer! = Null)
{
Item. BlackPlayer = null;
Item. RedPlayer = null;
Item. IsGaming = false;
Item. ReDraw ();
}
}
}
Reset each room to its initial state.
3: implement the indexObj. Reset () method. Go to Index. xaml. cs:
Public void Reset ()
{
ChessControl. Reset ();
OnlineUserControl. Reset ();
ChessManualControl. Reset ();
EventButtonControl. Reset ();
ChatControl. Reset ();
}
The code here is relatively simple, but there will be more to do next. Every control needs to be implemented, and it will become physical.
The following describes how to reset the status of each control:
A: Reset the chessboard and pawns: chessControl. Reset ();
Public void Reset ()
{
Chess. Reset (); // This has been implemented.
}
Therefore, the internal call is like a reset of the chess class, which is divided:
B: Reset of Online room users: onlineUserControl. Reset ();
Public void Reset ()
{
App. client. GetPlayerListAsync (App. player. RoomID );
}
You can obtain the user again.
C: Reset the score: chessManualControl. Reset ();
Public void Reset ()
{
Timer. Stop ();
MoveStepIndex = 0;
TempIsCanMove = false;
App. chessManualPlaying = false;
App. stepList. Clear ();
LbChessManual. Items. Clear ();
}
D: Reset of online chat: chatControl. Reset ();
Public void Reset ()
{
LbMsg. Items. Clear ();
}
4: Go back and enable the Codes commented out by the three lines.
OK, everything is ready. Check the effect at the end of the operation. The running status is good. Cut a few pictures:
A: Login
B: enter the room.
C: exit the system.
D: Log On again with another name.
E: enter the room page after re-Login
OK. This section will introduce you here.