private void LoadTopScores()
    {
        if (File.Exists(Application.persistentDataPath + "/topScoresData.dat"))
        {
            BinaryFormatter bf   = new BinaryFormatter();
            FileStream      file = File.Open(Application.persistentDataPath + "/topScoresData.dat", FileMode.Open);

            ScoreData savedScores = (ScoreData)bf.Deserialize(file);
            file.Close();

            // Deletes legacy top 5 file and creates new top 10 file with default values
            if (savedScores.topScores.Count < 6)
            {
                File.Delete(Application.persistentDataPath + "/topScores.dat");
                CreateTopScoresFile();
            }

            _topScoresData = new List <TopScore>();
            for (int i = 0; i < savedScores.topScores.Count; i++)
            {
                TopScore topScore = savedScores.topScores[i];
                _topScoresData.Add(topScore);
            }
        }
        else
        {
            CreateTopScoresFile();
        }
    }
    private void CreateTopScoresFile()
    {
        _topScoresData = new List <TopScore>();

        DefaultHighScores();

        BinaryFormatter bf = new BinaryFormatter();
        FileStream      file;

        file = File.Create(Application.persistentDataPath + "/topScoresData.dat");
        file.Close();

        file = File.Open(Application.persistentDataPath + "/topScoresData.dat", FileMode.Open);

        ScoreData savedScores = new ScoreData();

        for (int i = 0; i < _topScoresData.Count; i++)
        {
            TopScore topScore = new TopScore();
            topScore.name  = _topScoresData[i].name;
            topScore.score = _topScoresData[i].score;

            savedScores.topScores.Add(topScore);
        }

        bf.Serialize(file, savedScores);
        file.Close();
    }
    public void saveHighScore()
    {
        TopScore topScore = new TopScore();

        if (loadData(SAVE_FILE_PATH + "TopScore.json") == null)
        {
            topScore.topScore = playerScore;
            string finalJson = JsonUtility.ToJson(topScore, true);
            Debug.Log("Inside GameManager finalJson : " + finalJson);
            saveData(finalJson, SAVE_FILE_PATH + "TopScore.json");
        }
        else
        {
            string   highScoreJson    = loadData(SAVE_FILE_PATH + "TopScore.json");
            TopScore topScoreDataTemp = JsonUtility.FromJson <TopScore>(highScoreJson);

            if (playerScore > topScoreDataTemp.topScore)
            {
                topScore.topScore = playerScore;
                string finalJson = JsonUtility.ToJson(topScore, true);
                Debug.Log("Inside GameManager finalJson : " + finalJson);
                saveData(finalJson, SAVE_FILE_PATH + "TopScore.json");
            }
        }
    }
    public List <TopScore> UpdateHighScores()
    {
        new GameSparks.Api.Requests.LeaderboardDataRequest().SetLeaderboardShortCode("SCORE_LEADERBOARD").SetEntryCount(10).Send((response) => {
            if (!response.HasErrors)
            {
                Debug.Log("Found Leaderboard Data...");
                _topScores.Clear();

                foreach (GameSparks.Api.Responses.LeaderboardDataResponse._LeaderboardData entry in response.Data)
                {
                    TopScore topScore = new TopScore();

                    int rank          = (int)entry.Rank;
                    string playerName = entry.UserName;
                    topScore.name     = playerName;
                    string score      = entry.JSONData["SCORE"].ToString();
                    topScore.score    = int.Parse(score);

                    _topScores.Add(topScore);

                    Debug.Log("Rank:" + rank + " Name:" + playerName + " \n Score:" + score);
                }
            }
            else
            {
                Debug.Log("Error Retrieving Leaderboard Data...");
                Debug.Log(response.Errors.JSON);
            }
        });

        return(_topScores);
    }
Exemplo n.º 5
0
        private int CalculateWinner(int gameId)
        {
            List <UserTeam> _allUserTeamsForGame = _userTeams.GetList(x => x.GameId).ToList();
            var             _topScore            = new TopScore();

            foreach (UserTeam team in _allUserTeamsForGame)
            {
                int _tempScore = 0;

                List <UserTeam_Player> _chosenPlayersForTeam = (List <UserTeam_Player>)GetAllChosenUserTeamPlayersForTeam(team.Id);
                Player _player;

                foreach (UserTeam_Player player in _chosenPlayersForTeam)
                {
                    _player    = _players.Get(x => x.Id == player.PlayerId);
                    _tempScore = _tempScore + _player.Age;
                }
                if (_tempScore > _topScore.Score)
                {
                    _topScore.UserTeamId = team.Id;
                    _topScore.Score      = _tempScore;
                }
            }
            return(_topScore.UserTeamId);
        }
Exemplo n.º 6
0
        public MainWindow(ISampleService sampleService, IOptions <AppSettings> settings, DatabaseContext dataContext)
        {
            InitializeComponent();
            this.sampleService = sampleService;
            this.settings      = settings.Value;
            context            = dataContext;

            // Tesztadatokkal történő feltöltés
            // A QuizContents tábla feltöltése a initial_questions.csv-ből nyert kezdő adatokkal, ha táblában 0 rekord van
            if (context.QuizContents.ToList().Count() == 0)
            {
                using (TextFieldParser parser = new TextFieldParser("initial_questions.csv", Encoding.UTF8))
                {
                    parser.TextFieldType = FieldType.Delimited;
                    parser.SetDelimiters(";");
                    while (!parser.EndOfData)
                    {
                        string[]    fields           = parser.ReadFields();
                        QuizContent temp_quizcontent = new QuizContent
                        {
                            Question     = fields[0],
                            GoodAnswer   = fields[1],
                            WrongAnswer1 = fields[2],
                            WrongAnswer2 = fields[3]
                        };
                        context.QuizContents.Add(temp_quizcontent);
                    }
                    context.SaveChanges();
                }
            }

            // Tesztadatokkal történő feltöltés
            // A TopScores tábla feltöltése a initial_topscores.csv-ből nyert kezdő adatokkal, ha a táblában 0 rekord van
            if (context.TopScores.ToList().Count() == 0)
            {
                using (TextFieldParser parser = new TextFieldParser("initial_topscores.csv", Encoding.UTF8))
                {
                    parser.TextFieldType = FieldType.Delimited;
                    parser.SetDelimiters(";");
                    while (!parser.EndOfData)
                    {
                        string[] fields        = parser.ReadFields();
                        TopScore temp_topscore = new TopScore
                        {
                            Name  = fields[0],
                            Score = int.Parse(fields[1])
                        };
                        context.TopScores.Add(temp_topscore);
                    }
                    context.SaveChanges();
                }
            }

            // A többi ablak létrehozása
            topscoreswindow = new TopScoresWindow(this, context);
            dbmanagerwindow = new DbManagerWindow(this, context);
            quizwindow      = new QuizWindow(this, context);
        }
Exemplo n.º 7
0
 private static void Add12345ToTopScoreList(TopScore topScore)
 {
     for (int i = 1; i <= 5; i++)
     {
         Player player = new Player();
         player.Score = i;
         topScore.AddToTopScoreList(player);
     }
 }
    private void UpdateExistingFileToTop10(ScoreData savedScores, BinaryFormatter bf, FileStream file)
    {
        for (int i = 0; i < _topScoresData.Count; i++)
        {
            TopScore topScore = new TopScore();
            topScore.name  = _topScoresData[i].name;
            topScore.score = _topScoresData[i].score;

            savedScores.topScores.Add(topScore);
        }

        bf.Serialize(file, savedScores);
    }
Exemplo n.º 9
0
        /// <summary>
        /// Нажатие на кнопку сохранить
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Save_Click(object sender, RoutedEventArgs e)
        {
            var gamerName = GamerName.Text;

            if (string.IsNullOrEmpty(gamerName))
            {
                return;
            }

            TopScore.SetTopScore(new TopScoreResult(GamerName.Text, _score, Level));

            Close();
        }
Exemplo n.º 10
0
        public void IsTopScore_InValidInput_Test()
        {
            TopScore.Instance.Clear();
            TopScore newTopScore = new TopScore();

            Add12345ToTopScoreList(newTopScore);

            Player testPlayer = new Player();

            testPlayer.Score = 9;
            bool result = newTopScore.IsTopScore(testPlayer);

            Assert.IsFalse(result);
        }
Exemplo n.º 11
0
 void Start()
 {
     orbScript          = particles.GetComponent <OrbScript>();
     cameraMovement     = mainCameraObject.GetComponent <CameraMovement>();
     topScoreScript     = TopScoreHolder.GetComponent <TopScore>();
     GUIMainframeBody   = MainframeBody.GetComponent <SplineFollower>();
     GUImainCamera      = mainCamera.GetComponent <SplineFollower>();
     playMesh           = playIcon.GetComponent <MeshRenderer>();
     arrayTest          = gameManager.GetComponent <ArrayTest>();
     guiMainframeScript = MainframeBody.GetComponent <GUImainframeScript>();
     score            = gameManager.GetComponent <Score>();
     adManager        = Ads.GetComponent <AdManager>();
     positionOperator = MainMainframeBody.GetComponent <PositionOperator>();
     tutorialScript   = GetComponent <TutorialScript>();
 }
    public void TopScore()
    {
        mainMenuCanvas.SetActive(false);

        if (loadData(SAVE_FILE_PATH + "TopScore.json") != null)
        {
            string   highScoreJson    = loadData(SAVE_FILE_PATH + "TopScore.json");
            TopScore topScoreDataTemp = JsonUtility.FromJson <TopScore>(highScoreJson);
            topScoreText.text = topScoreDataTemp.topScore.ToString();
        }
        else
        {
            topScoreText.text = "0";
        }
        topScoreCanvas.SetActive(true);
    }
Exemplo n.º 13
0
        protected virtual void Start()
        {
            input.enabled = false;

            CheckForSettings();

            FindObjectOfType <GridGenerator>().Init(col, row);
            generator.Init(col, row, () =>
            {
                input.enabled = true;
            });
            generator.RaiseEndOfGame += Generator_RaiseEndOfGame;
            generator.RaiseItemPop   += UpdateScore;

            uiCtrl.RaiseNewGame += UiCtrl_RaiseNewGame;
            uiCtrl.UpdateHiScore(TopScore.GetHiScore().ToString());

            input.RaiseItemTapped += Input_RaiseItemTapped;
        }
Exemplo n.º 14
0
 // Update score with new amount
 private void UpdateScore(int amount)
 {
     // If only one item tapped, nothing
     if (amount <= 0)
     {
         return;
     }
     // Based on amount, set feedback to user
     uiCtrl.SetFeedback(amount);
     // Exponential increase based on power of two
     score += Mathf.FloorToInt(Mathf.Pow(2, amount));
     // Update the visual of the score
     uiCtrl.UpdateScore(score.ToString());
     // Update the hi score if higher
     if (TopScore.SetHiScore(score))
     {
         // Update the visual of hiscore if needed
         uiCtrl.UpdateHiScore(TopScore.GetHiScore().ToString());
     }
 }
Exemplo n.º 15
0
        private void OnClick_Rogzites(object sender, RoutedEventArgs e)
        {
            string nev = "Név nélkül";          //Ha nem adnak meg nevet, akkor "Név nélkül" névvel kerül rügzítésre az eredmény

            if (Nev.Text != "")
            {
                nev = Nev.Text;
            }

            ///Az eredmény adatbázisba rögzítése
            TopScore ujrekord = new TopScore
            {
                Name  = nev,
                Score = 100 * jo_valaszok_szama / osszes_feltett_kerdes
            };

            context.TopScores.Add(ujrekord);
            context.SaveChanges();

            //Visszatérés a főmenü ablakához
            Hide();
            Thread.Sleep(150);
            mainwindow.Show();
        }
    private void DefaultHighScores()
    {
        TopScore topScore1 = new TopScore();

        topScore1.name  = "Bob";
        topScore1.score = 15000;
        _topScoresData.Add(topScore1);

        TopScore topScore2 = new TopScore();

        topScore2.name  = "Susie";
        topScore2.score = 13000;
        _topScoresData.Add(topScore2);

        TopScore topScore3 = new TopScore();

        topScore3.name  = "Carlos";
        topScore3.score = 11000;
        _topScoresData.Add(topScore3);

        TopScore topScore4 = new TopScore();

        topScore4.name  = "Jess";
        topScore4.score = 10000;
        _topScoresData.Add(topScore4);

        TopScore topScore5 = new TopScore();

        topScore5.name  = "George";
        topScore5.score = 8000;
        _topScoresData.Add(topScore5);

        TopScore topScore6 = new TopScore();

        topScore6.name  = "Elaine";
        topScore6.score = 6000;
        _topScoresData.Add(topScore6);

        TopScore topScore7 = new TopScore();

        topScore7.name  = "Kramer";
        topScore7.score = 4000;
        _topScoresData.Add(topScore7);

        TopScore topScore8 = new TopScore();

        topScore8.name  = "Newman";
        topScore8.score = 3000;
        _topScoresData.Add(topScore8);

        TopScore topScore9 = new TopScore();

        topScore9.name  = "Barbara";
        topScore9.score = 2000;
        _topScoresData.Add(topScore9);

        TopScore topScore10 = new TopScore();

        topScore10.name  = "Frank";
        topScore10.score = 1000;
        _topScoresData.Add(topScore10);
    }
Exemplo n.º 17
0
        private int CalculateWinner(int gameId)
        {
            List<UserTeam> _allUserTeamsForGame = _userTeams.GetList(x => x.GameId).ToList();
            var _topScore = new TopScore();

            foreach (UserTeam team in _allUserTeamsForGame)
            {
                int _tempScore = 0;

                List<UserTeam_Player> _chosenPlayersForTeam = (List<UserTeam_Player>)GetAllChosenUserTeamPlayersForTeam(team.Id);
                Player _player;

                foreach (UserTeam_Player player in _chosenPlayersForTeam)
                {
                    _player = _players.Get(x => x.Id == player.PlayerId);
                    _tempScore = _tempScore + _player.Age;
                }
                if (_tempScore > _topScore.Score)
                {
                    _topScore.UserTeamId = team.Id;
                    _topScore.Score = _tempScore;
                }
            }
            return _topScore.UserTeamId;
        }