Beispiel #1
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);
        }
Beispiel #2
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);
        }
Beispiel #3
0
        public bool Logout(User User)
        {
            bool isExistOnSys = _user.CanAddNewUser(User.UserName, User.Password);

            if (!isExistOnSys)
            {
                return(true);
            }
            return(false);
        }
Beispiel #4
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);
        }
Beispiel #5
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);
     }
 }
Beispiel #6
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);
        }
Beispiel #7
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);
        }