Exemple #1
0
        /// <summary>
        /// in charge of sending the clients message about a movement in the game.
        /// </summary>
        /// <param name="move">the move</param>
        /// <param name="clientInfo">the client info who moved</param>
        public void NotifyOfMove(string move, ClientConnectionInfo clientInfo)
        {
            Array directions = Enum.GetValues(typeof(Direction));
            int   i;

            for (i = 0; i < directions.Length; i++)
            {
                if (directions.GetValue(i).ToString().Equals(move))
                {
                    break;
                }
            }
            if (i == 4) // there was not found appropriate value in the Direction enum
            {
                JObject errorMessage = new JObject();
                errorMessage["Error"] = "invalid direction key word";
                view.SendReply(errorMessage.ToString(), clientInfo);
                return;
            }

            JObject movement = new JObject();

            movement["Name"]      = maze.Name;
            movement["Direction"] = move;

            if (clientInfo.Equals(Player1))
            {
                view.SendReply(movement.ToString(), Player2);
            }
            else
            {
                view.SendReply(movement.ToString(), Player1);
            }
        }
Exemple #2
0
        /// <summary>
        /// in charge of sending the clients messages about the finish of the game.
        /// </summary>
        /// <param name="client">the reuqesting to close game client info</param>
        public void NotifyGameFinish(ClientConnectionInfo client)
        {
            JObject finishGame = new JObject();

            if (client.Equals(Player1))
            {
                view.SendReply(finishGame.ToString(), Player2);
            }
            else
            {
                view.SendReply(finishGame.ToString(), Player1);
            }

            Player1.ShouldKeepConnection = false;
            Player2.ShouldKeepConnection = false;
        }