예제 #1
0
        // Returns true if score made it onto the leaderboard, false otherwise
        public void addToLeaderboard(string submittedName, string date, int difficulty, int timeInSecs, int newScore, NameRequest nameReq)
        {
            nameRequest = nameReq;
            string fileAddress = path + name;
            int    BufferSize  = 128;
            string line;
            int    pos = 0;
            int    scoreInLeaderboard = 0;

            string[] splitString;

            using (var fileStream = File.OpenRead(fileAddress))
                using (var streamReader = new StreamReader(fileStream, Encoding.UTF8, true, BufferSize))
                {
                    while ((line = streamReader.ReadLine()) != null)
                    {
                        pos++;
                        splitString = line.Split(',');
                        // if splitString[4] > score ...
                        scoreInLeaderboard = int.Parse(splitString[4]);

                        if (newScore > scoreInLeaderboard)
                        {
                            break;
                        }
                    }
                }
            propagateDownLeaderboard(submittedName, date, difficulty, timeInSecs, newScore, pos);
        }
예제 #2
0
        public void button_click(object sender, EventArgs e)
        {
            // If first button clicked, start the clock
            if (startTimer == false)
            {
                startStopWatch();
                Thread t = new Thread(doWork);
                t.IsBackground = true;
                t.Name         = "TIME_THREAD";
                Debug.WriteLine("[PlayWindow] Starting clock");
                t.Start();
                startTimer = true;
            }

            // Have to work out whether or not it was a correct click
            Button b = sender as Button;

            string res1 = sudokuGrid.getValueOfButtonInGrid(b.Name).ToString();
            string res2 = gameControl.getSelectedToolkitButtonName()[7].ToString();

            // Determining whether or not user has guessed correctly
            if (sudokuGrid.getValueOfButtonInGrid(b.Name).ToString() == gameControl.getSelectedToolkitButtonName()[7].ToString())
            {
                b.Text    = sudokuGrid.getValueOfButtonInGrid(b.Name).ToString();
                b.Enabled = false;
                gameControl.updateNumberInstance(b.Text);

                // Also highlight new number
                gameControl.highlightOrDehighlightDisabledButtons(b.Text, true);

                // Perform a win-check
                if (gameControl.checkForPlayerWin())
                {
                    // Deal with player winning
                    gameControl.highlightOrDehighlightDisabledButtons(b.Text, false);
                    gameAlive = false;
                    TimeSpan ts = stopWatch.Elapsed;
                    string   secs, mins;
                    if (ts.Seconds.ToString().Length == 1)
                    {
                        secs = "0" + ts.Seconds;
                    }
                    else
                    {
                        secs = ts.Seconds.ToString();
                    }
                    if (ts.Minutes.ToString().Length == 1)
                    {
                        mins = "0" + ts.Minutes;
                    }
                    else
                    {
                        mins = ts.Minutes.ToString();
                    }
                    string finalResult   = mins + ":" + secs;
                    int    totalSecs     = (ts.Minutes * 60) + ts.Seconds;
                    string penaltyEnding = "";
                    int    penaltyNum    = gameControl.getPlayerPenalty();
                    int    finalScore    = getFinalScore(ts.Minutes, ts.Seconds, penaltyNum, gridDifficulty);
                    penaltyEnding = (gameControl.getPlayerPenalty() == 1) ? "intento" : "intentos";
                    MessageBox.Show("Sudoku completado! Terminado en " + finalResult + " con " + penaltyNum + " " + penaltyEnding + ".\n" +
                                    "Marcador final: " + finalScore);

                    // Add score to leaderboard
                    Leaderboard lb = new Leaderboard();
                    if (lb.scoreMadeItOntoLeaderboard(finalScore))
                    {
                        MessageBox.Show("Felicitaciones estan en el top 10!");
                        NameRequest nr = new NameRequest(lb, gridDifficulty, totalSecs, finalScore);
                        nr.FormClosed += (s, args) => Close();
                        Hide();
                        nr.Show();
                    }

                    // Show leaderboard
                }
            }
            // Show the user they got it wrong - give penalty
            else
            {
                gameControl.incrementPenaltyLabel(this);
            }
        }