A sample Server/Client game writen with C#. This application uses a custom message protocol on TCPClient & TCPListener with asynchronous
- Create/Join Lobby
- Async TcpClient/TcpListener
- Windows Form Application
- ObservableCollection & EventHandler
- JsonConvert
- Generate Shapes
- Newtonsoft.Json
- Download and install the latest version of Visual Studio.
- In Project Folder. open "Playhub.sln"
- Browse to the location of the project, and double-click on the project directory.
- Click the green start button (or 'F5') to run the project!
- Newtonsoft.Json
- System.*
- System.Net.Http
*All request and responses convert to JSON before to send.
JsonConvert.SerializeObject(*request or response object)
new ProtocolModel.Base
{
DateTime = DateTime.Now,
Type = ProtocolModel.MessageType.RequestJoin,
Data = new ProtocolModel.Player
{
Name = playerName,
Point = 0
}
}
new ProtocolModel.Base
{
DateTime = DateTime.Now,
Type = ProtocolModel.MessageType.LobbyMessage,
Data = new ProtocolModel.LobbyMessage()
{
Player = "*userName",
Message = "*message"
}
}
new ProtocolModel.Base
{
DateTime = DateTime.Now,
Type = ProtocolModel.MessageType.RequestGameSettings,
Data = ""
}
new ProtocolModel.Base
{
DateTime = DateTime.Now,
Type = ProtocolModel.MessageType.RequestStart,
Data = ""
}
new ProtocolModel.Base
{
DateTime = DateTime.Now,
Type = ProtocolModel.MessageType.RequestSendCoor,
Data = new ProtocolModel.ClickCoor
{
Coor = new Point(*x, *y)
}
}
new ProtocolModel.Base
{
Type = ProtocolModel.MessageType.ResponsePlayers,
DateTime = DateTime.Now,
Data = new ProtocolModel.PlayerList
{
Players = *ObservableCollection<ProtocolModel.Player>
}
}
new ProtocolModel.Base
{
Type = ProtocolModel.MessageType.ResponseShapes,
DateTime = DateTime.Now,
Data = *ObservableCollection<Shapes>
}
new ProtocolModel.Base
{
DateTime = DateTime.Now,
Type = ProtocolModel.MessageType.LobbyMessage,
Data = new ProtocolModel.LobbyMessage()
{
Message = "message"
}
}
new ProtocolModel.Base
{
Type = ProtocolModel.MessageType.RequestGameSettings,
Data = new ProtocolModel.GameSetting
{
GameName = GameName,
Red = GameShapeRed.ToString(),
Blue = GameShapeBlue.ToString(),
Yellow = GameShapeYellow.ToString(),
Timer = GameRefreshTime.ToString(),
Win = GameWinPoint.ToString(),
PanelSize = new Point(GamePanelSizeX, GamePanelSizeY)
}
}