Exemplo n.º 1
0
        // peg display values
        // set a margin based on the peg size

        // constructor takes a reference to the parent element and
        // the number of pegs (and columns) to be inserted in each container
        public PegContainer(StackPanel parent, int numPegs)
        {
            // give the turn a name

            // set some visual properties for the container
            //this.BorderBrush = MainPage.PEG_CONTAINER_COLOUR;
            //this.BorderThickness = new Thickness(PEG_CONTAINER_BORDER);
            //this.Padding = new Thickness(MainPage.PEG_CONTAINER_PADDING);
            //this.Margin = new Thickness(MainPage.PEG_CONTAINER_PADDING);
            this.Name = parent.Name + "pegs";

            // add a new row which, in the case of turns,
            // will be used to indicate the current turn and peg
            this.RowDefinitions.Add(new RowDefinition());

            // add an ellipse which will represent each peg
            for (int i = 1; i <= numPegs; i++)
            {
                // each peg will be placed in its own column,
                // so add a new ColumnDefinition to the PegContainer
                this.ColumnDefinitions.Add(new ColumnDefinition());
                // build a new peg using PegWrapperClass
                PegWrapper pegLocationWrapper = new PegWrapper(
                    parent.Name + "loc",
                    i,
                    MainPage.BORDER_BG,
                    MainPage.PEG_LOCATION_SIZE);

                // add the wrapped element Peg to the PegContainer (this)
                // which extends Grid
                this.Children.Add(pegLocationWrapper.Peg);
            }
        }
Exemplo n.º 2
0
        public ColourPalette(MainPage mainPage, int current_turn, int current_peg)
        {
            this._mainPage = mainPage;

            // layout and colours
            //this.Orientation = Orientation.Vertical;
            this.Padding = new Thickness(5);
            //this.Background = MainPage.SECONDARY_BG;
            //this.BorderBrush = new SolidColorBrush(Colors.Black);
            //this.BorderThickness = new Thickness(1);

            Ellipse el;

            foreach (SolidColorBrush c in MainPage._colorList)
            {
                this.RowDefinitions.Add(new RowDefinition());

                int i = MainPage._colorList.IndexOf(c);

                PegWrapper pegLocationWrapper = new PegWrapper(
                    "colorLoc" + (i + 1),
                    MainPage._colorList.IndexOf(c) + 1,
                    MainPage.BORDER_BG,
                    MainPage.PEG_LOCATION_SIZE
                    );
                pegLocationWrapper.Peg.SetValue(Grid.RowProperty, i);
                pegLocationWrapper.Peg.Margin = new Thickness(10);

                PegWrapper pegWrapper = new PegWrapper(
                    "color" + MainPage._colorList.IndexOf(c) + 1,
                    MainPage._colorList.IndexOf(c) + 1,
                    c,
                    MainPage.PEG_SIZE
                    );
                pegWrapper.Peg.SetValue(Grid.RowProperty, i);
                pegWrapper.Peg.Margin = new Thickness(10);

                pegWrapper.Peg.Tapped += El_Tapped;

                //el = new Ellipse();
                //// TODO: check
                //el.Name = "color" + (MainPage._colorList.IndexOf(c) + 1);
                //el.Fill = c;
                //el.Height = MainPage.PEG_LOCATION_SIZE;
                //el.Width = MainPage.PEG_LOCATION_SIZE;
                //el.Margin = new Thickness(10);
                //el.Tapped += El_Tapped; ;
                this.Children.Add(pegLocationWrapper.Peg);
                this.Children.Add(pegWrapper.Peg);
            }
        }
Exemplo n.º 3
0
        // event handler which fires when a colour is tapped
        // because of the game logic, the majority of the time,
        // this is a move, except for the last peg in the last turn,
        // which is (game over?)
        private void El_Tapped(object sender, Windows.UI.Xaml.Input.TappedRoutedEventArgs e)
        {
            Ellipse tapped = (Ellipse)sender;
            // get the current game state values from the MainPage
            // retrieve the pegLocation which matches these values
            Ellipse elCurrentTurnPegLocation = GetPegLocation(
                MainPage.current_turn, MainPage.current_peg);

            // set the peg colour to the tapped colour
            //elCurrentTurnPegLocation.Fill = tapped.Fill;
            elCurrentTurnPegLocation.Opacity = 100;

            // !!!refactoring to use the PegWrapper class!!!
            // first find the parent element that the new
            // peg should be added to
            PegContainer pegContainer = (PegContainer)elCurrentTurnPegLocation.Parent;

            // the peg should be named turnXpegY, so add the prefix
            PegWrapper pegWrapper = new PegWrapper(
                "turn" + MainPage.current_turn + "peg",
                MainPage.current_peg,
                tapped.Fill,
                MainPage.PEG_SIZE
                );

            pegContainer.Children.Add(pegWrapper.Peg);
            Debug.WriteLine(pegWrapper.Peg.Name);

            //// add a new ellipse into the peg location
            //Ellipse elMove = new Ellipse();
            //elMove.Height = 21;
            //elMove.Width = MainPage.PEG_SIZE;
            ////elMove.SetValue(Canvas.ZIndexProperty, 100);
            //elMove.Fill = tapped.Fill;
            //elMove.SetValue(
            //    Grid.ColumnProperty,
            //    elCurrentTurnPegLocation.GetValue(Grid.ColumnProperty)
            //    );
            //elMove.SetValue(
            //    Grid.RowProperty,
            //    elCurrentTurnPegLocation.GetValue(Grid.RowProperty)
            //    );
            //PegContainer pegContainer = (PegContainer)elCurrentTurnPegLocation.Parent;
            //pegContainer.Children.Add(elMove);
            // go to the next move
            this._mainPage.NextMove();
        }
Exemplo n.º 4
0
        // feedback containers are named turnXfeedback
        private void AddFeedBackMarker(Color colour, int pegNumber)
        {
            Debug.WriteLine("Adding feedbackpeg!!");
            // set a string to search for
            string qryString = "turn" + current_turn + "feedbackpeg" + pegNumber;
            // add a peg to the feedback container
            Ellipse fbPegLocation = FindName(qryString) as Ellipse;
            // now add a new Peg to the same parent and grid positions

            // feedback pegs will (should) be called turnXfeedbackpegYpegY
            PegWrapper pegWrapper = new PegWrapper(
                qryString + "peg",
                pegNumber,
                new SolidColorBrush(colour),
                FEEDBACK_PEG_SIZE
                );

            // TODO: maybe add a method for figuring this out. it could also
            // be used for building the feedback containers initialy
            if (pegNumber == 1)
            {
                pegWrapper.Peg.SetValue(Grid.ColumnProperty, 0);
                pegWrapper.Peg.SetValue(Grid.RowProperty, 0);
            }
            else if (pegNumber == 2)
            {
                pegWrapper.Peg.SetValue(Grid.ColumnProperty, 1);
                pegWrapper.Peg.SetValue(Grid.RowProperty, 0);
            }
            else if (pegNumber == 3)
            {
                pegWrapper.Peg.SetValue(Grid.ColumnProperty, 0);
                pegWrapper.Peg.SetValue(Grid.RowProperty, 1);
            }
            else if (pegNumber == 4)
            {
                pegWrapper.Peg.SetValue(Grid.ColumnProperty, 1);
                pegWrapper.Peg.SetValue(Grid.RowProperty, 1);
            }

            FeedbackContainer fbContainer = FindName("turn" + current_turn + "feedback") as FeedbackContainer;

            Debug.WriteLine(fbContainer.Name);
            fbContainer.Children.Add(pegWrapper.Peg);
        }
Exemplo n.º 5
0
        // generate a new solution and add it to the PegContainer solution object
        private void SetSolution()
        {
            // first, reset the solutionList
            this.solutionList = new List <Ellipse>();
            // TODO: do this a better way
            //this.solution.Width = TURN_CONTAINER_WIDTH;
            // for each number of pegs per turn,
            // add a random colour to the peg container named "solution"
            // name each peg solutionPeg + i
            Ellipse solutionPeg;
            // better to create a random object here and call .Next() multiple times
            Random rand = new Random();

            for (int i = 1; i <= NUM_PEGS_PER_TURN; i++)
            {
                // add the peg location
                PegWrapper pegLocationWrapper = new PegWrapper(solution.Name, i, BORDER_BG, PEG_LOCATION_SIZE);
                this.solution.Children.Add(pegLocationWrapper.Peg);

                // add the actual peg with colour
                solutionPeg = new Ellipse();
                // generate a random number between 0 and the length of
                // _colourList, uppperbound is not included in random
                int _randColourIndex = rand.Next(0, _colorList.Count);
                // create a new pegWrapper with the correct arguments
                PegWrapper pegWrapper = new PegWrapper(
                    "solutionPeg",
                    i,
                    _colorList.ElementAt(_randColourIndex),
                    PEG_SIZE);
                solutionPeg = pegWrapper.Peg;
                // add it to the PegContainer
                this.solution.Children.Add(solutionPeg);
                // also add it to the solutionList
                this.solutionList.Add(solutionPeg);
            }
        }