Ejemplo n.º 1
0
        public bool CreateNewGame(int byInPolicy, int numOfPlayers)
        {
            try
            {
                Collection <UserManagement.User> users = new Collection <UserManagement.User>();
                UserManagement.User user  = _user.AddNewUser("temp" + _userCreationIndex, "12344234");
                UserManagement.User user2 = _user.AddNewUser("temp2" + _userCreationIndex, "12344234");
                _userCreationIndex++;

                user.SetMoney(80);
                users.Add(user);
                if (numOfPlayers > 1)
                {
                    users.Add(user2);
                }

                IGame client = new GameLogic.Game_Client.GameClient(users, GameType.Limit, byInPolicy, 10, 2, 10, true, new GameLogic.Chip(10));
                _game.ActivateGame(client);
                return(true);
            }
            catch (Exception e)
            {
                return(false);
            }
        }
Ejemplo n.º 2
0
        public bool CreateNewGameFromInstance(GameClient game)
        {
            IGame client;
            Collection <UserManagement.User> users = new Collection <UserManagement.User>();
            bool val;

            foreach (KeyValuePair <string, User> entry in game.Players)
            {
                User tmp = entry.Value;
                UserManagement.User U = new UserManagement.User(tmp.UserName, tmp.Password, 0);
                U.Set_email(tmp.Email.Address);
                U.SetMoney(100);
                U.ChangePlayerState(PlayerState.Player);
                users.Add(U);
            }
            try
            {
                client = new GameLogic.Game_Client.GameClient(users, GameType.Limit, 2, 10, 2, 10, true, new GameLogic.Chip(10));
                _game.ActivateGame(client);
                val = true;
            }
            catch (Exception)
            {
                val = false;
            }



            return(val);
        }
Ejemplo n.º 3
0
 public int Register(string userName, string password, MailAddress email)
 {
     UserManagement.User user = _user.AddNewUser(userName, password);
     if (user != null)
     {
         return(0);
     }
     return(1);
 }
Ejemplo n.º 4
0
        public User EditUserDetails(User oldeuser, User newuser)
        {
            UserManagement.User user = new UserManagement.User(oldeuser.UserName, oldeuser.Password, 0);
            user.Set_email(oldeuser.Email.Address);
            bool mail = _user.ChangeEmail(user, newuser.Email.Address);
            bool pass = _user.ChangePassword(user, oldeuser.Password, newuser.Password);

            return((mail && pass && oldeuser.UserName == newuser.UserName) ? newuser : null);
        }
Ejemplo n.º 5
0
 public void Register(string userName, string password, string email)
 {
     UserManagement.User user = new UserManagement.User(userName, password, 0);
     try
     {
         _user.AddNewUser(userName, password);
     }
     catch (Exception e)
     {
         throw new Exception(e.Message);
     }
 }
Ejemplo n.º 6
0
        public bool JoinToGame(GameClient game, User user, State state)
        {
            GameLogic.Game_Client.GameClient client;
            UserManagement.User userToJoin         = _user.GetUserFromUserList(user.UserName);
            Collection <UserManagement.User> users = new Collection <UserManagement.User>();
            bool val = false;

            foreach (KeyValuePair <string, User> entry in game.Players)
            {
                User tmp = entry.Value;
                UserManagement.User U = new UserManagement.User(tmp.UserName, tmp.Password, 0);
                U.Set_email(tmp.Email.Address);
                U.ChangePlayerState(PlayerState.Player);
                U.SetMoney(100);
                users.Add(U);
            }

            client = new GameLogic.Game_Client.GameClient(users, GameType.Limit, 0, game.AmountOfPlayers, 4, game.AmountOfPlayers, true, new GameLogic.Chip(20));
            int before = client.GetPlayers().Count;

            if (state == State.Player)
            {
                try
                {
                    _game.JoinGameAsPlayer(userToJoin, client);
                    if (client.GetPlayers().Count == before + 1)
                    {
                        val = true;
                    }
                }
                catch (Exception)
                {
                    return(false);
                }
            }
            else if (state == State.Spectator)
            {
                try
                {
                    _game.JoinGameAsSpectator(userToJoin, client);
                    val = true;
                }
                catch (Exception)
                {
                    return(false);
                }
            }
            return(val);
        }
Ejemplo n.º 7
0
 public bool JoinUserToFirstActiveGame(User user, State state)
 {
     try
     {
         IGame client          = _game.GetAllActiveGames()[0];
         UserManagement.User U = new UserManagement.User(user.UserName, user.Password, 0);
         U.SetMoney(100);
         U.ChangePlayerState(PlayerState.Player);
         client.AddPlayer(U);
         _game.JoinGameAsPlayer(U, client);
         return(true);
     }
     catch (Exception)
     {
         return(false);
     }
 }
Ejemplo n.º 8
0
        public int Login(string userName, string password)
        {
            int v = 1;

            UserManagement.User user = new UserManagement.User(userName, password, 0);
            try
            {
                if (_user.UserLogIn(user.PlayerName, password) != null)
                {
                    v = 0;
                }
            }
            catch (Exception e)
            {
                throw new Exception(e.Message);
            }
            return(v);
        }
Ejemplo n.º 9
0
        public User TestfindUserByUserName(string userName)
        {
            User u;

            try
            {
                UserManagement.User user = _user.GetUserFromUserList(userName);
                u = new User(user.PlayerName, "not relevanr", "*****@*****.**");
                switch (user.GetRank())
                {
                case 0:
                {
                    u.LeagueRank = LeagueType.Beginner;
                    break;
                }

                case 1:
                {
                    u.LeagueRank = LeagueType.Normal;
                    break;
                }

                case 3:
                {
                    u.LeagueRank = LeagueType.Advanced;
                    break;
                }
                }
            }
            catch (Exception e)
            {
                u            = new User("undef", "not relevanr", "*****@*****.**");
                u.LeagueRank = LeagueType.Undefined;
            }

            return(u);
        }
Ejemplo n.º 10
0
        public bool LeaveActiveGame(GameClient game, User user)
        {
            GameLogic.Game_Client.GameClient client;
            UserManagement.User userToDelete       = new UserManagement.User(user.UserName, user.Password, 0);
            Collection <UserManagement.User> users = new Collection <UserManagement.User>();
            bool val;

            foreach (KeyValuePair <string, User> entry in game.Players)
            {
                User tmp = entry.Value;
                UserManagement.User U = new UserManagement.User(tmp.UserName, tmp.Password, _userId);
                U.Set_email(tmp.Email.Address);
                U.ChangePlayerState(PlayerState.Player);
                U.SetMoney(100);
                users.Add(U);
                _userId++;
            }
            client = new GameLogic.Game_Client.GameClient(users, GameType.Limit, 2, 10, 2, 10, true, new GameLogic.Chip(10));
            _game.ActivateGame(client);

            try
            {
                if (_game.LeaveGame(userToDelete, client))
                {
                    val = true;
                }
                else
                {
                    val = false;
                }
            }
            catch (Exception)
            {
                val = false;
            }
            return(val);
        }