Skip to content

A sample Server/Client game writen with C#. This application uses a custom message protocol on TCPClient & TCPListener with asynchronous

Notifications You must be signed in to change notification settings

omansak/playhub

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Playhub

A sample Server/Client game writen with C#. This application uses a custom message protocol on TCPClient & TCPListener with asynchronous

Features

  • Create/Join Lobby
  • Async TcpClient/TcpListener
  • Windows Form Application
  • ObservableCollection & EventHandler
  • JsonConvert
  • Generate Shapes

Build Setup

Prerequisites

  • Newtonsoft.Json

Building in Visual Studio

  1. Download and install the latest version of Visual Studio.
  2. In Project Folder. open "Playhub.sln"
  3. Browse to the location of the project, and double-click on the project directory.
  4. Click the green start button (or 'F5') to run the project!

Dependencies

  • Newtonsoft.Json
  • System.*
  • System.Net.Http

Protocol Formats

*All request and responses convert to JSON before to send.
JsonConvert.SerializeObject(*request or response object)

Client Requests

*Request join to lobby

   new ProtocolModel.Base
                {
                    DateTime = DateTime.Now,
                    Type = ProtocolModel.MessageType.RequestJoin,
                    Data = new ProtocolModel.Player
                    {
                        Name = playerName,
                        Point = 0
                    }
                }

*Send message to lobby

new ProtocolModel.Base
            {
                DateTime = DateTime.Now,
                Type = ProtocolModel.MessageType.LobbyMessage,
                Data = new ProtocolModel.LobbyMessage()
                {
                    Player = "*userName",
                    Message = "*message"
                }
            }

*Request game settings

new ProtocolModel.Base
            {
                DateTime = DateTime.Now,
                Type = ProtocolModel.MessageType.RequestGameSettings,
                Data = ""
            }

*Start game (can only hosts)

new ProtocolModel.Base
            {
                DateTime = DateTime.Now,
                Type = ProtocolModel.MessageType.RequestStart,
                Data = ""
            }

*Send to clicked coordinants

new ProtocolModel.Base
            {
                DateTime = DateTime.Now,
                Type = ProtocolModel.MessageType.RequestSendCoor,
                Data = new ProtocolModel.ClickCoor
                {
                    Coor = new Point(*x, *y)
                }
            }

Server Responses

*Broadcast Players in Lobby

new ProtocolModel.Base
            {
                Type = ProtocolModel.MessageType.ResponsePlayers,
                DateTime = DateTime.Now,
                Data = new ProtocolModel.PlayerList
                {
                    Players = *ObservableCollection<ProtocolModel.Player>
                }
            }

*Broadcast Shapes

new ProtocolModel.Base
                {
                    Type = ProtocolModel.MessageType.ResponseShapes,
                    DateTime = DateTime.Now,
                    Data = *ObservableCollection<Shapes>
                }

*Broadcast Message

new ProtocolModel.Base
            {
                DateTime = DateTime.Now,
                Type = ProtocolModel.MessageType.LobbyMessage,
                Data = new ProtocolModel.LobbyMessage()
                {
                    Message = "message"
                }
            }

*Broadcast Settings

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)
                     }

                 }

In-App Images

Home Game Panel

About

A sample Server/Client game writen with C#. This application uses a custom message protocol on TCPClient & TCPListener with asynchronous

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages