예제 #1
0
 // The maze is provided by the constructor, and the game holds a reference to the players
 // In a dictionary
 public MultiplayerMazeGame(SearchableMaze maze)
 {
     this.maze         = maze;
     this.name         = maze.name;
     joinable          = true;
     players           = new Dictionary <string, Position>();
     playerConnections = new Dictionary <TcpClient, StreamWriter>();
 }
예제 #2
0
        /*
         * StartGame creates a new multiplayer game, generating the maze and registering
         * the client to the game
         */
        public void StartGame(string name, int rows, int cols, string user)
        {
            Maze baseMaze = mazeMaker.Generate(rows, cols);

            baseMaze.Name = name;
            SearchableMaze      maze    = new SearchableMaze(baseMaze, baseMaze.Name);
            MultiplayerMazeGame oneGame = new MultiplayerMazeGame(maze);

            oneGame.SendMessageEvent += UpdateClientEvent;

            // We add the player to the game we just created
            oneGame.AddPlayer(user);
            // We place the maze into our database
            multiplayerMazes[name] = oneGame;

            playerToGameMap[user] = oneGame;
        }
예제 #3
0
        /*
         * The generate command creates a single player maze, which is added to the database
         * and then returned to the user
         */
        public SearchableMaze GenerateMaze(string name, int rows, int cols)
        {
            Maze           m    = mazeMaker.Generate(rows, cols);
            SearchableMaze maze = new SearchableMaze(m, name);

            // The maze is saved in the database
            if (!singlePlayerMazes.ContainsKey(name))
            {
                singlePlayerMazes.Add(name, maze);
            }
            else
            {
                singlePlayerMazes[name] = maze;
                if (singlePlayerSolutions.ContainsKey(name))
                {
                    singlePlayerSolutions.Remove(name);
                }
            }
            return(maze);
        }