Exemplo n.º 1
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);
            }
        }
Exemplo n.º 2
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);
            }
        }
Exemplo n.º 3
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);
            }
        }