コード例 #1
0
        private bool CheckCollisionWithObjects()
        {
            var point = _player.Position;

            foreach (var obj in _objects)
            {
                switch (obj)
                {
                case Food f:
                    if (f.Position.Equals(point))
                    {
                        Point p = GetFreePoint();
                        f.Position = p;
                        _player.AddPart();
                        _gui.Scores++;
                    }
                    break;

                case Tree s:
                    if (s.Position.Equals(point))
                    {
                        return(true);
                    }
                    break;
                }
            }
            return(false);
        }
コード例 #2
0
ファイル: GameMaster.cs プロジェクト: PYZILEND/Snake
    void EatFood(Transform bit)
    {
        if (score < 30 && food.Count - 1 < Decimal.Round(score / 10))
        {
            SpawnFood();
        }
        if (score == 30)
        {
            SpawnFood();
            SpawnFood();
        }

        bit.position = FindValidSpawnPosition();

        score++;
        scoreText.text = "Score: " + score;
        if (score > highScore)
        {
            highScore = score;
            if (highScore > PlayerPrefs.GetInt("HighScore"))
            {
                PlayerPrefs.SetInt("HighScore", highScore);
                PlayerPrefs.Save();
                newHighScore = true;
            }
        }

        snake.speed += initialSnakeSpeed / 100f;
        snake.AddPart();

        SpawnObstacle();
    }