예제 #1
0
파일: MazeModel.cs 프로젝트: rikifis/WebApi
        /// <summary>
        /// get a multiplayer game.
        /// </summary>
        /// <param name="user">the player</param>
        /// <returns>the game</returns>
        public MultiPlayerGame GetGame(User user)
        {
            MultiPlayerGame game = null;

            // go over the game
            for (int i = 0; i < multiGames.Count; i++)
            {
                game = multiGames.ElementAt(i).Value;
                // check if that is the players game.
                if (game.IsPlayer(user))
                {
                    return(game);
                }
            }
            // game wasn't found.
            return(null);
        }
예제 #2
0
파일: MazeModel.cs 프로젝트: rikifis/WebApi
        /// <summary>
        /// start a multi player game.
        /// </summary>
        /// <param name="user">the client that will be player1</param>
        /// <param name="name">the name of the game</param>
        /// <param name="x">number of rows.</param>
        /// <param name="y">number off cols</param>
        /// <returns>returns the game maze</returns>
        public Maze Start(User user, string name, int x, int y)
        {
            // the game exist.
            if (toJoinMazes.ContainsKey(name))
            {
                // error.
                return(null);
            }
            // generate the
            IMazeGenerator gen  = new DFSMazeGenerator();
            Maze           maze = gen.Generate(x, y);

            maze.Name = name;
            // add the game,
            toJoinMazes.Add(name, maze);
            // buils a muli player game.
            MultiPlayerGame game = new MultiPlayerGame(user, name);

            multiGames.Add(name, game);
            game.WaitForJoin();
            // we got another player.
            return(playingMazes[name]);
        }