Esempio n. 1
0
        /// <summary>
        /// Gets the game by client.
        /// </summary>
        /// <param name="client">The client.</param>
        /// <returns></returns>
        /// <exception cref="System.InvalidOperationException">you are not taking part in a game</exception>
        public MazeGame GetGameByClient(string client)
        {
            MazeGame game = this.dataBase.GetGameByClient(client);

            if (game == null)
            {
                throw new InvalidOperationException("you are not taking part in a game");
            }
            return(game);
        }
Esempio n. 2
0
        /// <summary>
        /// Determines whether the client is part of a multiplayer game.
        /// </summary>
        /// <param name="client">The client.</param>
        /// <returns>
        ///   <c>true</c> if [is in multi game] [the specified client]; otherwise, <c>false</c>.
        /// </returns>
        public bool IsInMultiGame(string client)
        {
            MazeGame game = this.dataBase.GetGameByClient(client);

            if (game == null)
            {
                return(false);
            }
            return(true);
        }
Esempio n. 3
0
        /// <summary>
        /// Joins the game.
        /// </summary>
        /// <param name="name">The name.</param>
        /// <param name="guest">The client.</param>
        /// <returns></returns>
        /// <exception cref="System.ArgumentException">no such game, re-enter a command</exception>
        public MazeGame JoinGame(string name, string guest)
        {
            if (!dataBase.IsGameExists(name))
            {
                throw new ArgumentException("no such game");
            }

            MazeGame game = dataBase.GetGame(name);

            game.Join(guest);
            return(game);
        }
Esempio n. 4
0
        /// <summary>
        /// Adds the game.
        /// </summary>
        /// <param name="name">The name.</param>
        /// <param name="r">The r.</param>
        /// <param name="c">The c.</param>
        /// <param name="client">The client.</param>
        /// <exception cref="System.ArgumentException">name already taken, re-enter a command</exception>
        public void AddGame(string name, int r, int c, string clientId)
        {
            if (dataBase.IsGameExists(name))
            {
                throw new ArgumentException("name already taken");
            }
            MazeGeneratorLib.DFSMazeGenerator generator =
                new MazeGeneratorLib.DFSMazeGenerator();
            Maze maze = generator.Generate(r, c);

            maze.Name = name;
            MazeGame game = new MazeGame(maze, clientId);

            dataBase.AddGame(name, game);
        }
Esempio n. 5
0
 /// <summary>
 /// Adds the game.
 /// </summary>
 /// <param name="name">The name.</param>
 /// <param name="game">The game.</param>
 public void AddGame(string name, MazeGame game)
 {
     MazeModelDataBase.games.Add(name.GetHashCode(), game);
 }