예제 #1
0
        private void Awake()
        {
            _settingsProvider = new PlayerPrefsSettingProvider();
#if UNITY_EDITOR || UNITY_STANDALONE
            _inputService = new KeyboardInput();
#elif (UNITY_ANDROID || UNITY_IOS)
            _inputService = new MobileInput();
#endif
            CreateBall();
            CreateRackets();

            _scoreCounter          = new ScoreCounter.ScoreCounter();
            _ball.OnBallHitRacket += _scoreCounter.IncrementScore;
            _ball.OnBallRestart   += _scoreCounter.ResetScore;

            _scoreCounterText             = new ScoreCounterText(scoreCounterTextGo);
            _scoreCounter.OnScoreUpdated += _scoreCounterText.UpdateScore;

            _bestScoreUpdater             = new BestScoreUpdater(_settingsProvider);
            _scoreCounter.OnScoreUpdated += _bestScoreUpdater.UpdateScore;
            _ball.OnBallRestart          += _bestScoreUpdater.SaveToDisk;

            _bestScoreCounterText = new ScoreCounterText(bestScoreCounterTextGo, _settingsProvider.GetBestScore());
            _bestScoreUpdater.OnBestScoreUpdated += _bestScoreCounterText.UpdateScore;
        }
예제 #2
0
        /// <summary>
        /// Implements menu
        /// </summary>
        public static void StartMenu()
        {
            DBO.DBController controller = new DBO.DBController();
            Bow    bow    = new Bow();
            Pistol pistol = new Pistol();

            while (true)
            {
                Console.WriteLine("What to do?");
                Console.WriteLine("1. Start");
                Console.WriteLine("2. Leaderboards");
                Console.WriteLine("0. Exit");

                Tasks task = (Tasks)Convert.ToInt32(Console.ReadLine());

                if (task == Tasks.Exit)
                {
                    break;
                }
                Console.Clear();
                switch (task)
                {
                case Tasks.Start:
                    Console.Write("Player name: ");
                    string playerName = Console.ReadLine();

                    Shooter.Shooter shooter = Shooter.Shooter.GetInstance(playerName);

                    Console.Clear();

                    Console.WriteLine("Choose a gun: ");
                    Console.WriteLine("0. Bow");
                    Console.WriteLine("1. Pistol");

                    Guns gunChoice = (Guns)Convert.ToInt32(Console.ReadLine());

                    Console.Clear();

                    Console.WriteLine("Choose a target: ");
                    Console.WriteLine("0. Circle(default)");
                    Console.WriteLine("1. Human");

                    Targets targetChoice = (Targets)Convert.ToInt32(Console.ReadLine());

                    Target.Target             target;
                    ScoreCounter.ScoreCounter counter;
                    int maxTargetX, maxTargetY;
                    switch (targetChoice)
                    {
                    default:
                        maxTargetX = Target.Target.CIRCLE_TARGET_SIZE_X;
                        maxTargetY = Target.Target.CIRCLE_TARGET_SIZE_Y;
                        target     = new Target.Target(new Target.CircleTarget());
                        counter    = new ScoreCounter.ScoreCounter(new ScoreCounter.CircleTargetScoreCounter());
                        break;

                    case Targets.Human:
                        maxTargetX = Target.Target.HUMAN_TARGET_SIZE_X;
                        maxTargetY = Target.Target.HUMAN_TARGET_SIZE_Y;
                        target     = new Target.Target(new Target.HumanTarget());
                        counter    = new ScoreCounter.ScoreCounter(new ScoreCounter.HumanTargetScoreCounter());
                        break;
                    }

                    while (true)
                    {
                        Console.Clear();

                        Console.WriteLine("What to do?");
                        Console.WriteLine("0. Exit");
                        Console.WriteLine("1. Shoot");
                        ShootTask shootTask = (ShootTask)Convert.ToInt32(Console.ReadLine());
                        Console.Clear();
                        if (shootTask == ShootTask.Exit)
                        {
                            break;
                        }
                        else
                        {
                            Console.Write("Input X: ");
                            int coordinateX = int.Parse(GetCorrectCoordinateInput(maxTargetX));
                            Console.Write("Input Y: ");
                            int coordinateY = int.Parse(GetCorrectCoordinateInput(maxTargetY));
                            switch (gunChoice)
                            {
                            case Guns.Bow:
                                bow.Shoot(ref coordinateX, ref coordinateY, ref target);
                                break;

                            case Guns.Pistol:
                                pistol.Shoot(ref coordinateX, ref coordinateY, ref target);
                                break;
                            }

                            Target.TargetPrinter.PrintTarget(target);
                            counter.GetScore(coordinateX, coordinateY, target);
                            counter.SumScore();
                            counter.IncreaseShotsCounter();
                            Console.WriteLine("Your score: {0}", counter.Score);
                            Console.WriteLine("Total score: {0}", counter.TotalScore);
                            Console.WriteLine("Press any key to continue....");
                            Console.ReadKey();
                        }
                    }
                    controller.InsertResult(shooter.Name, gunChoice.ToString(), counter.Shots, counter.TotalScore, targetChoice.ToString());
                    counter.Reset();
                    shooter.ResetInstance();
                    break;

                case Tasks.Leaderboards:
                    controller.GetResults();
                    break;
                }
            }
        }