/// <summary> /// Execution requests from model to add this client to a /// given game, with the name args[0], and returns the maze /// to both of the players /// </summary> /// <param name="args"> name of maze to join </param> /// <param name="client"> client who wants to join the game </param> /// <returns> returns the result of the execution </returns> public string Execute(string[] args, TcpClient client = null) { //args[0] is name of game to join //Returns the game that this player joined MazeGame game = model.AddPlayer(args[0], client); game.IsFull = true; List <TcpClient> Players = game.Players; foreach (TcpClient P in Players) { NetworkStream stream = P.GetStream(); StreamWriter writer = new StreamWriter(stream); writer.WriteLine(game.Maze.ToJSON()); // writer.WriteLine("#"); writer.Flush(); } return("DO NOT CLOSE"); }
/// <summary> /// Method to generate a maze and add it to a dictionary /// </summary> /// <param name="name"> name of the new maze to generate </param> /// <param name="row"> number of rows </param> /// <param name="col"> number of columns </param> /// <param name="player"> client that wants to create the maze </param> /// <param name="gameType"> single or multi-player maze </param> /// <returns> Returns the new maze </returns> public Maze GenerateMaze(string name, int row, int col, TcpClient player, string gameType) { //Creates the maze Maze newMaze = new MazeGeneratorLib.DFSMazeGenerator().Generate(row, col); newMaze.Name = name; //Adds the current client as player1 to this game MazeGame newGame = new MazeGame(newMaze); if (gameType == "Single") { Console.WriteLine("Single-Player Game '{0}' Added", name); singlePlayerGames.Add(name, newGame); } else //Multi Player { Console.WriteLine("Multi-Player Game '{0}' Added", name); newGame.AddPlayer(player); multiPlayerGames.Add(name, newGame); Console.WriteLine(multiPlayerGames[name].Maze.Name); } return(newMaze); }