Exemplo n.º 1
0
 private static void RelayChatToAllClients(Client client, ChatMessage chatMessage)
 {
     var text = new ChatMessage { Text = client.PlayerName + ": " + chatMessage.Text };
     Console.WriteLine(text.Text);
     foreach (var other in server.clients)
         if (other != client)
             other.Send(text);
 }
Exemplo n.º 2
0
 private static void MessageReceived(Client client, Message message)
 {
     if (message is ChatMessage)
         RelayChatToAllClients(client, message as ChatMessage);
     else if (message is PlayCardMessage)
         HandlePlayCard(client, message as PlayCardMessage);
     else if (message is PlayerNameMessage)
         HandlePlayerName(client, message as PlayerNameMessage);
 }
Exemplo n.º 3
0
 private void ListenForClients()
 {
     while (true)
     {
         var client = new Client(listener.AcceptTcpClient());
         clients.Add(client);
         if (ClientConnected != null)
             ClientConnected(client.EndPoint);
         client.Disconnected += () =>
         {
             if (ClientDisconnected != null)
                 ClientDisconnected(client.EndPoint);
         };
         client.Received += message => ClientMessageReceived(client, message);
     }
 }
Exemplo n.º 4
0
 private static void HandlePlayCard(Client client, PlayCardMessage playCardMessage)
 {
     client.Points += playCardMessage.CardValue;
     foreach (var player in server.clients)
         if (player.Points == 0)
             return;
     Client playerWithHighestPoints = null;
     foreach (var player in server.clients)
         if (playerWithHighestPoints == null || playerWithHighestPoints.Points < player.Points)
             playerWithHighestPoints = player;
     if (playerWithHighestPoints.Points < 100)
         return;
     Console.Write("Game over, player " + playerWithHighestPoints.PlayerName + " has won with " + playerWithHighestPoints.Points);
     foreach (var player in server.clients)
         player.Send(new GameOverMessage
         {
             Winner = playerWithHighestPoints.PlayerName,
             Points = playerWithHighestPoints.Points
         });
 }
Exemplo n.º 5
0
 static void Main()
 {
     server = new Client("localhost");
     server.Received += ServerMessageReceived;
     GraphicsAPI = API.OpenGL;
     Init();
     //graphics.Init3D();
     CreateSprites();
     while (true)
     {
         Application.DoEvents();
         if (form.IsDisposed)
             break;
         graphics.Render();
         //graphics.Draw3DCube();
         HandleInput();
         DrawSprites();
         graphics.Present();
         if (title != null)
             form.Text = title;
         title = null;
     }
     graphics.Dispose();
 }
Exemplo n.º 6
0
 private static void HandlePlayerName(Client client, PlayerNameMessage playerNameMessage)
 {
     client.PlayerName = playerNameMessage.PlayerName;
 }
Exemplo n.º 7
0
 private static void PaddlePositionMessageReceived(Client client, Message message)
 {
     var paddleMessage = (PaddleMessage) message;
     client.PaddleY = paddleMessage.Y;
     foreach (var other in server.clients)
         if (other != client)
             other.Send(message);
 }