Esempio n. 1
0
 public void HandleMessage(TyperGamePlayer player, GameMessage message)
 {
     if (message.Type == GameMessageType.Action)
     {
         if (this.IsStarted)
         {
             var goalChar   = this.GoalString[player.Score];
             var playerChar = ((string)message.Content)[0];
             if (goalChar == playerChar)
             {
                 player.Score++;
                 var messageContent = new { PlayerID = player.ID, Score = player.Score };
                 this.SendMessageToAll(new GameMessage {
                     Type = "PLAYER_SUCCESS", Content = messageContent
                 });
                 if (player.Score == this.GoalString.Length)
                 {
                     this.SendMessageToAll(new GameMessage {
                         Type = "PLAYER_WON", Content = player.ID
                     });
                     this.End();
                 }
             }
             else
             {
                 Console.WriteLine($"Wrong char! Expected {goalChar}, got {playerChar}");
             }
         }
     }
 }
Esempio n. 2
0
        public override Player AddPlayer(WebSocket socket, string id)
        {
            var player = new TyperGamePlayer(socket, id);

            this.Players.Add(player);
            player.Game = this;
            return(player);
        }
Esempio n. 3
0
        public TyperGameState GetClientState(TyperGamePlayer player)
        {
            var playerList = new List <TyperGamePlayerClient>();

            foreach (TyperGamePlayer p in this.Players)
            {
                playerList.Add(p.GetClientRepresentation());
            }
            var state = new TyperGameState
            {
                GoalString = this.GoalString,
                Players    = playerList
            };

            return(state);
        }