/// <summary> /// Checks the valid. /// </summary> /// <returns><c>true</c>, if valid was checked, <c>false</c> otherwise.</returns> /// <param name="args">Arguments.</param> /// <param name="client">Client.</param> public bool CheckValid(string[] args, TcpClient client) { if (args.Length > 2) { Controller.NestedErrors nested = new Controller.NestedErrors("Bad arguement", client); return(false); } try { string name = args[0]; int rows = int.Parse(args[1]); if (rows > 1 || rows < 0) { Controller.NestedErrors nested = new Controller.NestedErrors("Bad arguement", client); return(false); } else { return(true); } } catch (Exception) { Controller.NestedErrors nested = new Controller.NestedErrors("Bad arguement", client); return(false); } }
/// <summary> /// Execute the specified args and client. /// </summary> /// <returns>The execute.</returns> /// <param name="args">Arguments.</param> /// <param name="client">Client.</param> public string Execute(string[] args, TcpClient client) { if (!this.CheckValid(args, client)) { return("singlePlayer"); } model.GetmodelData().mutexGamePlaying.WaitOne(); model.GetmodelData().mutexGameWating.WaitOne(); string name = args[0]; int rows = int.Parse(args[1]); int cols = int.Parse(args[2]); // get the game from the model. GameMultiPlayer game = model.GenerateGame(name, rows, cols, client); model.GetmodelData().mutexGamePlaying.ReleaseMutex(); model.GetmodelData().mutexGameWating.ReleaseMutex(); if (game != null) { return("multiPlayer"); } else { Controller.NestedErrors nested = new Controller.NestedErrors("Error exist game", client); return("singlePlayer"); } }
public string Execute(string[] args, TcpClient client) { if (!CheckValid(args, client)) { return("multiPlayer"); } string direction = args[0]; // Get the game of the client who press play. GameMultiPlayer game = model.FindGameByClient(client); // Check the direction. if (!directions.Contains(direction)) { Controller.NestedErrors error = new Controller.NestedErrors("The dirction is incorrect", client); return("multiPlayer"); } // Check if the game exist. if (game != null) { NestedPlay nested = new NestedPlay(game.GetMaze().Name, direction); Controller.SendToClient(JsonConvert.SerializeObject(nested), game.OtherClient(client)); } else { // The game dosnt exits. Send message to the client. Controller.NestedErrors error = new Controller.NestedErrors("you need to start a game", client); } return("multiPlayer"); }
/// <summary> /// Close the multi players game. /// </summary> /// <param name="args">The arguments.</param> /// <param name="client">The client.</param> /// <returns> /// string: "singlePlayer" or "multiPlayer". /// </returns> public string Execute(string[] args, TcpClient client) { // Check the valid if the arguements. if (!this.CheckValid(args, client)) { return("multiPlayer"); } string name = args[0]; GameMultiPlayer game = model.FindGamePlaying(name); // Check if the game is in the list of games to play. if (game != null) { model.RemoveGamePlaying(name); Controller.SendToClient("close client do close", client); Controller.SendToClient("close the game by other client", game.OtherClient(client)); if (!model.ClientOnGame(game.OtherClient(client))) { Controller.SendToClient("singlePlayer", game.OtherClient(client)); } if (!model.ClientOnGame(client)) { return("singlePlayer"); } return("multiPlayer"); } else { Controller.NestedErrors nested = new Controller.NestedErrors("Error exist game", client); return("multiPlayer"); } }
/// <summary> /// Execute the specified args and client. /// </summary> /// <returns>The execute.</returns> /// <param name="args">Arguments.</param> /// <param name="client">Client.</param> public string Execute(string[] args, TcpClient client) { if (!this.CheckValid(args, client)) { return("singlePlayer"); } string name = args[0]; int rows = int.Parse(args[1]); int cols = int.Parse(args[2]); if (!model.ContainMaze(name)) { Maze maze = model.GenerateMaze(name, rows, cols); maze.Name = name; Controller.SendToClient(maze.ToJSON(), client); } else { Controller.NestedErrors nested = new Controller.NestedErrors("Maze exist", client); } if (model.ClientOnGame(client)) { return("multiPlayer"); } return("singlePlayer"); }
/// <summary> /// Checks the valid. /// </summary> /// <param name="args">The arguments.</param> /// <param name="client">The client.</param> /// <returns></returns> public bool CheckValid(string[] args, TcpClient client) { if (args.Length > 1 || args.Length < 1) { Controller.NestedErrors nested = new Controller.NestedErrors("Bad arguement", client); return(false); } return(true); }
/// <summary> /// Checks the valid. /// </summary> /// <param name="args">The arguments.</param> /// <param name="client">The client.</param> /// <returns></returns> public bool CheckValid(string[] args, TcpClient client) { if (args.Length > 1) { Controller.NestedErrors nested = new Controller.NestedErrors("Bad arguement", client); return(false); } try { string name = args[0]; return(true); } catch (Exception) { Controller.NestedErrors nested = new Controller.NestedErrors("Bad arguement", client); return(false); } }
public string Execute(string[] args, TcpClient client) { if (!this.CheckValid(args, client)) { return("multiPlayer"); } string name = args[0]; int rows = int.Parse(args[1]); int cols = int.Parse(args[2]); // Get the game from the model. GameMultiPlayer game = model.GenerateGame(name, rows, cols, client); if (game == null) { Controller.NestedErrors nested = new Controller.NestedErrors("Error exist game", client); } return("multiPlayer"); }
public string Execute(string[] args, TcpClient client) { if (!this.CheckValid(args, client)) { // Check if the client is on other game to keep the connection. if (model.ClientOnGame(client)) { return("multiPlayer"); } return("singlePlayer"); } string name = args[0]; string typeAlgorithem = args[1]; AdapterSolution adpterSolution = null; Solution <Position> s = null; // Solve the maze by BFS - 0, DFS - 1. switch (typeAlgorithem) { case "0": s = model.solveMazeBFS(name); // BFS solution. break; case "1": s = model.solveMazeDFS(name); // DFS solution. break; } // If the solution is not null send the solution to the client. Else send a message. if (s != null) { adpterSolution = new AdapterSolution(s, name); Controller.SendToClient(adpterSolution.ToJson(), client); } else { Controller.NestedErrors nested = new Controller.NestedErrors("maze not exist", client); } if (model.ClientOnGame(client)) { return("multiPlayer"); } return("singlePlayer"); }
/// <summary> /// Checks the valid. /// </summary> /// <param name="args">The arguments.</param> /// <param name="client">The client.</param> /// <returns></returns> public bool CheckValid(string[] args, TcpClient client) { // number of arguements big than 3. if (args.Length > 3) { Controller.NestedErrors nested = new Controller.NestedErrors("Bad arguement", client); return(false); } try { string name = args[0]; int rows = int.Parse(args[1]); int cols = int.Parse(args[2]); return(true); } catch (Exception) { Controller.NestedErrors nested = new Controller.NestedErrors("Bad arguement", client); return(false); } }
/// <summary> /// Execute the specified args and client. /// </summary> /// <returns>The execute.</returns> /// <param name="args">Arguments.</param> /// <param name="client">Client.</param> public string Execute(string[] args, TcpClient client) { string direction = args[0]; GameMultiPlayer game = model.FindGameByClient(client); if (!directions.Contains(direction)) { Controller.NestedErrors error = new Controller.NestedErrors("The dirction is incorrect}", client); return("multiPlayer"); } if (game != null) { NestedPlay nested = new NestedPlay(game.GetMaze().Name, direction); Controller.SendToClient(JsonConvert.SerializeObject(nested), game.OtherClient(client)); return("multiPlayer"); } else { Controller.SendToClient("{Erorr: you need to start a game}", client); return("singlePlayer"); } }
/// <summary> /// Create a maze. If the maze exist the client gets a message. /// </summary> /// <param name="args">The arguments.</param> /// <param name="client">The client.</param> /// <returns> /// string: "singlePlayer" or "multiPlayer". /// </returns> public string Execute(string[] args, TcpClient client) { if (!this.CheckValid(args, client)) { // check if the client play on other game to keep the connection. if (model.ClientOnGame(client)) { return("multiPlayer"); } return("singlePlayer"); } string name = args[0]; int rows = int.Parse(args[1]); int cols = int.Parse(args[2]); // Check if the maze exist. if (!model.ContainMaze(name)) { // Create a new maze. Maze maze = model.GenerateMaze(name, rows, cols); maze.Name = name; // Send the maze to the client. Controller.SendToClient(maze.ToJSON(), client); } else { // Send to client that the game exist. Controller.NestedErrors nested = new Controller.NestedErrors("Maze exist", client); } if (model.ClientOnGame(client)) { return("multiPlayer"); } return("singlePlayer"); }