Ejemplo n.º 1
0
    // Start is called before the first frame update
    void Start()
    {
        RestartText.text  = "";
        GameOverText.text = "";

        if (controler == null)
        {
            controler = this;
        }
        else if (controler != this)
        {
            Destroy(gameObject);
        }


        HighestScore savedScore = SaveGame.LoadScore();

        if (savedScore != null)
        {
            highestScore = savedScore.highestScore;
        }

        nextTimeIncrease = Time.unscaledTime;


        state = STATES.INTRO;
        soundController.PlayIntro();
    }
Ejemplo n.º 2
0
    public static void SaveHighetScore(HighestScore data)
    {
        BinaryFormatter formatter = new BinaryFormatter();
        string          path      = Application.persistentDataPath + "/highestScore.ms";
        FileStream      stream    = new FileStream(path, FileMode.Create);

        formatter.Serialize(stream, data);
        stream.Close();
    }
Ejemplo n.º 3
0
        public GameStatistics GetGameStatisticsForMember(int memberId)
        {
            var games = _gameRepository.GetGamesForMember(memberId);

            if (games.Any())
            {
                var averageScore = (from x in games
                                    from y in x.Players
                                    where x.Id == y.GameId &&
                                    y.MemberId == memberId
                                    select y.Score).Average();

                int          wins = 0, loses = 0, highestScore = 0;
                HighestScore highestScorePlayer = null;
                foreach (var game in games)
                {
                    if (game.Players.OrderByDescending(x => x.Score).First().MemberId == memberId)
                    {
                        wins++;

                        if (game.Players.Single(x => x.MemberId == memberId).Score > highestScore)
                        {
                            highestScore = game.Players.Single(x => x.MemberId == memberId).Score;

                            string otherPlayerNames = null;
                            foreach (var member in game.Players.Where(x => x.MemberId != memberId))
                            {
                                var dataMember = _memberRepository.Get(member.MemberId);
                                otherPlayerNames += $"{dataMember.FirstName} {dataMember.LastName}, ";
                            }

                            highestScorePlayer = new HighestScore
                            {
                                GameDate = game.GameDate,
                                Location = game.Location,
                                Score    = highestScore,
                                PlayedAgainstPlayerName = otherPlayerNames != null?otherPlayerNames.Substring(0, otherPlayerNames.Length - 2) : string.Empty
                            };
                        }
                    }
                    else
                    {
                        loses++;
                    }
                }

                return(new GameStatistics
                {
                    Wins = wins,
                    Loses = loses,
                    AverageScore = averageScore,
                    HighestScore = highestScorePlayer
                });
            }

            return(null);
        }
 // Update is called once per frame
 void Update()
 {
     if (health <= 0)
     {
         //levelManager.RespawnPlayer();
         HighestScore.checking();
         SceneManager.LoadScene(afterDeath);
     }
     text.text = "" + health + "/" + maxPlayerHealth;
 }
Ejemplo n.º 5
0
    public static void SaveScore()
    {
        BinaryFormatter formatter = new BinaryFormatter();
        string          path      = Application.persistentDataPath + "/highest_score.dat";
        FileStream      stream    = new FileStream(path, FileMode.Create);
        HighestScore    data      = new HighestScore(GameController.controler);

        formatter.Serialize(stream, data);
        stream.Close();
    }
Ejemplo n.º 6
0
 public void FileSave()
 {
     try {
         System.IO.File.WriteAllLines(_directory + @"\documents",
                                      new string[] { TextEncrypt(Gold.ToString(), SECRET_KEY),
                                                     TextEncrypt(HighestScore.ToString(), SECRET_KEY),
                                                     TextEncrypt(OwnBulletTime.ToString(), SECRET_KEY),
                                                     TextEncrypt(OwnBackToHistory.ToString(), SECRET_KEY),
                                                     TextEncrypt(OwnGetBlockI.ToString(), SECRET_KEY) }, Encoding.UTF8);
     } catch { }
 }
Ejemplo n.º 7
0
    public int LoadHighestScore()
    {
        HighestScore score = SaveData.LoadScore();

        if (score != null)
        {
            return(score.highestScore);
        }
        else
        {
            return(0);
        }
    }
    /// <summary>
    /// Save a new highestScore
    /// </summary>
    /// <param name="highestScore"></param>
    public static void SaveHighestScore(int highestScoreValue)
    {
        string       path         = GetPathToHighestScore();
        HighestScore highestScore = new HighestScore();

        highestScore.highestScore = highestScoreValue;
        string jsonObj = JsonUtility.ToJson(highestScore);
        //Debug.Log("SavedJsonFile: " + jsonObj);
        FileInfo file = new FileInfo(path);

        file.Directory.Create(); // If the directory already exists, this method does nothing.
        File.WriteAllText(path, jsonObj);
    }
 // Update is called once per frame
 void Update()
 {
     if (Input.GetKeyDown(KeyCode.W) && playerInZone)
     {
         PlayerPrefs.SetInt("PlayerCurrentLives", PlayerHealth.health);
         PlayerPrefs.SetInt("PlayerCurrentScores", ScoreManager.score);
         if (levelToLoad == "Won")
         {
             print("check");
             HighestScore.checking();
         }
         SceneManager.LoadScene(levelToLoad);
     }
 }
Ejemplo n.º 10
0
    public void SaveTheHighestScore()
    {
        HighestScore previousScore = SaveData.LoadScore();

        if (previousScore != null)
        {
            if (previousScore.highestScore < GameplayManager.Instance.highestScore)
            {
                HighestScore newHighestScore = new HighestScore();
                newHighestScore.highestScore = GameplayManager.Instance.highestScore;
                SaveData.SaveHighetScore(newHighestScore);
            }
        }
    }
Ejemplo n.º 11
0
        public void HighestNumbers()
        {
            var input = new[]
            {
                "72 64 150 | 100 18 33 | 13 250 -6",
                "10 25 -30 44 | 5 16 70 8 | 13 1 31 12",
                "100 6 300 20 10 | 5 200 6 9 500 | 1 10 3 400 143"
            };
            var expected = new[] { "100 250 150", "13 25 70 44", "100 200 300 400 500" };
            var prog     = new HighestScore(input);
            var result   = prog.Run().ToArray();

            for (int i = 0; i < expected.Length; i++)
            {
                Assert.AreEqual(expected[i], result[i]);
            }
        }
Ejemplo n.º 12
0
    public static HighestScore LoadScore()
    {
        string path = Application.persistentDataPath + "/highest_score.dat";

        if (File.Exists(path))
        {
            BinaryFormatter formatter = new BinaryFormatter();
            FileStream      stream    = new FileStream(path, FileMode.Open);
            HighestScore    score     = (HighestScore)formatter.Deserialize(stream);
            stream.Close();
            return(score);
        }
        else
        {
            Debug.LogError("Save file not found in " + path);
            return(null);
        }
    }
Ejemplo n.º 13
0
    public static HighestScore LoadScore()
    {
        string path = Application.persistentDataPath + "/highestScore.ms";

        if (File.Exists(path))
        {
            BinaryFormatter formatter = new BinaryFormatter();
            FileStream      stream    = new FileStream(path, FileMode.Open);
            HighestScore    data      = (HighestScore)formatter.Deserialize(stream);
            stream.Close();
            return(data);
        }
        else
        {
            HighestScore zeroScore = new HighestScore();
            zeroScore.highestScore = 0;
            return(zeroScore);
        }
    }
    /// <summary>
    /// Get the highestScore
    /// </summary>
    /// <returns></returns>
    public static HighestScore GetHighestScore()
    {
        string path = GetPathToHighestScore();

        if (!File.Exists(path))     //Checks if the file exists
        {
            HighestScore highestScore = new HighestScore();
            string       jsonObj      = JsonUtility.ToJson(highestScore);
            //Debug.Log("SavedJsonFile: " + jsonObj);
            FileInfo defaultFile = new FileInfo(path);
            defaultFile.Directory.Create();     // If the directory already exists, this method does nothing.
            File.WriteAllText(path, jsonObj);
        }

        string       file             = File.ReadAllText(path);
        HighestScore highestScoreJson = JsonUtility.FromJson <HighestScore>(file);

        //Debug.Log(highestScoreJson.highestScore); //here you can check the value on the debug if you want
        return(highestScoreJson);
    }
Ejemplo n.º 15
0
        /// <summary>
        /// THIS METHOD CREATES AND INITALIZES ALL THE SPRITES, MUSIC, ECT
        /// </summary>
        private void StartUp()
        {
            Banner       banner;
            Flag         flag;
            Lives        lives;
            SpaceKey     space;
            HighestScore HScore;
            Snowball     snow;

            //BACKGROUND
            background = new Background(SkiingGameCoursework.Content.Background, new Vector2(0, 0), SkiingGameCoursework.Content.Background.Width, SkiingGameCoursework.Content.Background.Height, 0.0f);
            background.Initialize(GraphicsDevice);

            skier = new Skier(SkiingGameCoursework.Content.Skier, new Vector2(350, 170), 29, 63, 0.2f);
            flag  = new Flag();
            lives = new Lives();
            space = new SpaceKey(spaceBar, new Vector2(150, 300), 500, 80);
            Res   = new RestartPrompt();
            Cheese cheese = new Cheese();

            snow   = new Snowball(snowballSpriteSheet, new Vector2(310, -210), 65, 65);
            banner = new Banner(SkiingGameCoursework.Content.TVBanner, new Vector2(50, 400), 1252, 42, 0.82f);
            Blur blur = new Blur(GraphicsDevice);


            //MENU
            startButton = new Start(SkiingGameCoursework.Content.StartButton, new Vector2(280, 60), SkiingGameCoursework.Content.StartButton.Width, SkiingGameCoursework.Content.StartButton.Height);
            HScore      = new HighestScore();

            mainGame.Active    = false;
            userPrompts.Active = false;
            menu.Active        = true;

            mainGame.LoadParticle();
            menu.LoadParticle();

            mainGame.Initialize();

            PlayBackgroundMusic();
        } //CREATES ALL THE INSTANCES OF ALL THE ASSETS
Ejemplo n.º 16
0
 public void UpdateLabel()
 {
     labHighestScore.Text = "最高分 : " + HighestScore.ToString();
     labGold.Text         = "金币 : " + Gold.ToString();
 }
Ejemplo n.º 17
0
 public void HighestNumbers()
 {
     var input = new[]
     {
         "72 64 150 | 100 18 33 | 13 250 -6",
         "10 25 -30 44 | 5 16 70 8 | 13 1 31 12",
         "100 6 300 20 10 | 5 200 6 9 500 | 1 10 3 400 143"
     };
     var expected = new[] {"100 250 150", "13 25 70 44", "100 200 300 400 500"};
     var prog = new HighestScore(input);
     var result = prog.Run().ToArray();
     for (int i = 0; i < expected.Length; i++)
     {
         Assert.AreEqual(expected[i], result[i]);
     }
 }
Ejemplo n.º 18
0
    void OnGUI()
    {
        GUIStyle text_style;
        GUIStyle button_style;

        text_style = new GUIStyle()
        {
            fontSize = 20
        };
        button_style = new GUIStyle("button")
        {
            fontSize = 15
        };

        if (gameState == 0)
        {
            //初始界面
            if (GUI.Button(new Rect(Screen.width / 2 - 50, 80, 100, 60), "Start Game", button_style))
            {
                action.StartGame();
            }
        }
        else if (gameState == 1)
        {
            //游戏进行中
            //用户射击
            if (Input.GetButtonDown("Fire1"))
            {
                Vector3 mousePos = Input.mousePosition;
                action.Hit(mousePos);
            }

            score = "Score: " + action.GetScore().ToString();
            GUI.Label(new Rect(200, 5, 100, 100), score, text_style);
            round = "Round: " + action.GetCurrentRound().ToString();
            GUI.Label(new Rect(400, 5, 100, 100), round, text_style);

            blood = action.GetBlood();
            string bloodStr = "Blood: " + blood.ToString();
            GUI.Label(new Rect(600, 5, 50, 50), bloodStr, text_style);
        }
        else
        {
            //游戏结束,有两种情况
            if (gameState == 2)
            {
                if (action.GetScore() > HighestScore)
                {
                    HighestScore = action.GetScore();
                }
                GUI.Label(new Rect(Screen.width / 2 - 50, Screen.height / 2 - 250, 100, 60), "Game Over", text_style);
                string record = "Highest Score: " + HighestScore.ToString();
                GUI.Label(new Rect(Screen.width / 2 - 70, Screen.height / 2 - 150, 150, 60), record, text_style);
            }
            else
            {
                GUI.Label(new Rect(Screen.width / 2 - 50, Screen.height / 2 - 150, 100, 70), "You Lost!", text_style);
            }

            if (GUI.Button(new Rect(Screen.width / 2 - 50, Screen.height / 2 - 30, 100, 60), "Restart", button_style))
            {
                action.Restart();
            }
        }
    }