Exemplo n.º 1
0
            protected override async Task Given()
            {
                var gamesUrl   = "games";
                var jsonStream =
                    new FileStreamBuilder()
                    .WithFileResourceName("get_game_report_new_game.json")
                    .Build();

                var localTeamCode   = "RMD";
                var foreignTeamCode = "FCB";

                var content =
                    new StringContentBuilder()
                    .WithContent(jsonStream)
                    .WithPlaceholderReplacement("local_team_code", localTeamCode)
                    .WithPlaceholderReplacement("foreign_team_code", foreignTeamCode)
                    .Build();

                var resultPost = await HttpClient.PostAsync(gamesUrl, content);

                // ReSharper disable once PossibleNullReferenceException
                var locationUrlParts = resultPost.Headers.Location.ToString().Split('/');
                var idPart           = locationUrlParts.Single(x => Guid.TryParse(x, out _));

                _id = new Guid(idPart);

                _expectedGameReport = new GameReport(_id, localTeamCode, 0, foreignTeamCode, 0);
            }
Exemplo n.º 2
0
 public void AddReport(GameReport report)
 {
     VerifyAccess();
     if (ReportReceived != null)
     {
         ReportReceived(report);
     }
 }
Exemplo n.º 3
0
            protected override void Given()
            {
                _sut = new GameToGameReportMapper();

                var id = Guid.Empty;

                _game = new Game(id);
                _expectedGameReport = new GameReport(id, null !, 0, null !, 0);
            }
Exemplo n.º 4
0
            private GameReport _expectedGameReport; //plantilla de informe de partido

            protected override void Given()
            {
                _sut = new GameToGameReportMapper();                            //inicializamos el mapeador

                var id = Guid.Empty;                                            //declaramos una id

                _game = new Game(id);                                           //creamos un nuevo partido con la id vacio
                _expectedGameReport = new GameReport(id, null !, 0, null !, 0); //inicalizamos el informe
            }
        public void AddGoal(Guid id, NewGoal newGoal)
        {
            var game = _gamesRepository.GetGame(id);//obtenemos el partido mediante la id


            GameToGameReportMapper mapeador     = new GameToGameReportMapper();
            GameReport             report       = mapeador.Map(game);
            ReporteGoles           reporteGoles = new ReporteGoles(report);



            var currentDate = _dateTimeService.GetUtcNow();     //establecemos la fecha actual del partido

            var teamCode = newGoal.TeamCode;                    //obtenemos el nombre del equipo

            var goal = new Goal(currentDate, newGoal.ScoredBy); //creamos un goal con la fecha actual del gol
            //, y scoreby quien marco (nombre del jugador)

            var isTeamPlaying = game.LocalTeamCode == teamCode || game.ForeignTeamCode == teamCode;


            if (!isTeamPlaying)//si no esta jugando
            {
                throw new ResourceNotFoundException($"The team code {teamCode} is not playing the game");
            }

            if (game.LocalTeamCode == teamCode) //si el juego el quipoLocal  es igual al teamcode
            {
                game.AddLocalTeamGoal(goal);    //agregamos al juego los goal que han marcado si pertenece a ese equipo
                                                //
                reporteGoles.añadirGoles(newGoal, goal);
            }
            else
            {
                game.AddForeignTeamGoal(goal);//se lo metemos al equipo adversario

                reporteGoles.añadirGoles(newGoal, goal);
            }

            _gamesRepository.UpdateGame(id, game);//actualizamos la base de datos con la id y game

            //actualizamos el reporte de la clase pivote

            mapeador = new GameToGameReportMapper();
            Game       juegoFinal   = _gamesRepository.GetGame(id);
            GameReport reporteFinal = mapeador.Map(juegoFinal);

            reporteGoles = new ReporteGoles(report);

            _gamesRepository.AddReporteGoles(juegoFinal, reporteGoles);
            //
        }
Exemplo n.º 6
0
    public int MyTurn()
    {
        GameManager gameManager = GameManager.instance;
        int         currentturn = gameManager.turn;

        if (mynumber == 1)
        {
            currenstatus = new GameReport(currentturn, GameManager.instance.player1.hand, GameManager.instance.ground, gameManager.player1.under, gameManager.player2.under);
        }
        else if (mynumber == 2)
        {
            currenstatus = new GameReport(currentturn, gameManager.player2.hand, gameManager.ground, gameManager.player2.under, gameManager.player1.under);
        }
        int output = -1;

        for (int index = 0; index < hubos[currentturn].Count; index++)
        {
            GameReport gameReport = hubos[currentturn][index];
            if (Same(gameReport.myhand, currenstatus.myhand) && gameReport.ground.Same(currenstatus.ground) && gameReport.myown.Same(currenstatus.myown) && gameReport.enemyown.Same(currenstatus.enemyown))
            {
                float rate = 1f;
                for (int i = 0; i < gameReport.statisticsaboutselection.Count && i < currenstatus.myhand.Count; i++)
                {
                    List <int> winlose   = gameReport.statisticsaboutselection[i];
                    int        numofwin  = winlose[0];
                    int        numoflose = winlose[1];
                    if (numofwin + numoflose != 0 && rate > (float)(numoflose / (numofwin + numoflose)))
                    {
                        output = i;
                        rate   = (numoflose / (numofwin + numoflose));
                    }
                    else if (numofwin + numoflose == 0 && rate > 0.5f)
                    {
                        output = i;
                        rate   = 0.5f;
                    }
                }
                selectroute[currentturn] = new Vector2Int(index, output);
            }
        }
        if (output == -1)
        {
            output = 0;
            hubos[currentturn].Add(currenstatus);
            selectroute[currentturn] = new Vector2Int(hubos[currentturn].Count - 1, output);
        }
        return(output);
    }
Exemplo n.º 7
0
        void HandleReport(GameReport report)
        {
            if (report is LivingReport)
            {
                var r = (LivingReport)report;

                if (Sees((EnvironmentObject)r.Living.Environment, r.Living.Location))
                {
                    Send(new ReportMessage()
                    {
                        Report = report
                    });
                }
            }
            else
            {
                Send(new ReportMessage()
                {
                    Report = report
                });
            }
        }
Exemplo n.º 8
0
 public void AddReport(GameReport report)
 {
     VerifyAccess();
     if (ReportReceived != null)
         ReportReceived(report);
 }
Exemplo n.º 9
0
        void HandleReport(GameReport report)
        {
            if (report is LivingReport)
            {
                var r = (LivingReport)report;

                if (Sees((EnvironmentObject)r.Living.Environment, r.Living.Location))
                    Send(new ReportMessage() { Report = report });
            }
            else
            {
                Send(new ReportMessage() { Report = report });
            }
        }
Exemplo n.º 10
0
 public ReporteGoles(GameReport report)
 {
     this.report          = report;
     this.golesAdversario = new List <Goal>();
     this.golesLocales    = new List <Goal>();
 }
        /**
         * Funcion donde le pasamos un game y le devuelve un GameReport
         */
        public GameReport Map(Game game)
        {
            GameReport informe = new GameReport(game.Id, game.LocalTeamCode, game.LocalGoals.Count, game.ForeignTeamCode, game.ForeignGoals.Count);

            return(informe);
        }
Exemplo n.º 12
0
 protected override void When()
 {
     _result = _sut.Map(_game);
 }
Exemplo n.º 13
0
        private void MainForm_FormClosing(System.Object sender, System.Windows.Forms.FormClosingEventArgs e)
        {
            try
            {
                if (ProcessManagement.ProcessIsRunning(File.ReadAllText(Core.AppPath + "chosengameexec.txt")))
                {
                    int gameclosedtimestamp = TextHandling.GetUnixTimestamp();

                    GameReport report = new GameReport();

                    report.WriteLine("Anticheat closed while game was running! at " + DateTime.Now.TimeOfDay + " timestamp: " + gameclosedtimestamp + Environment.NewLine + "On match ID: " + getID + Environment.NewLine);

                    File.WriteAllText(Core.AppPath + "acscreens\\gameclosed.txt", report.toFile());

                    try
                    {
                        FileManagement fm = new FileManagement();
                        fm.postFile(username, null, null, Core.AppPath + "acscreens\\gameclosed.txt");
                    }

                    catch (Exception)
                    {
                        ReportForm ef = new ReportForm();
                        ef.label2.Text = "Upload failed.";
                        ef.Show();
                    }

                    File.Delete(Core.AppPath + "acscreens\\gameclosed.txt");

                    string grabName;
                    grabName = File.ReadAllText(Core.AppPath + "chosengameexec.txt");
                    string grabProc;
                    grabProc = grabName;
                    grabProc = grabProc.Substring(0, grabProc.Length - 4);

                    RuntimeChecker.IsGameRunning(grabProc);
                    ProcessManagement.TriggerTaskmanager(true);

                    notifyIcon1.Visible = false;

                    Environment.Exit(0);
                }
            }

            catch (FileNotFoundException)
            {
                /* user does not need to know about this error */
                try
                {
                    string grabName;
                    grabName = File.ReadAllText(Core.AppPath + "chosengameexec.txt");
                    string grabProc;
                    grabProc = grabName;
                    grabProc = grabProc.Substring(0, grabProc.Length - 4);

                    RuntimeChecker.IsGameRunning(grabProc);
                    ProcessManagement.TriggerTaskmanager(true);
                    notifyIcon1.Visible = false;
                    Environment.Exit(0);
                }
                catch (Exception)
                {
                    ProcessManagement.TriggerTaskmanager(true);
                    notifyIcon1.Visible = false;
                    Environment.Exit(0);
                }
            }
            ProcessManagement.TriggerTaskmanager(true);
            notifyIcon1.Visible = false;
            Environment.Exit(0);
        }