Exemplo n.º 1
0
        void StartGame()
        {
            foreach (var source in _sources)
            {
                source.Value.Dragg   += OnDragg;
                source.Value.Drop    += OnDrop;
                source.Value.Capture += OnCapture;
                source.Value.Color    = GetColor(false, source.Value.Color);
            }

            foreach (var receiver in _receivers)
            {
                receiver.Value.Color = GetColor(true, receiver.Value.Color);
            }

            Scores = 0;
            _uiScore.SetBestScores(BestScores.ToString());
            _time = _config.Timer;
            _tickable.SecondTick += OnSecondTick;

            foreach (var v in _receiverProgresses)
            {
                v.Value.Start();
            }
        }
Exemplo n.º 2
0
        private void UpdateScorePercent()
        {
            var highScore = Math.Max(score, Math.Max(userHighScore, webHighScore));

            ScorePercent         = String.Format("{0}*", (float)score / highScore);
            ScoreWhitePercent    = String.Format("{0}*", (float)(highScore - score) / highScore);
            UserHighScorePercent = String.Format("{0}*", (float)userHighScore / highScore);
            if (BestScores != null && BestScores.Count > 0)
            {
                KeyValuePair <DateTime, int> best;
                try
                {
                    best = BestScores.First(p => p.Key >= baseTime.AddSeconds(lastTime - currentScoreInfo.StartTime));
                }
                catch
                {
                    best = new KeyValuePair <DateTime, int>(DateTime.Now, userHighScore);
                }
                UserHighScoreRealTimePercent      = String.Format("{0}*", (float)best.Value / userHighScore);
                UserHighScoreRealTimeWhitePercent = String.Format("{0}*", (float)(userHighScore - best.Value) / userHighScore);
                RealTimeScoreDiff = score - best.Value;
            }
            else
            {
                UserHighScoreRealTimePercent      = "1*";
                userHighScoreRealTimeWhitePercent = "0*";
                RealTimeScoreDiff = score - userHighScore;
            }
            UserHighScoreWhitePercent    = String.Format("{0}*", (float)(highScore - userHighScore) / highScore);
            WebHighScorePercent          = String.Format("{0}*", (float)webHighScore / highScore);
            WebHighScoreWhitePercent     = String.Format("{0}*", (float)(highScore - webHighScore) / highScore);
            HighScoreScoreDiff           = score - Math.Max(userHighScore, webHighScore);
            IsHighScoreScoreDiffNegative = HighScoreScoreDiff < 0;
            IsRealTimeScoreDiffNagative  = RealTimeScoreDiff < 0;
        }
        private void LoadBestScores()
        {
            BestScores scores = new BestScores();
            XDocument  doc    = new XDocument();

            string pathfile = GetPathFile(Dificuldade.Facil);

            if (pathfile != null)
            {
                doc = XDocument.Load(pathfile);
                Program.M_BestScores.EasyBestScore = GetBestScore(doc);
            }

            pathfile = GetPathFile(Dificuldade.Medio);
            if (pathfile != null)
            {
                doc = XDocument.Load(pathfile);
                Program.M_BestScores.MediumBestScore = GetBestScore(doc);
            }

            pathfile = GetPathFile(Dificuldade.Dificil);
            if (pathfile != null)
            {
                doc = XDocument.Load(pathfile);
                Program.M_BestScores.HardBestScore = GetBestScore(doc);
            }
        }
Exemplo n.º 4
0
        //public ControllerMineSweeperGameCode C_MineSweeperGame { get; set; }
        //public ControllerLeaderBoard C_LeaderBoard { get; set; }
        //public ControllerOptions C_OptionsForm { get; set; }
        //public ControllerRegister C_RegisterForm { get; set; }
        //public ControllerLogin C_LoginPage { get; set; }

        //public ControllerSearchUser C_SearchPage { get; set; }

        // Controllers

        //public static FormVencedor V_Vencedor { get; private set; }
        //public static GameController C_Master { get; private set; }

        /// <summary>
        /// Initializes the singleton application object.  This is the first line of authored code
        /// executed, and as such is the logical equivalent of main() or WinMain().
        /// </summary>
        public App()
        {
            this.InitializeComponent();
            this.Suspending += OnSuspending;

            M_Grelha     = new TileGrid();
            M_Status     = new ConnectionToServer();
            M_Options    = new Options();
            M_BestScores = new BestScores();

            // class que vai permitir a reprodução de audio
            SoundPlayer = new SoundEffects();

            C_Master = new GameController();
        }
Exemplo n.º 5
0
    public bool Add_ExistingScores_Adds(int existingScores, uint moves, int expectedIndex)
    {
        var bestScores = new BestScores();

        for (uint i = 0; i < existingScores; i++)
        {
            bestScores.Add(new Score {
                Name = i.ToString(), Moves = i + 1, Timer = new TimeSpan(0, 1, 2, 3)
            });
        }
        var score = new Score {
            Name = "Dmitrik", Moves = moves, Timer = new TimeSpan(0, 0, 1, 30)
        };

        bestScores.Add(score);

        return(bestScores.Scores[expectedIndex] == score);
    }
Exemplo n.º 6
0
    public void CanBeAdded_NotOneOfTheBestScores_DoesntAddScore()
    {
        // Best scores
        var bestScores = new BestScores();

        bestScores.Add(new Score {
            Name = "A", Moves = 1, Timer = new TimeSpan(0, 0, 10, 25)
        });
        bestScores.Add(new Score {
            Name = "A", Moves = 2, Timer = new TimeSpan(0, 0, 10, 25)
        });
        bestScores.Add(new Score {
            Name = "A", Moves = 3, Timer = new TimeSpan(0, 0, 10, 25)
        });
        bestScores.Add(new Score {
            Name = "A", Moves = 4, Timer = new TimeSpan(0, 0, 10, 25)
        });
        bestScores.Add(new Score {
            Name = "A", Moves = 5, Timer = new TimeSpan(0, 0, 10, 25)
        });
        bestScores.Add(new Score {
            Name = "A", Moves = 6, Timer = new TimeSpan(0, 0, 10, 25)
        });
        bestScores.Add(new Score {
            Name = "A", Moves = 7, Timer = new TimeSpan(0, 0, 10, 25)
        });
        bestScores.Add(new Score {
            Name = "A", Moves = 8, Timer = new TimeSpan(0, 0, 10, 25)
        });
        bestScores.Add(new Score {
            Name = "A", Moves = 9, Timer = new TimeSpan(0, 0, 10, 25)
        });
        bestScores.Add(new Score {
            Name = "A", Moves = 10, Timer = new TimeSpan(0, 0, 10, 25)
        });
        // New score
        var score = new Score {
            Name = "Dmitrik", Moves = 11, Timer = new TimeSpan(0, 0, 10, 25)
        };

        bool actual = bestScores.CanBeAdded(score);

        Assert.That(actual, Is.False);
    }
    public void Save_10BestScores_Saves()
    {
        var bestScores = new BestScores();

        bestScores.Add(new Score {
            Name = "Aaaaaaaaaa", Moves = 92, Timer = new TimeSpan(0, 0, 11, 25)
        });
        bestScores.Add(new Score {
            Name = "Bbbbbbbbb", Moves = 102, Timer = new TimeSpan(0, 0, 12, 25)
        });
        bestScores.Add(new Score {
            Name = "Cccccc", Moves = 103, Timer = new TimeSpan(0, 0, 13, 25)
        });
        bestScores.Add(new Score {
            Name = "Dmitrik", Moves = 124, Timer = new TimeSpan(0, 0, 14, 25)
        });
        bestScores.Add(new Score {
            Name = "Eeeeee", Moves = 135, Timer = new TimeSpan(0, 0, 15, 25)
        });
        bestScores.Add(new Score {
            Name = "Ffffffffffff", Moves = 146, Timer = new TimeSpan(0, 0, 16, 25)
        });
        bestScores.Add(new Score {
            Name = "Gggg", Moves = 147, Timer = new TimeSpan(0, 1, 17, 25)
        });
        bestScores.Add(new Score {
            Name = "Hhhhhhh", Moves = 158, Timer = new TimeSpan(0, 1, 18, 25)
        });
        bestScores.Add(new Score {
            Name = "Iiiiiiii", Moves = 159, Timer = new TimeSpan(0, 1, 19, 25)
        });
        bestScores.Add(new Score {
            Name = "Jjjjjjj", Moves = 200, Timer = new TimeSpan(0, 1, 20, 25)
        });

        var bestScoresStoragePath = $"{AppDomain.CurrentDomain.BaseDirectory}\\{Options.BestScoresStorageFileName}";

        new BestScoresStorage(bestScoresStoragePath).Save(bestScores);
        bool actual = File.Exists(bestScoresStoragePath);

        Assert.That(actual, Is.True);
    }
Exemplo n.º 8
0
        private static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);

            // Model
            M_Grelha     = new TileGrid();
            M_Status     = new ConnectionToServer();
            M_Options    = new Options();
            M_BestScores = new BestScores();

            // View
            V_StartForm       = new FormStart();
            V_MineSweeperGame = new FormMinesweeper();
            V_Login           = new FormLogin();
            V_Register        = new FormRegister();
            V_Vencedor        = new FormVencedor();

            // Controlador
            C_Master = new GameController();

            Application.Run(V_StartForm);
        }
Exemplo n.º 9
0
        static void Main()
        {
            Console.WriteLine(@"

  ___  __ )____________________  /_    ___  /___________ _______ ____  ______ 
  __  __  |  __ \  __ \_  ___/  __/    __  / _  _ \  __ `/_  __ `/  / / /  _ \
  _  /_/ // /_/ / /_/ /(__  )/ /_      _  /__/  __/ /_/ /_  /_/ // /_/ //  __/
  /_____/ \____/\____//____/ \__/      /_____|___/\__,_/ _\__, / \__,_/ \___/ 
                                                         /____/               

                    @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
                    @@@@@@@@@@@@@@@@@@%//////////@@@@@@@@@@@
                    @%))))))))@((((((((@@//////////%@@@@@@@@
                    @@@)))))))))@((((((((@@(/////////(&@@@@@
                    @@@@@&))))))))@@((((((((@@//////////#@@@
                    @@@@@@@@)))))))))@(((((((((@///////////&
                    @@@@@@%))))))))@@(((((((((@(//////////%@
                    @@@@)))))))))@@((((((((@@//////////(@@@@
                    @@%)))))))@@(((((((((@(//////////%@@@@@@
                    @@@@@@@@@#((((((((@@(/////////#@@@@@@@@@
                    @@@@@@@@@@@@@@@@@@@&&&&&&&&&&@@@@@@@@@@@

");

            // Load data
            string            root = "";
            List <Record>     allData;
            int               allMdCount;
            List <(int, int)> yearMdCounts;

            try
            {
                (allData, allMdCount, yearMdCounts) = DataReader.ReadLogs(root);
            }
            catch (Exception e)
            {
                Console.WriteLine(
                    "Error loading data!\n" + e.Message + "\n" +
                    "Press any key to close this window...");
                Console.ReadKey();
                return;
            }
            Console.WriteLine(
                "Data loaded successfully!\n" +
                "Press any key to continue...");
            Console.ReadKey();

            var watch = System.Diagnostics.Stopwatch.StartNew();

            // Generate results
            Console.WriteLine("\nGenerating results...");

            int matchday = 0;
            Dictionary <int, Dictionary <Map, Dictionary <ulong, Record> > > mdToMapToSteamIdToRec = Indexing.MdToMapToSteamIdToRecord(allData);
            Dictionary <int, Dictionary <Map, List <Record> > > mdToMapToRecs = Indexing.MdToMapToRecords(allData, mergeRoAs: false);

            // cumulative data for calculating points
            Dictionary <Map, List <Record> > mapToCRecs = new();
            Dictionary <Map, Dictionary <ulong, List <Record> > > mapToSteamIdToCRecs = new();

            // cumulative data for yearly/all-time summary
            Dictionary <Map, Dictionary <ulong, Record> > playerBestScores = new();
            Dictionary <Map, List <Record> > bestScoreProgression          = new();
            IEnumerable <ulong> lastMatchdaySteamIds = null;

            foreach ((int, int)yearMdCount in yearMdCounts)  // (year, matchday count)
            {
                Dictionary <ulong, PlayerSummary> yearSummary = new();
                for (int i = 0; i < yearMdCount.Item2; i++)
                {
                    string matchdayDir = root + yearMdCount.Item1 + "/MD#" + ++matchday;

                    // Matchday points
                    PointSystem.AddAndCalcPoints(mdToMapToRecs[matchday], mapToCRecs, mapToSteamIdToCRecs);

                    // Matchday details table
                    Console.WriteLine(matchdayDir + "/MD#" + matchday + "_Details.txt");
                    List <Dictionary <ulong, Record> > results = Details.OrderedMapResults(mdToMapToSteamIdToRec[matchday]);
                    Table details = Details.MakeDetailsTable(results, 4);
                    details.ToFile(matchdayDir + "/MD#" + matchday + "_Details.txt");

                    // Matchday summary table (points)
                    Console.WriteLine(matchdayDir + "/MD#" + matchday + "_Summary_Points.txt");
                    Dictionary <ulong, PlayerSummary> matchdaySummary = Summary.SingleMatchdaySummary(results);
                    Table summaryPoints = Summary.MakeSummaryTable(matchdaySummary, usePoints: true);
                    summaryPoints.ToFile(matchdayDir + "/MD#" + matchday + "_Summary_Points.txt");

                    // Matchday summary table (positions)
                    Console.WriteLine(matchdayDir + "/MD#" + matchday + "_Summary_Positions.txt");
                    Table summaryPositions = Summary.MakeSummaryTable(matchdaySummary, usePoints: false);
                    summaryPositions.ToFile(matchdayDir + "/MD#" + matchday + "_Summary_Positions.txt");

                    // Update yearly and all-time results
                    Summary.UpdateMuitiMatchdaySummary(yearSummary, matchdaySummary);
                    BestScores.UpdatePlayerBestScores(playerBestScores, results, calcOldRanks: matchday == allMdCount, calcNewRanks: matchday == allMdCount);
                    BestScores.UpdateBestScoreProgression(bestScoreProgression, results);
                    if (matchday == allMdCount)                      // most recent matchday
                    {
                        lastMatchdaySteamIds = matchdaySummary.Keys; // for the best scores summary
                        Summary.CalculateOldRanks(yearSummary);
                        Summary.ShowDeltas(yearSummary, lastMatchdaySteamIds, pointDelta: false, rankDelta: true);
                    }
                    if (i == yearMdCount.Item2 - 1) // last matchday of the year
                    {
                        Summary.CalculateRanks(yearSummary);
                    }
                }

                string yearDir = root + yearMdCount.Item1;

                // Yearly summary table (points)
                Console.WriteLine(yearDir + "/" + yearMdCount.Item1 + "_Summary_Points.txt");
                Table yearSummaryPoints = Summary.MakeSummaryTable(yearSummary, frequencyData: true, summaryName: yearMdCount.Item1 + " LEADERBOARD", usePoints: true);
                yearSummaryPoints.ToFile(yearDir + "/" + yearMdCount.Item1 + "_Summary_Points.txt");

                // Yearly summary table (positions)
                Console.WriteLine(yearDir + "/" + yearMdCount.Item1 + "_Summary_Positions.txt");
                Table yearSummaryPositions = Summary.MakeSummaryTable(yearSummary, frequencyData: true, summaryName: yearMdCount.Item1 + " LEADERBOARD", usePoints: false);
                yearSummaryPositions.ToFile(yearDir + "/" + yearMdCount.Item1 + "_Summary_Positions.txt");
            }


            // All-time best score details table
            Console.WriteLine(root + "AllTime_BestScores_Details.txt");
            List <Dictionary <ulong, Record> > bestScoreResults = Details.OrderedMapResults(playerBestScores, updatePositions: false);
            Table bestScoresDetails = Details.MakeDetailsTable(bestScoreResults, eventsPerRow: 4, nResults: 20, showMatchdays: false, showPositions: true, showPosDeltas: true, showPoints: false, showBonus: false);

            bestScoresDetails.ToFile(root + "AllTime_BestScores_Details.txt");

            // All-time best score summary table
            Console.WriteLine(root + "AllTime_BestScores_Summary.txt");
            Dictionary <ulong, PlayerSummary> bestScoresSummary = BestScores.PlayerBestScoresSummary(bestScoreResults, nPositions: 20);

            Summary.CalculateRanks(bestScoresSummary);
            Summary.CalculateOldRanks(bestScoresSummary);
            Summary.ShowDeltas(bestScoresSummary, lastMatchdaySteamIds, pointDelta: true, rankDelta: true);
            Table bestScoresSummaryPositions = Summary.MakeSummaryTable(bestScoresSummary, "Overall Ranks", frequencyData: true, usePoints: false);

            bestScoresSummaryPositions.ToFile(root + "AllTime_BestScores_Summary.txt");

            // All-time best score progress table
            Console.WriteLine(root + "AllTime_BestScores_Progress.txt");
            List <List <Record> > bestProgressionResults = Details.OrderedMapResults(bestScoreProgression, recordComp: Record.CompareScores);
            Table bestScoresProgressionDetails           = Details.MakeDetailsTable(bestProgressionResults, eventsPerRow: 4, showMatchdays: true, showPositions: false, showPoints: false, showBonus: false);

            bestScoresProgressionDetails.ToFile(root + "AllTime_BestScores_Progress.txt");

            // Test tables
            //Dictionary<ulong, Dictionary<Map, List<Record>>> recsByPlayer = Indexing.SteamIdMapToRecords(allData, mergeRoAs: false);
            //Table testTable = Details.MakeDetailsTable(recsByPlayer[76561198347259925].Values, eventsPerRow: 23, showPositions: false);
            //testTable.ToFile("piero.txt");

            // Bonus info

            /*
             * decimal total = 0;
             * foreach (Record rec in allData)
             * {
             *  total += rec.Bonus;
             * }
             * Console.WriteLine("Bonus average: " + total / allData.Count);
             */

            watch.Stop();
            Console.WriteLine(@"
______________       _____       ______      ______________
___  ____/__(_)_________(_)_________  /____________  /__  /
__  /_   __  /__  __ \_  /__  ___/_  __ \  _ \  __  /__  / 
_  __/   _  / _  / / /  / _(__  )_  / / /  __/ /_/ /  /_/  
/_/      /_/  /_/ /_//_/  /____/ /_/ /_/\___/\__,_/  (_)    

Time taken: " + watch.ElapsedMilliseconds / 1000d + " seconds!");
            Console.WriteLine("Press any key to close this window...");
            Console.ReadKey();
        }
    public void Load_10BestScores_Loads()
    {
        var bestScores = new BestScores();

        bestScores.Add(new Score {
            Name = "Aaaaaaaaaa", Moves = 92, Timer = new TimeSpan(0, 0, 11, 25)
        });
        bestScores.Add(new Score {
            Name = "Bbbbbbbbb", Moves = 102, Timer = new TimeSpan(0, 0, 12, 25)
        });
        bestScores.Add(new Score {
            Name = "Cccccc", Moves = 103, Timer = new TimeSpan(0, 0, 13, 25)
        });
        bestScores.Add(new Score {
            Name = "Dmitrik", Moves = 124, Timer = new TimeSpan(0, 0, 14, 25)
        });
        bestScores.Add(new Score {
            Name = "Eeeeee", Moves = 135, Timer = new TimeSpan(0, 0, 15, 25)
        });
        bestScores.Add(new Score {
            Name = "Ffffffffffff", Moves = 146, Timer = new TimeSpan(0, 0, 16, 25)
        });
        bestScores.Add(new Score {
            Name = "Gggg", Moves = 147, Timer = new TimeSpan(0, 1, 17, 25)
        });
        bestScores.Add(new Score {
            Name = "Hhhhhhh", Moves = 158, Timer = new TimeSpan(0, 1, 18, 25)
        });
        bestScores.Add(new Score {
            Name = "Iiiiiiii", Moves = 159, Timer = new TimeSpan(0, 1, 19, 25)
        });
        bestScores.Add(new Score {
            Name = "Jjjjjjj", Moves = 200, Timer = new TimeSpan(0, 1, 20, 25)
        });

        var bestScoresStoragePath = $"{AppDomain.CurrentDomain.BaseDirectory}\\{Options.BestScoresStorageFileName}";
        var bestScoresStorage     = new BestScoresStorage(bestScoresStoragePath);

        bestScoresStorage.Save(bestScores);

        var loadBestScores = new BestScores();

        bestScoresStorage.Load(loadBestScores);

        //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        // Вариант на случай отсутствия перегруженного метода Score.Equals
        //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        //if (bestScores.Count != loadBestScores.Count)
        //    Assert.Fail();
        //bool equals = true;
        //for (int i = 0; i < bestScores.Count; i++)
        //{
        //    if (bestScores[i].Name != loadBestScores[i].Name ||
        //        bestScores[i].Moves != loadBestScores[i].Moves ||
        //        bestScores[i].Timer != loadBestScores[i].Timer)
        //    {
        //        equals = false;
        //        break;
        //    }
        //}
        //Assert.That(equals, Is.True);

        Assert.That(loadBestScores.Scores, Is.EqualTo(bestScores.Scores));
    }