public void SpawnPlayer()
    {
        m_SpawnedPlayer = null;
        m_SpawnedPlayer = Instantiate(m_FootballPlayerPrefab) as FootballPlayer;

        if (m_SpawnedPlayer)
        {
            m_SpawnedPlayer.transform.position = transform.position;
            m_SpawnedPlayer.SetPlayerControlled(false);
            m_SpawnedPlayer.SetIsFriendlyTeamPlayer(m_IsFriendlyTeamPlayerSpawner);
            m_SpawnedPlayer.SetInitialPosition(transform.position);

            if (!m_IsFriendlyTeamPlayerSpawner)
            {
                GameObject cubeChild = m_SpawnedPlayer.transform.GetChild(0).gameObject;

                if (cubeChild)
                {
                    Renderer rc = cubeChild.GetComponent <Renderer> ();

                    if (rc)
                    {
                        rc.material = m_OppositionMaterial;
                    }
                }
            }
        }
    }
Exemple #2
0
        public async Task <bool> Edit(string id, FootballPlayerServiceModel footballPlayerServiceModel)
        {
            PlayerPosition playerPositionFromDb = await this.context.PlayerPositions
                                                  .SingleOrDefaultAsync(playerPosition => playerPosition.Name == footballPlayerServiceModel.PlayerPosition.Name);

            if (playerPositionFromDb == null)
            {
                throw new ArgumentNullException(nameof(playerPositionFromDb));
            }

            FootballPlayer footballPlayerFromDb = await this.context.FootballPlayers.SingleOrDefaultAsync(player => player.Id == id);

            if (footballPlayerFromDb == null)
            {
                throw new ArgumentNullException(nameof(footballPlayerFromDb));
            }

            footballPlayerFromDb.Name         = footballPlayerServiceModel.Name;
            footballPlayerFromDb.Country      = footballPlayerServiceModel.Country;
            footballPlayerFromDb.Picture      = footballPlayerServiceModel.Picture;
            footballPlayerFromDb.Age          = footballPlayerServiceModel.Age;
            footballPlayerFromDb.Height       = footballPlayerServiceModel.Height;
            footballPlayerFromDb.PlayerNumber = footballPlayerServiceModel.PlayerNumber;

            footballPlayerFromDb.PlayerPosition = playerPositionFromDb;

            this.context.Update(footballPlayerFromDb);
            int result = await this.context.SaveChangesAsync();

            return(result > 0);
        }
        public void AddPlayerToDb(PlayerViewModel playerVm, int teamId)
        {
            var team = this.teamRepository
                       .GetById(teamId);

            if (team == null)
            {
                throw new ArgumentNullException();
            }

            var playerExists = this.playerRepository
                               .GetAllFiltered(p => p.FirstName == playerVm.FirstName && p.LastName == playerVm.LastName &&
                                               p.TeamId == team.Id)
                               .Any();

            if (playerExists)
            {
                throw new InvalidOperationException();
            }

            var player = new FootballPlayer()
            {
                FirstName   = playerVm.FirstName,
                LastName    = playerVm.LastName,
                Age         = playerVm.Age,
                TrophiesWon = playerVm.TrophiesWon,
                Nationality = playerVm.Nationality,
                Position    = playerVm.Position,
                TeamId      = team.Id
            };

            this.playerRepository.Add(player);
        }
        public async Task <IActionResult> OnPostAsync(FootballPlayer FootballPlayer)
        {
            FootballPlayer FootballPlayerToUpdate = await _context.FootballPlayers.FirstOrDefaultAsync(m => m.Id == FootballPlayer.Id).ConfigureAwait(false);

            if (null == FootballPlayerToUpdate)
            {
                return(Content("Error - Football player does not exist."));
            }

            FootballPlayerToUpdate.CentreBack        = FootballPlayer.CentreBack;
            FootballPlayerToUpdate.Sweeper           = FootballPlayer.Sweeper;
            FootballPlayerToUpdate.FullBack          = FootballPlayer.FullBack;
            FootballPlayerToUpdate.WingBack          = FootballPlayer.WingBack;
            FootballPlayerToUpdate.CentreMidfield    = FootballPlayer.CentreMidfield;
            FootballPlayerToUpdate.DefensiveMidfield = FootballPlayer.DefensiveMidfield;
            FootballPlayerToUpdate.AttackingMidfield = FootballPlayer.AttackingMidfield;
            FootballPlayerToUpdate.WideMidfield      = FootballPlayer.WideMidfield;
            FootballPlayerToUpdate.Forward           = FootballPlayer.Forward;
            FootballPlayerToUpdate.CentreForward     = FootballPlayer.CentreForward;
            FootballPlayerToUpdate.Winger            = FootballPlayer.Winger;
            FootballPlayerToUpdate.SetRating();

            int result = await _context.SaveChangesAsync().ConfigureAwait(false);

            if (result == 1)
            {
                return(Content($"{FootballPlayerToUpdate.Player.FirstName} has been updated!"));
            }

            return(Content("Error - please contact your system administrator"));
        }
        public async Task <IActionResult> OnPostAsync(Player Player, bool Football)
        {
            if (!ModelState.IsValid)
            {
                return(Content("Error - Model state is invalid."));
            }

            if (Player != null)
            {
                Player NewPlayer = SportsFactory.CreatePlayer(Player);
                _context.Players.Add(NewPlayer);

                if (Football)
                {
                    FootballPlayer NewFootballPlayer = SportsFactory.CreateFootballPlayer(NewPlayer);
                    _context.FootballPlayers.Add(NewFootballPlayer);
                }

                await _context.SaveChangesAsync().ConfigureAwait(true);

                return(Content(NewPlayer.FirstName + " has been created!"));
            }

            return(Content("Error - Could not create Player."));
        }
Exemple #6
0
    FootballPlayer GetClosestOppositionPlayerToBall()
    {
        if (m_Football == null)
        {
            return(null);
        }

        float          smallestDistance = -1.0f;
        FootballPlayer selectedPlayer   = null;

        foreach (FootballPlayer p in mOppositionTeam)
        {
            Vector3 diff = m_Football.GetComponent <Rigidbody>().transform.position - p.GetComponent <Rigidbody>().transform.position;

            float magSqrAbs = Mathf.Abs(diff.sqrMagnitude);

            if (smallestDistance == -1 ||
                magSqrAbs < smallestDistance)
            {
                smallestDistance = magSqrAbs;
                selectedPlayer   = p;
            }
        }

        return(selectedPlayer);
    }
        public void AddFootballPlayer(string firstName,
                                      string lastName,
                                      string imagePath,
                                      PlayerPositionType position,
                                      int height,
                                      int weight,
                                      int shirtNumber,
                                      int countryId,
                                      int teamId,
                                      DateTime birthDate)
        {
            FootballPlayer footballPlayer = new FootballPlayer()
            {
                FirstName     = firstName,
                LastName      = lastName,
                ImagePath     = imagePath,
                Height        = height,
                Weight        = weight,
                ShirtNumber   = shirtNumber,
                Position      = position,
                CountryId     = countryId,
                CurrentTeamId = teamId,
                BirthDate     = birthDate
            };

            using (this.unitOfWork)
            {
                this.footballPlayerRepository.Add(footballPlayer);
                this.unitOfWork.Commit();
            }
        }
Exemple #8
0
        internal static FootballTeam[] CreateTeams(string textName)
        {
            int stringIndex = 0;

            string[] text = File.ReadAllLines(textName);

            int numberOfFootballTeams = Int32.Parse(Program.CutText(text, ref stringIndex));

            FootballTeam[] teams = new FootballTeam[numberOfFootballTeams];
            for (int i = 0; i < numberOfFootballTeams; i++)
            {
                stringIndex++;
                if (stringIndex < text.Length && !String.IsNullOrEmpty(text[stringIndex]))
                {
                    string           nameOfTeam      = Program.CutText(text, ref stringIndex);
                    int              numberOfMembers = Int32.Parse(Program.CutText(text, ref stringIndex));
                    FootballPlayer[] group           = new FootballPlayer[numberOfMembers];
                    for (int k = 0; k < numberOfMembers; k++)
                    {
                        group[k] = new FootballPlayer(Program.CutText(text, ref stringIndex));
                    }
                    teams[i] = new FootballTeam(group, nameOfTeam);
                }
                else
                {
                    stringIndex++;
                }
            }
            return(teams);
        }
Exemple #9
0
        public IHttpActionResult PutFootballPlayer(int id, FootballPlayer footballPlayer)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != footballPlayer.id)
            {
                return(BadRequest());
            }

            db.Entry(footballPlayer).State = EntityState.Modified;

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!FootballPlayerExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
    private static void AddPlayer(Dictionary <string, FootballTeam> footballTeamsByName, string teamName, string[] playerParams)
    {
        if (!footballTeamsByName.ContainsKey(teamName))
        {
            Console.WriteLine($"Team {teamName} does not exist.");
            return;
        }

        string playerName = playerParams[0];
        int    endurance  = int.Parse(playerParams[1]);
        int    sprint     = int.Parse(playerParams[2]);
        int    drible     = int.Parse(playerParams[3]);
        int    passing    = int.Parse(playerParams[4]);
        int    shooting   = int.Parse(playerParams[5]);

        try
        {
            FootballPlayer player = new FootballPlayer(playerName, endurance, sprint, drible, passing, shooting);

            footballTeamsByName[teamName].AddPlayer(player);
        }
        catch (Exception ex)
        {
            Console.WriteLine(ex.Message);
        }
    }
        static void Main(string[] args)
        {
            FootballPlayer player1 = new FootballPlayer();

            player1.FootballPlayerConstructor("Joske", 20.0f, 18, FieldPosition.Back);

            FootballPlayer player2 = new FootballPlayer();

            player2.FootballPlayerConstructor("Sofie", 20.0f, 18, FieldPosition.Back);

            FootballPlayer player3 = new FootballPlayer();

            player3.FootballPlayerConstructor("Jefke", 20.0f, 18, FieldPosition.Back);

            FootballPlayer player4 = new FootballPlayer();

            player4.FootballPlayerConstructor("Tomke", 20.0f, 18, FieldPosition.Back);

            FootballPlayer player5 = new FootballPlayer();

            player5.FootballPlayerConstructor("ikbenneevveeeeeeeeeeltelangeNaamvoorneSpeler", 20.0f, 18, FieldPosition.Back);


            Console.WriteLine(player1.TakeTheBallInTheHand());

            Console.WriteLine(player2.Run());

            Console.WriteLine(player5.ShootOnGoal());


            //-------------------------------------------------------------------
            Console.ReadKey();
        }
Exemple #12
0
        public bool ScoreGoal(FootballPlayer playerWithBall, FootballPlayer opponentGoalKeeper)
        {
            //player with ball attempts a shot at goal
            var chanceToScore = (double)playerWithBall.GoalScoring /
                                (playerWithBall.GoalScoring + opponentGoalKeeper.GoalKeeping * MatchConstants.GoalKeepingMultiplier);

            return(chanceToScore > _randomHandler.NextDouble());
        }
Exemple #13
0
        public bool PassPlayer(FootballPlayer playerWithBall, FootballPlayer opponentPlayer)
        {
            //player with ball uses a maneuver to skilfully outplay the opponent player
            var chanceToPass = (double)playerWithBall.BallControl /
                               (playerWithBall.BallControl + opponentPlayer.Tackles);

            return(chanceToPass > _randomHandler.NextDouble());
        }
Exemple #14
0
        public bool PassBall(FootballPlayer playerWithBall, FootballPlayer teamPlayer, FootballPlayer opponentPlayer)
        {
            //player with ball shoots ball towards team player. opponent player is defending against this action
            var teamValue    = (playerWithBall.Passing + teamPlayer.BallControl) / 2;
            var chanceToPass = (double)teamValue / (teamValue + opponentPlayer.Tackles);

            return(chanceToPass > _randomHandler.NextDouble());
        }
        public ActionResult DeleteConfirmed(int id)
        {
            FootballPlayer footballPlayer = db.footballPlayerDB.Find(id);

            db.footballPlayerDB.Remove(footballPlayer);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
Exemple #16
0
        public void GetAPositionRatingTest()
        {
            FootballPlayer FootyPlayer = GenerateFootballPlayers()[0];
            int            posRating   = FootyPlayer.GetPositionRating("Defence");

            Assert.IsNotNull(posRating);
            Assert.IsTrue(posRating >= 0 && posRating <= 100);
        }
        public void CreateFootballPlayerTest()
        {
            Player NewPlayer = GeneratePlayers()[0];

            FootballPlayer footballPlayer = SportsFactory.CreateFootballPlayer(NewPlayer);

            Assert.IsNotNull(footballPlayer);
            Assert.AreEqual("Andrew", footballPlayer.Player.FirstName);
        }
Exemple #18
0
        public async Task <bool> Delete(string id)
        {
            FootballPlayer footballPlayer = await this.context.FootballPlayers.SingleOrDefaultAsync(player => player.Id == id);

            this.context.Remove(footballPlayer);
            int result = await this.context.SaveChangesAsync();

            return(result > 0);
        }
Exemple #19
0
        public int AddFootballPlayer(FootballPlayerViewModel model)
        {
            FootballPlayer player = AutoMapper.Mapper.Map <FootballPlayer>(model);

            UnitOfWork.FootballPlayers.Add(player);
            UnitOfWork.SaveChanges();

            return(player.Id);
        }
Exemple #20
0
    public Match(Club amyClub, Club aenemyClub)
    {
        myClub    = amyClub;
        enemyClub = aenemyClub;

        currentPlayer      = null;
        previousPlayer     = null;
        previousBallHolder = null;
    }
    FootballPlayer reversefootballplayer(FootballPlayer foot)
    {
        if(foot == FootballPlayer.Player1)
            foot = FootballPlayer.Player2;
        else if(foot ==	FootballPlayer.Player2)
            foot = FootballPlayer.Player1;

        return foot;
    }
        public void DeleteFootballPlayer(FootballPlayer footballPlayer)
        {
            Guard.WhenArgument(footballPlayer, "footballPlayer").IsNull().Throw();

            using (this.unitOfWork)
            {
                this.footballPlayerRepository.Delete(footballPlayer);
                this.unitOfWork.Commit();
            }
        }
    public void UpdateBallOwner(FootballPlayer player, bool force = false)
    {
        var team = player.Team == Team.Blue ? blueTeam : redTeam;

        ball.transform.parent = team[player.JerseyNumber].transform;
        if (force)
        {
            ball.transform.localPosition = Vector3.zero;
        }
    }
        public void ReturnNull_WhenPlayerWithSuchIdDoesNotExist()
        {
            var mockedRepository = new Mock <IWhoScoredRepository <FootballPlayer> >();
            var mockedUnitOfWork = new Mock <IUnitOfWork>();

            IFootballPlayerService footballPlayerService = new FootballPlayerService(mockedRepository.Object, mockedUnitOfWork.Object);
            FootballPlayer         footballPlayer        = footballPlayerService.GetFootballPlayerById(8);

            Assert.IsNull(footballPlayer);
        }
Exemple #25
0
        public void GetTopPositionsTest()
        {
            FootballPlayer FootyPlayer = GenerateFootballPlayers()[0];

            List <string> TopPositions = FootyPlayer.GetTopPositions();

            Assert.IsNotNull(TopPositions);
            Assert.IsTrue(TopPositions.Count == 3);
            Assert.IsTrue(FootyPlayer.GetPositionRating(TopPositions[0]) >= FootyPlayer.GetPositionRating(TopPositions[2]));
        }
        public ActionResult Edit([Bind(Include = "id,name,TeamId")] FootballPlayer footballPlayer)
        {
            if (ModelState.IsValid)
            {
                db.Entry(footballPlayer).State = EntityState.Modified;
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(footballPlayer));
        }
Exemple #27
0
    void Update()
    {
        // Doing setup in Update because scene not fully created in Start()
        if (!m_IsSetup)
        {
            DoSetup();
            m_IsSetup = true;
            return;
        }

        if (m_IsInGoalScoredCooldown)
        {
            m_timeUntilScoreCooldownFinished -= Time.deltaTime;

            if (m_timeUntilScoreCooldownFinished <= 0.0f)
            {
                m_IsInGoalScoredCooldown = false;

                m_Football.GetComponent <Rigidbody> ().transform.position = m_Football.m_InitialPosition;
            }
        }

        if (mFriendlyTeam.Count == 0 || mOppositionTeam.Count == 0)
        {
            // intitial build
            RebuildTeams();

            m_CurrentSelectedPlayer = GetClosestFriendlyPlayerToBall();

            if (m_CurrentSelectedPlayer)
            {
                m_CurrentSelectedPlayer.SetPlayerControlled(true);
            }

            m_CurrentOppositionPlayer = GetClosestOppositionPlayerToBall();

            if (m_CurrentOppositionPlayer)
            {
                m_CurrentOppositionPlayer.SetIsAIControlled(true);
            }
        }

        TakeInput();

        UpdateCamera();

        ApplyBallControlAid();

        UpdateCurrentPlayer();

        UpdateCurrentOppositionPlayer();

        UpdateAIPositions();
    }
    public TimedMethod[] Summon()
    {
        System.Random rng = new System.Random();
        int           seed;
        Character     current;

        for (int i = 0; i < 3; i++)
        {
            seed = rng.Next(10);
            if (seed == 0)
            {
                current = new CSMajor();
            }
            else if (seed == 1)
            {
                current = new MusicMajor();
            }
            else if (seed == 2)
            {
                current = new PoliticalScientist();
            }
            else if (seed == 3)
            {
                current = new FootballPlayer();
            }
            else if (seed == 4)
            {
                current = new BusinessMajor();
            }
            else if (seed == 5)
            {
                current = new EnglishMajor();
            }
            else if (seed == 6)
            {
                current = new ChemistryMajor();
            }
            else if (seed == 7)
            {
                current = new CJMajor();
            }
            else if (seed == 8)
            {
                current = new CulinaryMajor();
            }
            else
            {
                current = new PsychMajor();
            }
            current.SetRecruitable(false);
            Party.AddEnemy(current);
        }
        return(new TimedMethod[] { new TimedMethod(60, "Log", new object[] { ToString() + "Surrounded themself with minions" }) });
    }
Exemple #29
0
        public IHttpActionResult GetFootballPlayer(int id)
        {
            FootballPlayer footballPlayer = db.footballPlayerDB.Find(id);

            if (footballPlayer == null)
            {
                return(NotFound());
            }

            return(Ok(footballPlayer));
        }
    public override void Enact()
    {
        System.Random rng = new System.Random();
        int           num;

        Character[] enemies = new Character[4];
        enemies[0] = new Expirimentor();
        for (int i = 1; i < 4; i++)
        {
            num = rng.Next(10);
            if (num == 0)
            {
                enemies[i] = new MathMajor();
            }
            else if (num == 1)
            {
                enemies[i] = new EnglishMajor();
            }
            else if (num == 2)
            {
                enemies[i] = new MechanicalEngineer();
            }
            else if (num == 3)
            {
                enemies[i] = new ChemistryMajor();
            }
            else if (num == 4)
            {
                enemies[i] = new FootballPlayer();
            }
            else if (num == 5)
            {
                enemies[i] = new CJMajor();
            }
            else if (num == 6)
            {
                enemies[i] = new PsychMajor();
            }
            else if (num == 7)
            {
                enemies[i] = new CSMajor();
            }
            else if (num == 8)
            {
                enemies[i] = new CulinaryMajor();
            }
            else
            {
                enemies[i] = new BusinessMajor();
            }
        }
        options1 = new LinkedList <TimedMethod>();
        options1.AddLast(new TimedMethod(0, "Battle", new object[] { enemies }));
    }
Exemple #31
0
        public IHttpActionResult PostFootballPlayer(FootballPlayer footballPlayer)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            db.footballPlayerDB.Add(footballPlayer);
            db.SaveChanges();

            return(CreatedAtRoute("DefaultApi", new { id = footballPlayer.id }, footballPlayer));
        }