Home > Back-end >  The realization of the function of network game, move later
The realization of the function of network game, move later

Time:10-07

Network go game software design, the now game on both sides of the client to achieve synchronous display move later information,
Go board for 20 * 20 two-dimensional arrays, single mouse can move later on board, now need to put the single mouse point, the information is passed to the server and then by the server to each client, the board move later code is as follows:
//-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --

Void __fastcall TfmMain: : imgChessboardMouseDown (TObject * Sender,
TMouseButton Button, TShiftState Shift, int X, int Y)
{
Int the Row, Col.

if(! GetPosition (X, Y)) return;
GetIndex (X, Y, the Row, Col);

If (gChessboard [Row] [Col]!=0)
return;//the current position for pieces
TryPlaceOneChess (Row, Col);
}
//-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --

Void TryPlaceOneChess (int Row, int Col)
{
//char Flag='B';
Int Result;
Char * pStr;

//Flag=(gStepCount % 2)? 'W', 'B'.
Result=DM - & gt; HandlePlacedChess (Row, Col, gStepCount);

//the return value 0: can not into the child; 1: no gas itself, but can kill each other pieces;
//2: itself alive and can kill each other pieces; 3: both sides no dead child
PStr=NULL;
If (Result==0) pStr="current location shall not enter into the son";
Else if (Result==4) pStr="killed, it is not the listing";

If (pStr!=NULL)
MessageBox (0, pStr, "", MB_OK | MB_TASKMODAL | MB_ICONSTOP);//do not accept this listing
The else PlaceOneChess (Row, Col, (the Result==3)? False: true);//effective listing, records information about
}
//-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
Server has been set up complete and chat function is implemented, the specific code is as follows:
//-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
Void SendNetInfo (TClientSocket * pSocket, String sInfo)
{
PSocket - & gt; The Socket - & gt; SendText (sInfo);
}
//-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --


Void __fastcall TfmMain: : Button2Click (TObject * Sender)
{
String sInfo;
SInfo=edName - & gt; The Text + ", said: "+ edTalk - & gt; The Text;
SendNetInfo (ClientSocket1, sInfo);
EdTalk - & gt; Text="";
}
//edName players name, edTalk is typing box

When the game both sides of the chat content is displayed in the chat window is designed so, so could you please tell me how to put every move piece table shows how to design in the board? The younger brother is a pure food, this is my graduation design, by myself is really not to come out, the best can you help me think about it, thanks!

CodePudding user response:

The array serialized store pieces of data transfer, the client according to the array to cloth, after receiving the message part you will have, passing serialized array method is the same

CodePudding user response:

Because of the following are likely to eat, so passing the entire array is good
  • Related