예제 #1
0
        /// <summary>
        /// defines the execution of the command.
        /// </summary>
        /// <param name="args"> arguments for the command</param>
        /// <param name="clientInfo"> info of client the sent the command</param>
        public override void Execute(string[] args, ClientConnectionInfo clientInfo)
        {
            string name;

            try
            {
                name = args[0];
            }
            catch // in case there is overflow in the index in the array
            {
                JObject errorMessage = new JObject();
                errorMessage["Error"] = "missing arguments";
                controller.View.SendReply(errorMessage.ToString(), clientInfo);
                return;
            }
            if (!controller.MultiplePlayerMazes.ContainsKey(name))
            {
                JObject errorMessage = new JObject();
                errorMessage["Error"] = String.Format("game {0} doesn't exist", name);
                controller.View.SendReply(errorMessage.ToString(), clientInfo);
                return;
            }
            ClientConnectionInfo startedGameClient = controller.CreatedGamesPlayers[name];
            MazeGame             mazeGame          = new MazeGame(controller.MultiplePlayerMazes[name], startedGameClient, clientInfo, controller.View, controller.Model);

            controller.CreatedGamesPlayers.Remove(name);
            controller.PlayersGamesBelonging[startedGameClient] = mazeGame;
            controller.PlayersGamesBelonging[clientInfo]        = mazeGame;
        }
예제 #2
0
        /// <summary>
        /// Handles the game started.
        /// </summary>
        /// <param name="game">The game.</param>
        public void HandleGameStarted(MazeGame game)
        {
            string         json    = game.Maze.ToJSON();
            Notification   notif   = new Notification(Notification.Type.GameStarted, json);
            List <IClient> clients = game.GetAllClients();

            foreach (IClient client in clients)
            {
                notifier.NotifyClient(client, notif);
            }
        }
예제 #3
0
        /// <summary>
        /// Handles the player moved.
        /// </summary>
        /// <param name="game">The game.</param>
        /// <param name="player">The player.</param>
        /// <param name="d">The d.</param>
        public void HandlePlayerMoved(MazeGame game, IClient player, Direction d)
        {
            MoveUpdate     update  = new MoveUpdate(game.Name, d);
            Notification   notif   = new Notification(Notification.Type.PlayerMoved, update.ToJSON());
            List <IClient> clients = game.GetAllClients();

            foreach (IClient client in clients)
            {
                // do not notify the player which moved.
                if (client.Equals(player))
                {
                    continue;
                }

                //notify the client.
                notifier.NotifyClient(client, notif);
            }
        }
예제 #4
0
        /// <summary>
        /// Handles the game over.
        /// </summary>
        /// <param name="game">The game.</param>
        /// <param name="args">The <see cref="GameOverEventArgs"/>
        ///  instance containing the event data.</param>
        public void HandleGameOver(MazeGame game, GameOverEventArgs args)
        {
            List <IClient> clients = game.GetAllClients();

            foreach (IClient client in clients)
            {
                string message;
                if (args.Winner == null)
                {
                    message = "The game was closed by your opponents.";
                }
                else
                {
                    message = client.Equals(args.Winner) ? "You Win!" : "You Lost!";
                }
                Notification notif = new Notification(Notification.Type.GameOver, message);
                notifier.NotifyClient(client, notif);
            }
        }
예제 #5
0
        /// <summary>
        /// defines the execution of the command.
        /// </summary>
        /// <param name="args"> arguments for the command</param>
        /// <param name="clientInfo"> info of client the sent the command</param>
        public override void Execute(string[] args, ClientConnectionInfo clientInfo)
        {
            string name;

            try
            {
                name = args[0];
            }
            catch // in case there is overflow in the index in the array
            {
                JObject errorMessage = new JObject();
                errorMessage["Error"] = "missing arguments";
                controller.View.SendReply(errorMessage.ToString(), clientInfo);
                return;
            }
            MazeGame game = controller.PlayersGamesBelonging[clientInfo];

            game.NotifyGameFinish(clientInfo);
            controller.MultiplePlayerMazes.Remove(name);
            controller.PlayersGamesBelonging.Remove(game.Player1);
            controller.PlayersGamesBelonging.Remove(game.Player2);
        }