Ejemplo n.º 1
0
        public string AddPlayer
            (string type, string username, int health, int armor, string gunName)
        {
            IGun gun = gunRepository.FindByName(gunName);

            if (gun == null)
            {
                throw new ArgumentException("Gun cannot be found!");
            }

            if (type == "Terrorist")
            {
                Player newPlayer = new Terrorist(username, health, armor, gun);
                playerRepository.Add(newPlayer);
            }
            else if (type == "CounterTerrorist")
            {
                Player newPlayer = new CounterTerrorist(username, health, armor, gun);
                playerRepository.Add(newPlayer);
            }
            else
            {
                throw new ArgumentException("Invalid player type!");
            }
            return($"Successfully added player {username}.");
        }
Ejemplo n.º 2
0
        public string AddPlayer(string type, string username, int health, int armor, string gunName)
        {
            IGun playersGun = gunsRep.FindByName(gunName);

            if (playersGun == null)
            {
                throw new ArgumentException("Gun cannot be found!");
            }
            if (type == "Terrorist" || type == "CounterTerrorist")
            {
                if (type == "Terrorist")
                {
                    playerRep.Add(new Terrorist(username, health, armor, playersGun));
                }
                else if (type == "CounterTerrorist")
                {
                    playerRep.Add(new CounterTerrorist(username, health, armor, playersGun));
                }
            }
            else
            {
                throw new ArgumentException("Invalid player type.");
            }
            return($"Successfully added player {username}.");
        }
Ejemplo n.º 3
0
        public string AddPlayer(string type, string username, int health, int armor, string gunName)
        {
            IGun gun = gunRepository.FindByName(gunName);

            if (gun == null)
            {
                throw new ArgumentException(ExceptionMessages.GunCannotBeFound);
            }

            IPlayer player;

            if (type == "Terrorist")
            {
                player = new Terrorist(username, health, armor, gun);
                playerRepository.Add(player);
                return($"Successfully added player {player.Username}.");
            }
            else if (type == "CounterTerrorist")
            {
                player = new CounterTerrorist(username, health, armor, gun);
                playerRepository.Add(player);
                return($"Successfully added gun {gun.Name}.");
            }
            else
            {
                throw new ArgumentException(ExceptionMessages.InvalidPlayerType);
            }
        }
Ejemplo n.º 4
0
        public string AddPlayer(string type, string username, int health, int armor, string gunName)
        {
            IGun gun = guns.FindByName(gunName);

            if (gun == null)
            {
                throw new ArgumentException(ExceptionMessages.GunCannotBeFound);
            }

            switch (type)
            {
            case "Terrorist":
                players.Add(new Terrorist(username, health, armor, gun));
                break;

            case "CounterTerrorist":
                players.Add(new CounterTerrorist(username, health, armor, gun));
                break;

            default:
                throw new ArgumentException(ExceptionMessages.InvalidPlayerType);
            }

            return(string.Format(OutputMessages.SuccessfullyAddedPlayer, username));
        }
Ejemplo n.º 5
0
        public void Should_be_able_to_add_player_rivalry_statistics()
        {
            var game = ObjectMother.CreateGame();

            _gameRepository.Add(game);

            var player         = ObjectMother.CreatePlayer();
            var affectedPlayer = ObjectMother.CreatePlayer();

            _playerRepository.Add(player);
            _playerRepository.Add(affectedPlayer);

            var hole = ObjectMother.CreateHole(Int32.MaxValue);

            _holeRepository.Add(hole);

            var shotType = ObjectMother.CreateShotType();

            _shotTypeRepository.Add(shotType);

            var playerRivalryStatistics = ObjectMother.CreatePlayerRivalryStatistics(game, player, affectedPlayer, hole, shotType);

            _playerRivalryStatisticsRepository.Add(playerRivalryStatistics);

            Assert.AreNotEqual(0, playerRivalryStatistics.Id);
        }
Ejemplo n.º 6
0
        public void Should_be_able_to_add_player()
        {
            var player = ObjectMother.CreatePlayer();

            _repository.Add(player);

            Assert.AreNotEqual(0, player.Id);
        }
Ejemplo n.º 7
0
        public void TestHighCardWinner()
        {
            IPlayerRepository playerRepository = new PlayerRepository();
            IGameManager      gameManager      = new GameManager();

            // Create test data
            playerRepository.Add(new Player
            {
                PlayerName = "Devin",
                Cards      = new List <Card>
                {
                    new Card {
                        Rank = "A", Suit = "D"
                    },
                    new Card {
                        Rank = "2", Suit = "D"
                    },
                    new Card {
                        Rank = "3", Suit = "D"
                    },
                    new Card {
                        Rank = "7", Suit = "S"
                    },
                    new Card {
                        Rank = "10", Suit = "H"
                    }
                }
            });

            playerRepository.Add(new Player
            {
                PlayerName = "Maks",
                Cards      = new List <Card>
                {
                    new Card {
                        Rank = "K", Suit = "H"
                    },
                    new Card {
                        Rank = "Q", Suit = "D"
                    },
                    new Card {
                        Rank = "10", Suit = "S"
                    },
                    new Card {
                        Rank = "9", Suit = "D"
                    },
                    new Card {
                        Rank = "7", Suit = "H"
                    }
                }
            });

            (var winners, var hand) = gameManager.GetWinners(playerRepository.GetAll());

            // Assert that Devin won with the High Card
            Assert.AreEqual("Devin", winners.FirstOrDefault().PlayerName);
            Assert.AreEqual(HandTypes.HighCard, hand);
        }
Ejemplo n.º 8
0
 public string AddPlayer(string type, string username)
 {
     if (type == "Beginner")
     {
         var player = new Beginner(new CardRepository(), username);
         playerRepository.Add(player);
         return($"Successfully added player of type {type} with username: {username}");
     }
     else
     {
         var player = new Advanced(new CardRepository(), username);
         playerRepository.Add(player);
         return($"Successfully added player of type {type} with username: {username}");
     }
 }
Ejemplo n.º 9
0
        public void ShouldBeAbleToAddPlayerGameStatistics()
        {
            var game = ObjectMother.CreateGame();

            _gameRepository.Add(game);

            var player = ObjectMother.CreatePlayer();

            _playerRepository.Add(player);

            var playerGameStatistics = ObjectMother.CreatePlayerGameStatistics(game, player);

            _playerGameStatisticsRepository.Add(playerGameStatistics);

            Assert.AreNotEqual(0, playerGameStatistics.Id);
        }
Ejemplo n.º 10
0
        public string AddPlayer(string type, string username, int health, int armor, string gunName)
        {
            var gun = _guns.FindByName(gunName);

            if (gun == null)
            {
                throw new ArgumentException(ExceptionMessages.GunCannotBeFound);
            }

            if (!Enum.TryParse(type, out PlayerType playerType))
            {
                throw new ArgumentException(ExceptionMessages.InvalidGunType);
            }

            IPlayer player = null;

            switch (playerType)
            {
            case PlayerType.Terrorist:
                player = new Terrorist(username, health, armor, gun);
                break;

            case PlayerType.CounterTerrorist:
                player = new CounterTerrorist(username, health, armor, gun);
                break;
            }
            _players.Add(player);

            return(string.Format(OutputMessages.SuccessfullyAddedPlayer, username));
        }
Ejemplo n.º 11
0
        public void Handle(NetConnection sender, SNMessageData messageData)
        {
            if (!(sender.Tag is PlayerClient))
            {
                return;
            }

            var client = (PlayerClient)sender.Tag;
            var selectCharacterMessageData = (SelectCharacterMessageData)messageData;

            if (!IsAccountCharacter(client.PersistentId, selectCharacterMessageData.CharacterId, out Character character))
            {
                return;
            }

            var characterSelectedMessageData = new CharacterSelectedMessageData();

            characterSelectedMessageData.Character = character;
            outgoingMessageService.Send(characterSelectedMessageData, sender);

            var player = new Player(client, character);

            playerRepository.Add(player);
            sender.Tag = player;

            // Send already connected players positions
            entitiesProcessor.NewPlayerConnected(player);
        }
        public ActionResult Create(PlayerModel model)
        {
            try
            {
                // TODO: Add insert logic here
                PlayerRepository repository = new PlayerRepository();
                model.UserId = User.Identity.GetUserId();
                var player = repository.Add(model);

                if (Request.Files[0].ContentLength > 0)
                {
                    HttpPostedFileBase postedFile = Request.Files[0];
                    string filename = player.Id + ".jpg";
                    var blobHelper = new StorageHelper.BlobHelper();

                    var container = blobHelper.GetContainer("playerspictures");

                    blobHelper.UploadToContainer(postedFile, container, filename);

                    return RedirectToAction("Index");
                }

                return RedirectToAction("Index");
            }
            catch(Exception ex)
            {
                Trace.TraceError(ex.Message);
                throw;
            }
        }
Ejemplo n.º 13
0
        private void PlayerCreateButton_Click(object sender, EventArgs e)
        {
            PlayerRepository repos = new PlayerRepository();

            if (NewPlayerTextBox.Text != "")
            {
                if (freestats == 0)
                {
                    if (!repos.IsExist(NewPlayerTextBox.Text))
                    {
                        Player pl = new Player(NewPlayerTextBox.Text, str, agi, stm);
                        repos.Add(pl);
                        SwitchScene(Scene.Menu, pl);
                    }
                    else
                    {
                        MessageBox.Show("This name is already taken");
                    }
                }
                else
                {
                    MessageBox.Show("Use all stats");
                }
            }
            else
            {
                MessageBox.Show("Input name");
            }
        }
Ejemplo n.º 14
0
 private void PlayerCreateButton_Click(object sender, EventArgs e)
 {
     PlayerRepository repos = new PlayerRepository();
     if (NewPlayerTextBox.Text != "")
     {
         if (freestats == 0)
         {
             if (!repos.IsExist(NewPlayerTextBox.Text))
             {
                 Player pl = new Player(NewPlayerTextBox.Text, str, agi, stm);
                 repos.Add(pl);
                 SwitchScene(Scene.Menu, pl);
             }
             else
             {
                 MessageBox.Show("This name is already taken");
             }
         }
         else
         {
             MessageBox.Show("Use all stats");
         }
     }
     else
     {
         MessageBox.Show("Input name");
     }
 }
Ejemplo n.º 15
0
        public string AddPlayer(string type, string username, int health, int armor, string gunName)
        {
            IPlayer Player = null;
            IGun    gun    = null;

            gun = gunRepository.FindByName(gunName);
            if (gun == null)
            {
                throw new ArgumentException(ExceptionMessages.GunCannotBeFound);
            }

            switch (type)
            {
            case "Terrorist":
                Player = new Terrorist(username, health, armor, gun);
                break;

            case "CounterTerrorist":
                Player = new CounterTerrorist(username, health, armor, gun);
                break;

            default:
                throw new ArgumentException(ExceptionMessages.InvalidPlayerType);
                // exc message-a se razlichava s tova ot faila
            }

            playerRepository.Add(Player);
            return(String.Format(OutputMessages.SuccessfullyAddedPlayer, username));
        }
Ejemplo n.º 16
0
        public string AddPlayer(string type, string username, int health, int armor, string gunName)
        {
            IPlayer player;
            IGun    gun = gunRepository.FindByName(gunName);

            if (gun == null)
            {
                throw new ArgumentException(ExceptionMessages.GunCannotBeFound);
            }

            if (type == "Terrorist")
            {
                player = new Terrorist(username, health, armor, gun);
            }
            else if (type == "CounterTerrorist")
            {
                player = new CounterTerrorist(username, health, armor, gun);
            }
            else
            {
                throw new ArgumentException(ExceptionMessages.InvalidPlayerType);
            }

            playerRepository.Add(player);

            return(string.Format(OutputMessages.SuccessfullyAddedPlayer, username));
        }
Ejemplo n.º 17
0
        protected override Event Persist()
        {
            if (Result.Resolution == EventResolutionType.Commit)
            {
                playerRepository.Add(_player);

                var dumpPlayerAt = new EnterLocationEvent(_id, _player.LoggedOutPosition);
                Engine.Instance.Push(dumpPlayerAt);
            }

            // TEMPORARY WORKAROUND TO ALWAYS SPAWN A MONSTER WHEN PLAYER SUBSCRIBES:
            //var monster = (Monster)ResourceLocator.Get(Id.FromString("M1111123"));
            //if (monster == null)
            //{
            //    monster = MonsterFactory.Create("A");
            //    ResourceLocator.Add(monster);
            //    _player.Scene.Entities.Add(monster);
            //}

            //TODO: Look at this! We should be able to have one way references.
            //_player.Scene.Entities.Add(_player);
            //_player.Scene = todoScene;

            return(this);
        }
Ejemplo n.º 18
0
 public void Post([FromBody] PlayerAddRequest players)
 {
     if (ModelState.IsValid)
     {
         playerRepository.Add(players);
     }
 }
Ejemplo n.º 19
0
        public string AddPlayer(string type, string username)
        {
            IPlayer player;

            if (type == "Beginner")
            {
                player = new Beginner(new CardRepository(), username);
                playerRepository.Add(player);
            }
            else if (type == "Advanced")
            {
                player = new Advanced(new CardRepository(), username);
                playerRepository.Add(player);
            }

            return(result = string.Format(ConstantMessages.SuccessfullyAddedPlayer, type, username));
        }
Ejemplo n.º 20
0
        public string AddPlayer(string type, string username)
        {
            var player = playerFactory.CreatePlayer(type, username);

            playerRepository.Add(player);

            return($"Successfully added player of type {type} with username: {username}");
        }
Ejemplo n.º 21
0
        public string AddPlayer(string type, string username, int health, int armor, string gunName)
        {
            if (type == nameof(Terrorist) || type == nameof(CounterTerrorist))
            {
                IPlayer player;
                IGun    gun;

                gun = guns.FindByName(gunName);

                if (type == nameof(Terrorist))
                {
                    if (gun == null)
                    {
                        throw new ArgumentException(String.Format(ExceptionMessages.GunCannotBeFound));
                    }

                    else
                    {
                        player = new Terrorist(username, health, armor, gun);
                        players.Add(player);
                    }
                }

                else
                {
                    if (gun == null)
                    {
                        throw new ArgumentException(String.Format(ExceptionMessages.GunCannotBeFound));
                    }

                    else
                    {
                        player = new CounterTerrorist(username, health, armor, gun);
                        players.Add(player);
                    }
                }

                return(String.Format(OutputMessages.SuccessfullyAddedPlayer, player.Username));
            }

            else
            {
                throw new ArgumentException(String.Format(ExceptionMessages.InvalidPlayerType));
            }
        }
Ejemplo n.º 22
0
        public void DoesNotAddDuplicatePlayer()
        {
            var player = new Player
            {
                FirstName = "First 1",
                LastName  = "Last 1"
            };

            var playerRepository = new PlayerRepository(_fixture.Context);

            playerRepository.Add(player);
            playerRepository.Add(player);

            var result = playerRepository.GetAll();

            Assert.Equal(1, result.Count());
            Assert.Equal(player, result.First());
        }
Ejemplo n.º 23
0
        public static void AddPlayerUsingRepository()
        {
            var playerRepo = new PlayerRepository();
            var player     = new Player {
                FirstName = "Emil", LastName = "Christensen", NickName = "HeatoN", CountryId = 1, BirthDate = new DateTime(1984, 5, 15), Status = "Retierd", Role = "Rifler"
            };

            playerRepo.Add(player);
            playerRepo.Save();
        }
Ejemplo n.º 24
0
        public ActionResult Create(PlayerModel model)
        {
            if (ModelState.IsValid)
            {
                playerRepository.Add(PlayerModel.ToDatabaseModel(model));

                return(RedirectToAction("Index"));
            }

            return(View(model));
        }
Ejemplo n.º 25
0
        private void CreatePlayer(Player player)
        {
            var playerRepo = new PlayerRepository();

            Player existing = playerRepo.FindByExternalId(player.ExternalId);

            if (existing == null)
            {
                playerRepo.Add(player);
            }
        }
        public void Should_be_able_to_add_ranking()
        {
            var player = ObjectMother.CreatePlayer();

            _playerRepository.Add(player);

            var ranking = ObjectMother.CreateRanking(player);

            _rankingRepository.Add(ranking);

            Assert.AreNotEqual(0, ranking.Id);
        }
        public void Should_be_able_to_add_player_statistics()
        {
            var player = ObjectMother.CreatePlayer();

            _playerRepository.Add(player);

            var playerStatistics = ObjectMother.CreatePlayerStatistics(player);

            _playerStatisticsRepository.Add(playerStatistics);

            Assert.AreNotEqual(0, playerStatistics.Id);
        }
Ejemplo n.º 28
0
        /// <summary>Saves this player.</summary>
        public override void Save()
        {
            // Save the player's basic info.
            var repository = new PlayerRepository();

            if (this.ID == 0)
            {
                repository.Add(this.PlayerData);
                this.ID = this.PlayerData.ID;
            }
            else
            {
                repository.Update(this.PlayerData);
            }

            /* Disabling roles for now
             * // Deal with the player roles.
             * var roleRepository = new PlayerRoleRepository();
             * ICollection<PlayerRoleRecord> existingRoles = roleRepository.FetchAllPlayerRoleRecordsForPlayer(this.Id);
             *
             * var toAdd = new List<PlayerRoleRecord>();
             *
             * foreach (var roleRecord in this.RoleData)
             * {
             *  var currRole = this.FindRole(roleRecord.ID, existingRoles);
             *
             *  if (currRole == null)
             *  {
             *      // Add it to the list to add
             *      toAdd.Add(currRole);
             *  }
             *  else
             *  {
             *      // Remove the role since there is nothing to do.
             *      existingRoles.Remove(currRole);
             *  }
             * }
             *
             * roleRepository.AddRolesToPlayer(toAdd);
             *
             * // Delete any roles still in the existing roles collection as they
             * // are no longer assigned to the person.
             * foreach (PlayerRoleRecord existingRole in existingRoles)
             * {
             *  roleRepository.Remove(existingRole);
             * }
             */

            // @@@ TODO: Need to do this with all the other custom lists and collections, like friends and inventory.
        }
Ejemplo n.º 29
0
        public void AddPlayer()
        {
            var player = new Player
            {
                FirstName = "First 1",
                LastName  = "Last 1"
            };

            var playerRepository = new PlayerRepository(_fixture.Context);

            var result = playerRepository.Add(player);

            Assert.NotNull(result);
            Assert.Equal(player, result);
        }
Ejemplo n.º 30
0
        public string AddPlayer(string type, string username)
        {
            var player = playerFactory.CreatePlayer(type, username);

            try
            {
                players.Add(player);
            }
            catch (Exception e)
            {
                return(e.Message);
            }
            return(ConstantMessages.SuccessfullyAddedPlayer
                   .Replace("{0}", type)
                   .Replace("{1}", username));
        }
Ejemplo n.º 31
0
        public void Should_be_able_to_add_player_hole_statistics()
        {
            var player = ObjectMother.CreatePlayer();

            _playerRepository.Add(player);

            var hole = ObjectMother.CreateHole(Int32.MaxValue);

            _holeRepository.Add(hole);

            var playerHoleStatistics = ObjectMother.CreatePlayerHoleStatistics(player, hole);

            _playerHoleStatisticsRepository.Add(playerHoleStatistics);

            Assert.AreNotEqual(0, playerHoleStatistics.Id);
        }
Ejemplo n.º 32
0
 public void SignUp(Registered player)
 {
     if (player == null)
     {
         throw new ArgumentNullException(nameof(player));
     }
     if (string.IsNullOrEmpty(player.Name))
     {
         throw new InvalidOperationException("Name must be provided.");
     }
     if (string.IsNullOrEmpty(player.Password))
     {
         throw new InvalidOperationException("Password must be provided.");
     }
     _repository.Add(player);
 }