Example #1
0
        public void CalculateSectorValueByCoordinates(int expectedSectorValue, int x, int y)
        {
            var     board   = new Dartboard();
            Section section = board.GetSector(x, y);

            Assert.AreEqual(expectedSectorValue, section.Value);
        }
Example #2
0
        public void CalculateThrowResult(string expected, int x, int y)
        {
            var board = new Dartboard();
            var res   = board.GetResult(x, y);

            Assert.AreEqual(expected, res.ToString());
        }
Example #3
0
        public override void LoadContent()
        {
            if (Content == null)
            {
                Content = new ContentManager(XnaDartsGame.ScreenManager.Game.Services, @"Content");
            }

            _background = Content.Load <Texture2D>(@"Images\Backgrounds\AbstractBackground");
            // XnaDartsGame.Options.Theme

            SerialManager.Instance().OnDartRegistered = _registerDart;
            SerialManager.Instance().OnDartHit        = null;

            _dartboard = new Dartboard();
            _dartboard.LoadContent(Content);
            _dartboard.OnSegmentClicked += _registerDart;
            _dartboard.Scale             = 0.5f;

            _playerChangeScreen = new PlayerChangeScreen("Player Change",
                                                         TimeSpan.FromSeconds(XnaDartsGame.Options.PlayerChangeTimeout));
            _playerChangeScreen.LoadContent();
            _playerChangeScreen.OnTimeout += _playerChange;

            _throwDartsScreen                 = new TimeoutScreen(Mode.CurrentPlayer.Name + " throw darts!", TimeSpan.FromSeconds(3));
            _newRoundTimeoutScreen            = new TimeoutScreen("Round 1", TimeSpan.FromSeconds(3));
            _newRoundTimeoutScreen.OnTimeout += _startTurn;

            foreach (var drawableGameComponent in GuiComponents)
            {
                drawableGameComponent.LoadContent(Content);
            }

            _startGame();
        }
Example #4
0
		public void PaintDartsBoard(Dartboard board, Graphics graphics)
		{
			graphics.SmoothingMode = SmoothingMode.AntiAlias;
			FillEllipse(graphics, DartboardColor.Dark, board.DoubleOuterRadius * 1.3);
			foreach (var sector in board.Sectors)
				PaintSector(board, graphics, sector);
			FillEllipse(graphics, DartboardColor.Green, board.OuterBullRadius);
			FillEllipse(graphics, DartboardColor.Red, board.InnerBullRadius);
		}
Example #5
0
 public void PaintDartsBoard(Dartboard board, Graphics graphics)
 {
     graphics.SmoothingMode = SmoothingMode.AntiAlias;
     FillEllipse(graphics, DartboardColor.Dark, board.DoubleOuterRadius * 1.3);
     foreach (var sector in board.Sectors)
     {
         PaintSector(board, graphics, sector);
     }
     FillEllipse(graphics, DartboardColor.Green, board.OuterBullRadius);
     FillEllipse(graphics, DartboardColor.Red, board.InnerBullRadius);
 }
        private async void SubmitButton_Clicked(object sender, EventArgs e) //handles all the logic when the submit button is clicked
        {
            await Dartboard.RotateTo(360, 1000);

            Dartboard.Rotation = 0;
            throwValue         = computeScore(Convert.ToString(colorPicker.SelectedItem), Convert.ToInt32(numberPicker.SelectedItem)); //throwValue = whatever values were put into the pickers by the user.
            if (currentTeam == "Team 1")                                                                                               //currentTeam is set to "Team 1" by default. This is why whichever team goes first needs to be set to Team 1.
            {
                if (!(Convert.ToString(colorPicker.SelectedItem) == "Red" || Convert.ToString(colorPicker.SelectedItem) == "Yellow"))
                {
                    if (teamAScore == Preferences.Get("startingGameScore", 0)) //the logic that requires the user to begin scoring by hitting a double
                    {
                        DisplayAlert("Invalid", "A double (the red section of the dart board) is required to begin scoring", "Ok");
                        throwValue = 0;
                    }
                }


                teamAScore -= throwValue;                      //Team A score is equal to itself minus whatever the throwValue is
                Preferences.Set("teamAScore", teamAScore);     //store teamA's updated score
                currentTeamScore.Text = teamAScore.ToString(); //updating the scoreLabel that displays at the top of the screen.
                teamABustCheck();                              //checks if team A busted after clicking the submit button
                counter++;                                     //incrementing the counter to determine if it is still this team's turn

                if (counter > 3)                               //switches teams and displays an alert showing the current team's score.
                {
                    teamASwitch();
                }
            }
            else //everything in this else statement is practically the same as the above, just for the opposite team.
            {
                if (!(Convert.ToString(colorPicker.SelectedItem) == "Red" || Convert.ToString(colorPicker.SelectedItem) == "Yellow"))
                {
                    if (teamBScore == Preferences.Get("startingGameScore", 0))
                    {
                        DisplayAlert("Invalid", "A double (the red section of the dart board) is required to begin scoring", "Ok");
                        throwValue = 0;
                    }
                }


                teamBScore -= throwValue;
                Preferences.Set("teamBScore", teamBScore);
                currentTeamScore.Text = teamBScore.ToString();
                teamBBustCheck();
                counter++;

                if (counter > 3)
                {
                    teamBSwitch();
                }
            }
        }
Example #7
0
        public void BeFilledByItsSectors()
        {
            var board = new Dartboard();
            var ss    = board.Sectors;

            for (int i = 0; i < 20; i++)
            {
                var sector = ss[i];
                Console.WriteLine(sector);
                var nextSector = ss[(i + 1) % ss.Count];
                Assert.AreEqual(sector.StartAngle, nextSector.EndAngle, sector + ", " + nextSector);
            }
        }
Example #8
0
		private void PaintSector(Dartboard board, Graphics graphics, Section section)
		{
			FillPie(graphics, section.DoubleColor, board.DoubleOuterRadius, section.StartAngle, section.SweepAngle);
			FillPie(graphics, section.SectorColor, board.DoubleInnerRadius, section.StartAngle, section.SweepAngle);
			FillPie(graphics, section.DoubleColor, board.TripleOuterRadius, section.StartAngle, section.SweepAngle);
			FillPie(graphics, section.SectorColor, board.TripleInnerRadius, section.StartAngle, section.SweepAngle);
			var cx = board.DoubleOuterRadius*1.1*Math.Cos(section.StartAngle + section.SweepAngle/2);
			var cy = -board.DoubleOuterRadius*1.1*Math.Sin(section.StartAngle + section.SweepAngle/2);
			var font = new Font(new FontFamily("Arial"),14, FontStyle.Regular);
			var text = section.Value.ToString();
			var size = graphics.MeasureString(text, font);
			graphics.DrawString(text, font, Brushes.White, (float) cx - size.Width/2, (float)cy - size.Height/2);
		}
Example #9
0
        private void PaintSector(Dartboard board, Graphics graphics, Section section)
        {
            FillPie(graphics, section.DoubleColor, board.DoubleOuterRadius, section.StartAngle, section.SweepAngle);
            FillPie(graphics, section.SectorColor, board.DoubleInnerRadius, section.StartAngle, section.SweepAngle);
            FillPie(graphics, section.DoubleColor, board.TripleOuterRadius, section.StartAngle, section.SweepAngle);
            FillPie(graphics, section.SectorColor, board.TripleInnerRadius, section.StartAngle, section.SweepAngle);
            var cx   = board.DoubleOuterRadius * 1.1 * Math.Cos(section.StartAngle + section.SweepAngle / 2);
            var cy   = -board.DoubleOuterRadius * 1.1 * Math.Sin(section.StartAngle + section.SweepAngle / 2);
            var font = new Font(new FontFamily("Arial"), 14, FontStyle.Regular);
            var text = section.Value.ToString();
            var size = graphics.MeasureString(text, font);

            graphics.DrawString(text, font, Brushes.White, (float)cx - size.Width / 2, (float)cy - size.Height / 2);
        }
Example #10
0
        public void TestGetScore_T2()
        {
            var dartboard = new Dartboard();

            Assert.AreEqual("T2", dartboard.GetScore(55.53, -87.95));
        }
Example #11
0
        public void TestGetScore_DB()
        {
            var dartboard = new Dartboard();

            Assert.AreEqual("DB", dartboard.GetScore(4.06, 0.71));
        }
Example #12
0
        public override void LoadContent()
        {
            if (Content == null)
            {
                Content = new ContentManager(XnaDartsGame.ScreenManager.Game.Services, @"Content");
            }

            _background = Content.Load<Texture2D>(@"Images\Backgrounds\AbstractBackground"); // XnaDartsGame.Options.Theme

            SerialManager.Instance().OnDartRegistered = registerDart;
            SerialManager.Instance().OnDartHit = null;

            _dartboard = new Dartboard();
            _dartboard.LoadContent(Content);
            _dartboard.OnSegmentClicked += registerDart;
            _dartboard.Scale = 0.5f;

            _playerChangeScreen = new PlayerChangeScreen("Player Change",
                TimeSpan.FromSeconds(XnaDartsGame.Options.PlayerChangeTimeout));
            _playerChangeScreen.LoadContent();
            _playerChangeScreen.OnTimeout += playerChange;

            _throwDartsScreen = new TimeoutScreen(Mode.CurrentPlayer.Name + " throw darts!", TimeSpan.FromSeconds(3));
            _newRoundTimeoutScreen = new TimeoutScreen("Round 1", TimeSpan.FromSeconds(3));
            _newRoundTimeoutScreen.OnTimeout += startTurn;

            foreach (var drawableGameComponent in GuiComponents)
            {
                drawableGameComponent.LoadContent(Content);
            }

            startGame();
        }
        public void GetScoreTest(string expected, double x, double y)
        {
            var dartboard = new Dartboard();

            Assert.AreEqual(expected, dartboard.GetScore(x, y));
        }
Example #14
0
        public void TestGetScore_SB()
        {
            var dartboard = new Dartboard();

            Assert.AreEqual("SB", dartboard.GetScore(2.38, -6.06));
        }
Example #15
0
        public void TestGetScore_X()
        {
            var dartboard = new Dartboard();

            Assert.AreEqual("X", dartboard.GetScore(-133.69, -147.38));
        }
Example #16
0
        public void TestGetScore_D9()
        {
            var dartboard = new Dartboard();

            Assert.AreEqual("D9", dartboard.GetScore(-145.19, 86.53));
        }
Example #17
0
        public void TestGetScore_7()
        {
            var dartboard = new Dartboard();

            Assert.AreEqual("7", dartboard.GetScore(-73.905, -95.94));
        }
Example #18
0
        public void TestGetScore_20()
        {
            var dartboard = new Dartboard();

            Assert.AreEqual("20", dartboard.GetScore(-5.43, 117.95));
        }