Example #1
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, TcpClient user)
        {
            Maze baseMaze = mazeMaker.Generate(rows, cols);

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

            // We add the player to the game we just created
            oneGame.AddPlayer(user);
            // We place the maze into our database
            if (!multiplayerMazes.ContainsKey(name))
            {
                multiplayerMazes.Add(name, oneGame);
            }
            else
            {
                multiplayerMazes[name] = oneGame;
            }

            if (!playerToGameMap.ContainsKey(user))
            {
                playerToGameMap.Add(user, oneGame);
            }
            else
            {
                playerToGameMap[user] = oneGame;
            }
        }
Example #2
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);
        }