Ejemplo n.º 1
0
 /// <summary>
 ///  playing a move in the multiplayer maze (up, down, right, left)
 /// </summary>
 /// <param name="move"></param>
 /// <param name="client"></param>
 /// <returns></returns>
 public string PlayMove(string move, TcpClient client)
 {
     if (multiplayerGames.Keys.Contains(client))
     {
         HandleMultiplayers handle = multiplayerGames[client];
         handle.SendMessageToClient(client, move);
     }
     return(String.Empty);
 }
Ejemplo n.º 2
0
 /// <summary>
 /// joining a multiplayer maze that was started by another client
 /// and sending the maze to the client that started it
 /// </summary>
 /// <param name="name"></param>
 /// <param name="client"></param>
 /// <returns></returns>
 public Maze JoinMaze(string name, TcpClient client)
 {
     if (multiplayerMazeDict.Keys.Contains(name))
     {
         HandleMultiplayers handle = handleMultiplayersDict[name];
         Maze m = multiplayerMazeDict[name];
         handle.Guest = client;
         handle.SendMazeToJsonToHost();
         multiplayerGames.Add(client, handle);
         multiplayerMazeDict.Remove(name);
         return(m);
     }
     return(null);
 }
Ejemplo n.º 3
0
 /// <summary>
 /// starting a new multiplayer maze
 /// if the maze already exists it returns it
 /// </summary>
 /// <param name="name"></param>
 /// <param name="rows"></param>
 /// <param name="cols"></param>
 /// <param name="client"></param>
 /// <returns></returns>
 public Maze MazeStart(string name, int rows, int cols, TcpClient client)
 {
     if (!multiplayerMazeDict.Keys.Contains(name))
     {
         Maze maze = Generate(name, rows, cols);
         multiplayerMazeDict.Add(name, maze);
         HandleMultiplayers handle = new HandleMultiplayers(client);
         handle.GameToJason = maze.ToJSON();
         handle.Name        = name;
         handleMultiplayersDict.Add(name, handle);
         multiplayerGames.Add(client, handle);
         return(maze);
     }
     return(null);
 }
Ejemplo n.º 4
0
 /// <summary>
 /// closing a multiplayer maze
 /// </summary>
 /// <param name="name"></param>
 /// <param name="client"></param>
 /// <returns></returns>
 public string CloseMultiPlayerGame(string name, TcpClient client)
 {
     if (multiplayerGames.Keys.Contains(client))
     {
         HandleMultiplayers handle = handleMultiplayersDict[name];
         TcpClient          guest  = handle.Guest;
         TcpClient          host   = handle.Host;
         if (guest == null || host == null)
         {
             multiplayerMazeDict.Remove(name);
             handleMultiplayersDict.Remove(name);
             multiplayerGames.Remove(client);
             return(String.Empty);
         }
         multiplayerGames.Remove(guest);
         multiplayerGames.Remove(host);
         handleMultiplayersDict.Remove(name);
         handle.Close(client);
         return(String.Empty);
     }
     return("Error Game not found");
 }