public IActionResult AssignFouls(FoulInputVM model)
        {
            if (!ModelState.IsValid)
            {
                return(RedirectToAction(nameof(AssignFouls), new { id = model.MatchId, message = 1 }));
            }
            var fouls    = _dataFoul.GetByDetails();
            var lastFoul = fouls.LastOrDefault(x => x.MatchId == model.MatchId);
            var foul     = new Foul
            {
                Minute   = model.Minute,
                MatchId  = model.MatchId,
                Penalty  = model.Penalty,
                PlayerId = model.PlayerId,
                VictimId = model.VictimId
            };

            if (lastFoul == null && model.Minute >= 1 && model.Minute <= 93)
            {
                _dataFoul.Add(foul);
            }
            else if (lastFoul != null && model.Minute >= 1 && model.Minute <= 93 &&
                     model.Minute > lastFoul.Minute)
            {
                _dataFoul.Add(foul);
            }
            else
            {
                return(RedirectToAction(nameof(AssignFouls), new { id = model.MatchId, leagueId = model.LeagueId, message = 1 }));
            }

            return(RedirectToAction(nameof(Index), new { id = model.LeagueId }));
        }
Beispiel #2
0
        private void bNewFoul_Click(object sender, EventArgs e)
        {
            FormPDD formPDD = new FormPDD();

            formPDD.dateTimePicker1.Value = DateTime.Now;
            formPDD.IdFoul         = 0;
            formPDD.IdTypeFoul     = 0;
            formPDD.txtNumber.Text = ""; formPDD.IdReg = 0;

            if (formPDD.ShowDialog() == DialogResult.OK)
            {
                Foul foul = new Foul();
                foul.DtFoul     = formPDD.dateTimePicker1.Value;
                foul.IdTypeFoul = formPDD.IdTypeFoul;
                foul.IdRegistr  = formPDD.IdReg;
                dbContext.NewFoul(foul);
                UpdateListFouls(txtNumber.Text);
            }
        }
Beispiel #3
0
        private void listBoxFouls_DoubleClick(object sender, EventArgs e)
        {
            VFoul   vfoul   = (VFoul)listBoxFouls.SelectedItem;
            FormPDD formPdd = new FormPDD();

            formPdd.dateTimePicker1.Value = vfoul.Date;
            formPdd.IdFoul         = vfoul.Id;
            formPdd.IdReg          = vfoul.IdReg;
            formPdd.IdTypeFoul     = vfoul.IdTypeFoul;
            formPdd.txtNumber.Text = vfoul.Number;
            if (formPdd.ShowDialog() == DialogResult.OK)
            {
                Foul foul = new Foul();
                foul.Id         = vfoul.Id;
                foul.DtFoul     = formPdd.dateTimePicker1.Value;
                foul.IdTypeFoul = formPdd.IdTypeFoul;
                foul.IdRegistr  = formPdd.IdReg;
                dbContext.UpdateFoul(foul);
            }
            UpdateListFouls(txtNumber1.Text);
        }
            public async Task <Unit> Handle(CreateFreeThrowCommand request, CancellationToken cancellationToken)
            {
                var incident = new Incident
                {
                    MatchId      = request.MatchId,
                    Minutes      = request.Minutes,
                    Seconds      = request.Seconds,
                    IncidentType = IncidentType.FOUL,
                    Quater       = request.Quater,
                    Flagged      = request.Flagged
                };

                var foul = new Foul
                {
                    PlayerWhoFouledId    = request.PlayerWhoFouledId,
                    PlayerWhoWasFouledId = request.PlayerWhoWasFouledId,
                    CoachId  = request.CoachId,
                    FoulType = request.FoulType,
                    Incident = incident
                };

                var freeThrow = new Domain.Entities.FreeThrows
                {
                    PlayerShooterId = request.PlayerShooterId,
                    AccurateShots   = request.AccurateShots,
                    Attempts        = request.Attempts,
                    Foul            = foul
                };

                _context.FreeThrow.Add(freeThrow);

                var success = await _context.SaveChangesAsync(cancellationToken) > 0;

                if (success)
                {
                    return(Unit.Value);
                }

                throw new Exception("Problem saving changes");
            }
        public void StartGame()
        {
            try
            {
                Team1.DopingTest();
                Team2.DopingTest();
            }
            catch (GameException e)
            {
                Console.WriteLine(e.Message);
            }
            try
            {
                CheckCountFootballers();
            }
            catch (GameException e)
            {
                Console.WriteLine(e.Message);
                System.Environment.Exit(1);
            }

            Console.WriteLine($"Матч {Team1.Team_name} - {Team2.Team_name} начался!\n{Team1}\n{Team2}\nСудья матча: {Game_referee.Name}");

            for (int i = 0; i < r.Next(3, 6); i++)
            {
                switch ((Events)r.Next(0, 2))
                {
                case Game.Events.Foul:
                    Foul?.Invoke(this, new GameEventArgs("Это фол, неспортивное поведение!\nСудья показывает желтую карточку\n"));
                    break;

                case Game.Events.Goal:
                    Goal?.Invoke(this, new GameEventArgs("Опасный момент... и... ГОООООЛ!\nСудья показывает на центр поля\n"));
                    break;
                }
            }
        }
Beispiel #6
0
        public void FoulEventHasCorrectName()
        {
            var foul = new Foul(0, new Guid(), new Guid());

            Assert.Equal("Foul", foul.Name);
        }
Beispiel #7
0
        public void FoulEventsDoNotAppearInTimeline()
        {
            var foul = new Foul(0, new Guid(), new Guid());

            Assert.False(foul.ShowInTimeline);
        }
            public async Task <int> Handle(CreateFoulCommand request, CancellationToken cancellationToken)
            {
                Match match = await _context.Match
                              .Include(x => x.TeamGuest)
                              .Include(x => x.TeamHome)
                              .FirstOrDefaultAsync(x => x.Id == request.MatchId, cancellationToken);

                TeamMatch teamMatchWhoFouled;
                TeamMatch teamMatchWhoWasFouled;

                if (request.IsGuest)
                {
                    teamMatchWhoFouled    = match.TeamGuest;
                    teamMatchWhoWasFouled = match.TeamHome;
                }
                else
                {
                    teamMatchWhoFouled    = match.TeamHome;
                    teamMatchWhoWasFouled = match.TeamGuest;
                }

                switch (request.Quater)
                {
                case 1:
                    teamMatchWhoFouled.Fouls1Qtr++;
                    break;

                case 2:
                    teamMatchWhoFouled.Fouls2Qtr++;
                    break;

                case 3:
                    teamMatchWhoFouled.Fouls3Qtr++;
                    break;

                case 4:
                    teamMatchWhoFouled.Fouls4Qtr++;
                    break;
                }

                var incident = new Incident
                {
                    MatchId      = request.MatchId,
                    Minutes      = request.Minutes,
                    Seconds      = request.Seconds,
                    IncidentType = IncidentType.FOUL,
                    Quater       = request.Quater,
                    Flagged      = request.Flagged,
                    IsGuest      = request.IsGuest
                };

                var playerMatchWhoFouled = await _context.PlayerMatch.Include(x => x.PlayerSeason).FirstOrDefaultAsync(
                    x => x.PlayerSeason.PlayerId == request.PlayerWhoFouledId && x.MatchId == request.MatchId, cancellationToken);

                var playerMatchWhoWasFouled = await _context.PlayerMatch.Include(x => x.PlayerSeason).FirstOrDefaultAsync(
                    x => x.PlayerSeason.PlayerId == request.PlayerWhoWasFouledId && x.MatchId == request.MatchId, cancellationToken);

                if (playerMatchWhoFouled == null)
                {
                    var playerSeason =
                        await _context.PlayerSeason.FirstOrDefaultAsync(x => x.PlayerId == request.PlayerWhoFouledId,
                                                                        cancellationToken);

                    playerMatchWhoFouled = new PlayerMatch
                    {
                        PlayerSeasonId = playerSeason.Id, MatchId = request.MatchId
                    };
                    _context.PlayerMatch.Add(playerMatchWhoFouled);
                }

                if (playerMatchWhoWasFouled == null)
                {
                    var playerSeason =
                        await _context.PlayerSeason.FirstOrDefaultAsync(x => x.PlayerId == request.PlayerWhoWasFouledId,
                                                                        cancellationToken);

                    playerMatchWhoWasFouled = new PlayerMatch
                    {
                        PlayerSeasonId = playerSeason.Id, MatchId = request.MatchId
                    };
                    _context.PlayerMatch.Add(playerMatchWhoWasFouled);
                }


                if (request.FoulType == FoulType.OFFENSIVE)
                {
                    playerMatchWhoFouled.OffFouls++;
                    teamMatchWhoFouled.OffFouls++;
                }
                playerMatchWhoFouled.Fouls++;
                teamMatchWhoFouled.Fouls++;


                var foul = new Foul
                {
                    PlayerWhoFouledId    = request.PlayerWhoFouledId,
                    PlayerWhoWasFouledId = request.PlayerWhoWasFouledId,
                    CoachId  = request.CoachId,
                    FoulType = request.FoulType,
                    Incident = incident
                };

                if (request.AccurateShots.HasValue && request.Attempts.HasValue)
                {
                    teamMatchWhoWasFouled.Fta += request.Attempts.Value;
                    teamMatchWhoWasFouled.Ftm += request.AccurateShots.Value;

                    playerMatchWhoWasFouled.Fta += request.Attempts.Value;
                    playerMatchWhoWasFouled.Ftm += request.AccurateShots.Value;

                    var freeThrow = new Domain.Entities.FreeThrows
                    {
                        AccurateShots   = request.AccurateShots.Value,
                        Attempts        = request.Attempts.Value,
                        Foul            = foul,
                        PlayerShooterId = request.PlayerWhoWasFouledId.Value
                    };

                    _context.FreeThrow.Add(freeThrow);

                    if (request.PlayerAssistId.HasValue)
                    {
                        var assist = new Assist {
                            FreeThrows = freeThrow, PlayerId = request.PlayerAssistId.Value
                        };

                        var playerMatchAssist = await _context.PlayerMatch.Include(x => x.PlayerSeason).FirstOrDefaultAsync(
                            x => x.PlayerSeason.PlayerId == request.PlayerAssistId && x.MatchId == request.MatchId, cancellationToken);

                        if (playerMatchAssist == null)
                        {
                            var playerSeason =
                                await _context.PlayerSeason.FirstOrDefaultAsync(x => x.PlayerId == request.PlayerAssistId,
                                                                                cancellationToken);

                            playerMatchAssist = new PlayerMatch
                            {
                                PlayerSeasonId = playerSeason.Id, MatchId = request.MatchId
                            };
                            _context.PlayerMatch.Add(playerMatchAssist);
                        }

                        playerMatchAssist.Ast++;
                        teamMatchWhoWasFouled.Ast++;

                        _context.Assist.Add(assist);
                    }

                    if (request.PlayerReboundId.HasValue || request.TeamReboundId.HasValue)
                    {
                        var rebound = new Rebound
                        {
                            FreeThrows  = freeThrow,
                            ReboundType = request.ReboundType.Value
                        };


                        if (request.PlayerReboundId.HasValue)
                        {
                            rebound.PlayerId = request.PlayerReboundId.Value;

                            var playerMatchRebound = await _context.PlayerMatch.Include(x => x.PlayerSeason).FirstOrDefaultAsync(
                                x => x.PlayerSeason.PlayerId == request.PlayerReboundId && x.MatchId == request.MatchId, cancellationToken);

                            if (playerMatchRebound == null)
                            {
                                var playerSeason =
                                    await _context.PlayerSeason.FirstOrDefaultAsync(x => x.PlayerId == request.PlayerReboundId,
                                                                                    cancellationToken);

                                playerMatchRebound = new PlayerMatch
                                {
                                    PlayerSeasonId = playerSeason.Id, MatchId = request.MatchId
                                };
                                _context.PlayerMatch.Add(playerMatchRebound);
                            }

                            if (request.ReboundType == Domain.Common.ReboundType.PLAYER_DEF)
                            {
                                playerMatchRebound.Drb++;
                                teamMatchWhoFouled.Drb++;
                            }
                            else
                            {
                                playerMatchRebound.Orb++;
                                teamMatchWhoWasFouled.Orb++;
                            }
                        }
                        else
                        {
                            rebound.TeamId = request.TeamReboundId.Value;

                            if (request.ReboundType == Domain.Common.ReboundType.TEAM_DEF)
                            {
                                teamMatchWhoFouled.Drb++;
                            }
                            else
                            {
                                teamMatchWhoWasFouled.Orb++;
                            }
                        }

                        _context.Rebound.Add(rebound);
                    }
                }

                _context.Foul.Add(foul);



                var success = await _context.SaveChangesAsync(cancellationToken) > 0;

                if (success)
                {
                    return(incident.Id);
                }

                throw new Exception("Problem saving changes");
            }
Beispiel #9
0
        public void StartMatch()
        {
            footballReferee = new FootballReferee("Best referee");
            Foul           += footballReferee.RefereeFoulHandler;
            Goal           += footballReferee.RefereeGoalHandler;
            int firstTeamFouls  = 0;
            int secondTeamFouls = 0;

            int[] score = { 0, 0 };
            Console.WriteLine("Match Started!");
            Thread.Sleep(350);
            for (int i = 0; i < 90; i++)
            {
                Thread.Sleep(350);
                Console.WriteLine($"{i} minutes of match");
                if (Resourses.MyRandom.Next(0, 90) < 5)
                {
                    int firstTeamChanseToGoal  = Resourses.MyRandom.Next(0, (int)FirstFootballTeam.TeamMastery - firstTeamFouls);
                    int secondTeamChanseToGoal = Resourses.MyRandom.Next(0, (int)SecondFootballTeam.TeamMastery - secondTeamFouls);
                    if (firstTeamChanseToGoal > secondTeamChanseToGoal)
                    {
                        Goal?.Invoke(FirstFootballTeam);
                        score[0] += 1;
                        continue;
                    }
                    else
                    {
                        Goal?.Invoke(SecondFootballTeam);
                        score[1] += 1;
                        continue;
                    }
                }
                if (Resourses.MyRandom.Next(0, 90) < 4)
                {
                    if (Resourses.MyRandom.Next(0, 100) < 50)
                    {
                        if (Foul?.Invoke(FirstFootballTeam, 1) == true)
                        {
                            firstTeamFouls += 65;
                        }
                    }
                    else
                    {
                        if (Foul?.Invoke(SecondFootballTeam, 2) == true)
                        {
                            secondTeamFouls += 65;
                        }
                    }
                }
            }
            if (score[0] > score[1])
            {
                Console.WriteLine($"Team {FirstFootballTeam.Name} wins with score {score[0]} : {score[1]}");
            }
            else if (score[0] < score[1])
            {
                Console.WriteLine($"Team {SecondFootballTeam.Name} wins with score {score[1]} : {score[0]}");
            }
            else
            {
                Console.WriteLine("Match was ended with draw");
            }
        }