Exemplo n.º 1
0
        /// <summary>
        /// Starts the game.
        /// </summary>
        /// <param name="name">The name.</param>
        /// <param name="rows">The rows.</param>
        /// <param name="cols">The cols.</param>
        /// <param name="client">The client.</param>
        /// <returns></returns>
        public bool StartGame(string name, int rows, int cols, TcpClient client)
        {
            // if the game doesn't exist
            if (MultiplayerMazeList.ContainsKey(name))
            {
                return(true);
            }
            // generate
            DFSMazeGenerator dfsMazeGenerator = new DFSMazeGenerator();
            Maze             maze             = dfsMazeGenerator.Generate(rows, cols);

            maze.Name = name;

            // add to games
            MazeGame game = new MazeGame(maze);

            MultiplayerMazeList[name] = game;

            game.AddPlayer(client, name);

            if (MultiplayerMazeList.ContainsKey(name))
            {
                MultiplayerMazeList.Remove(name);
            }

            return(false);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Joins the game.
        /// </summary>
        /// <param name="name">The name.</param>
        /// <param name="client">The client.</param>
        /// <returns></returns>
        public string JoinGame(string name, TcpClient client)
        {
            if (!MultiplayerMazeList.ContainsKey(name))
            {
                return("invalid command");
            }
            MazeGame game = MultiplayerMazeList[name];

            game.AddPlayer(client, name);

            if (MultiplayerMazeList.ContainsKey(name))
            {
                MultiplayerMazeList.Remove(name);
            }

            return("");
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="GamePlayCommand"/> class.
 /// </summary>
 /// <param name="myGame">My game.</param>
 public GamePlayCommand(MazeGame myGame)
 {
     game = myGame;
 }
Exemplo n.º 4
0
 /// <summary>
 /// Initializes a new instance of the <see cref="GameListCommand"/> class.
 /// </summary>
 /// <param name="myGame">My game.</param>
 public GameListCommand(MazeGame myGame)
 {
     game = myGame;
 }
Exemplo n.º 5
0
 /// <summary>
 /// Initializes a new instance of the <see cref="GameCloseCommand"/> class.
 /// </summary>
 /// <param name="myGame">My game.</param>
 public GameCloseCommand(MazeGame myGame)
 {
     game = myGame;
 }