/// <summary> /// Initializes a new instance of the <see cref="Game"/> class. /// </summary> /// <param name="maze">The maze.</param> /// <param name="client">The client.</param> /// <exception cref="System.ArgumentNullException">maze</exception> public Game(SearchableMazeAdapter maze, string client) { if (maze == null) { throw new ArgumentNullException(nameof(maze)); } this.maze = maze; joinable = true; players = new List <string>(); players.Add(client); }
/// <summary> /// Starts the specified name. /// </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>SearchableMazeAdapter.</returns> public SearchableMazeAdapter Start(string name, int rows, int cols, string client) { //generate the maze SearchableMazeAdapter searchableMaze = GenerateMaze(name, rows, cols); Game game = new Game(searchableMaze, client); games.Add(name, game); //waiting for another player to connect. while (game.Joinable == true) { System.Threading.Thread.Sleep(50); } return(searchableMaze); }
/// <summary> /// Generates the maze. /// </summary> /// <param name="name">The name.</param> /// <param name="rows">The rows.</param> /// <param name="cols">The cols.</param> /// <returns>SearchableMazeAdapter.</returns> public SearchableMazeAdapter GenerateMaze(string name, int rows, int cols) { //if the maze is allready exist we return it. if (searchableMazes.ContainsKey(name)) { return(searchableMazes[name]); } DFSMazeGenerator mazeGenerator = new DFSMazeGenerator(); Maze maze = mazeGenerator.Generate(rows, cols); maze.Name = name; //adapt the maze. SearchableMazeAdapter searchableMaze = new SearchableMazeAdapter(maze); searchableMazes.Add(name, searchableMaze); return(searchableMaze); }