Esempio n. 1
0
        public void GutterGameTest()
        {
            var broker = new ScoreBroker();
            var game   = new BowlingGame(broker);

            broker.Command(new RollballCommand(game, 0));
            broker.Command(new RollballCommand(game, 0));
            broker.Command(new RollballCommand(game, 0));
            broker.Command(new RollballCommand(game, 0));
            broker.Command(new RollballCommand(game, 0));
            broker.Command(new RollballCommand(game, 0));
            broker.Command(new RollballCommand(game, 0));
            broker.Command(new RollballCommand(game, 0));
            broker.Command(new RollballCommand(game, 0));
            broker.Command(new RollballCommand(game, 0));
            broker.Command(new RollballCommand(game, 0));
            broker.Command(new RollballCommand(game, 0));
            broker.Command(new RollballCommand(game, 0));
            broker.Command(new RollballCommand(game, 0));
            broker.Command(new RollballCommand(game, 0));
            broker.Command(new RollballCommand(game, 0));
            broker.Command(new RollballCommand(game, 0));
            broker.Command(new RollballCommand(game, 0));
            broker.Command(new RollballCommand(game, 0));
            broker.Command(new RollballCommand(game, 0));

            broker.Frames[9].TotalScore.Should().Be(0);
        }
Esempio n. 2
0
    //When a Red Cube dies Scene Controller gets notified and calls another event to update the HUD
    private void ScoreBroker_RedCubeKilled()
    {
        redScore -= 1;
        ScoreBroker.CallUpdateRedCubeScore(redScore);

        //if there are no more RED cubes in the game then the GREEN team is winning the fight
        if (redScore <= 0 && currentState == GameState.RUNNING)
        {
            ScoreBroker.CallTeamIsWinning("GREEN");
        }
    }
Esempio n. 3
0
 //Just before the Cube gets destroyed it calls the corresponding event to update the score value.
 private void OnDisable()
 {
     //Call appropriate event to reduce score depending the cube's color.
     if (transform.gameObject.CompareTag("GreenCube"))
     {
         ScoreBroker.CallGreenCubeKilled();
     }
     else if (transform.gameObject.CompareTag("RedCube"))
     {
         ScoreBroker.CallRedCubeKilled();
     }
 }
Esempio n. 4
0
    //When a Green Cube dies Scene Controller gets notified and calls another event to update the HUD
    #region Scene Controller Subscribed to Cube Death events handling
    private void ScoreBroker_GreenCubeKilled()
    {
        //When a Green Cube Dies reduce the greenScore value by 1 and call the event to update the HUD as well
        greenScore -= 1;
        ScoreBroker.CallUpdateGreenCubeScore(greenScore);

        //if there are no more green cubes in the game then the RED team is winning the fight
        if (greenScore <= 0 && currentState == GameState.RUNNING)
        {
            ScoreBroker.CallTeamIsWinning("RED");
        }
    }
Esempio n. 5
0
        static void Main(string[] args)
        {
            var broker = new ScoreBroker();
            var game   = new BowlingGame(broker);

            broker.Command(new RollballCommand(game, 1));
            broker.Command(new RollballCommand(game, 4));
            broker.Command(new RollballCommand(game, 4));
            broker.Command(new RollballCommand(game, 5));
            broker.Command(new RollballCommand(game, 6));
            broker.Command(new RollballCommand(game, 4));
            broker.Command(new RollballCommand(game, 5));
            broker.Command(new RollballCommand(game, 5));
            broker.Command(new RollballCommand(game, 10));
            broker.Command(new RollballCommand(game, 0));
            broker.Command(new RollballCommand(game, 1));
            broker.Command(new RollballCommand(game, 7));
            broker.Command(new RollballCommand(game, 3));
            broker.Command(new RollballCommand(game, 6));
            broker.Command(new RollballCommand(game, 4));
            broker.Command(new RollballCommand(game, 10));
            broker.Command(new RollballCommand(game, 2));
            broker.Command(new RollballCommand(game, 8));
            broker.Command(new RollballCommand(game, 6));


            var table = new ConsoleTable("FrameNumber", "RollNumber", "KnockedDownPins", "TotalScore", "Note");

            foreach (var frame in broker.Frames)
            {
                table.AddRow(frame.Number, 1, frame.Roll1.KnockedDownPins, "", frame.StrikeNote);

                if (frame.Number == 10)
                {
                    table.AddRow(frame.Number, 2, frame.Roll2?.KnockedDownPins, "", frame.SpareNote);
                    table.AddRow(frame.Number, 3, frame.Roll3?.KnockedDownPins, frame.TotalScore, "");
                }
                else
                {
                    table.AddRow(frame.Number, 2, frame.Roll2?.KnockedDownPins, frame.TotalScore, frame.SpareNote);
                }
            }
            table.Write();
            var f = broker.Query <Frame>(new FrameQuery()
            {
                Target = game
            });

            Console.WriteLine($"The total score is:{f.TotalScore}");
            Console.ReadLine();
        }
Esempio n. 6
0
    // Start is called before the first frame update
    void Start()
    {
        GameStateManager(GameState.IDLE);

        greenScore = 0;
        redScore   = 0;

        ScoreBroker.CallUpdateGreenCubeScore(greenScore);
        ScoreBroker.CallUpdateRedCubeScore(redScore);

        //Scene controller Subscribes to Cube Death as an Observer.
        ScoreBroker.GreenCubeKilled += ScoreBroker_GreenCubeKilled;
        ScoreBroker.RedCubeKilled   += ScoreBroker_RedCubeKilled;
    }
Esempio n. 7
0
    //Method that fires when the RED SPAWN BUTTON is pressed.
    public void SpawnRedCube()
    {
        //If this is the first cube in the game, change the state of the game to RUNNING
        if (currentState == GameState.IDLE)
        {
            GameStateManager(GameState.RUNNING);
        }

        //CHECK IF CUBE IS ABOUT TO SPAWN NEAR A COLLIDER (PLANET OR OTHER CUBES)
        do
        {
            randomSpawnPoint = Random.insideUnitSphere * warZoneRadius;
        }while (Physics.CheckSphere(randomSpawnPoint, checkRadius));

        //Spawn a RED Cube Prefab
        Instantiate(redCubePrefab, randomSpawnPoint, Quaternion.identity);

        //Increase RED SCORE as a value
        redScore++;

        //EVENT UPDATE REDSCORE to update the score on the HUD
        ScoreBroker.CallUpdateRedCubeScore(redScore);
    }
Esempio n. 8
0
        public void GameTest()
        {
            var broker = new ScoreBroker();
            var game   = new BowlingGame(broker);

            broker.Command(new RollballCommand(game, 1));
            broker.Command(new RollballCommand(game, 4));
            broker.Command(new RollballCommand(game, 4));
            broker.Command(new RollballCommand(game, 5));
            broker.Command(new RollballCommand(game, 6));
            broker.Command(new RollballCommand(game, 4));
            broker.Command(new RollballCommand(game, 5));
            broker.Command(new RollballCommand(game, 5));
            broker.Command(new RollballCommand(game, 10));
            broker.Command(new RollballCommand(game, 0));
            broker.Command(new RollballCommand(game, 1));
            broker.Command(new RollballCommand(game, 7));
            broker.Command(new RollballCommand(game, 3));
            broker.Command(new RollballCommand(game, 6));
            broker.Command(new RollballCommand(game, 4));
            broker.Command(new RollballCommand(game, 10));
            broker.Command(new RollballCommand(game, 2));
            broker.Command(new RollballCommand(game, 8));
            broker.Command(new RollballCommand(game, 6));

            broker.Frames[0].TotalScore.Should().Be(5);
            broker.Frames[1].TotalScore.Should().Be(14);
            broker.Frames[2].TotalScore.Should().Be(29);
            broker.Frames[3].TotalScore.Should().Be(49);
            broker.Frames[4].TotalScore.Should().Be(60);
            broker.Frames[5].TotalScore.Should().Be(61);
            broker.Frames[6].TotalScore.Should().Be(77);
            broker.Frames[7].TotalScore.Should().Be(97);
            broker.Frames[8].TotalScore.Should().Be(117);
            broker.Frames[9].TotalScore.Should().Be(133);
        }