コード例 #1
0
        // move marker will be added to row 1 in the turn container
        // and column (peg_number)
        public void AddNextMovemarker(int numTurn, int numPeg)
        {
            // remove any existing move markers
            try
            {
                // if the ellipse can be found
                Ellipse oldMoveMarker = FindName("nextMoveMarker") as Ellipse;
                // remove it from its parent...
                ((PegContainer)oldMoveMarker.Parent).Children.Remove(oldMoveMarker);
            }
            catch
            {
                // not found, no problem?
            }
            // ...and add the new marker
            // find the correct turn container (PegContainer)
            PegContainer turnContainer = FindName("turn" + numTurn + "pegs") as PegContainer;


            // add an ellipse object in row 1, column numPeg -1 of the turn container
            Ellipse nextMove = new Ellipse();

            nextMove.Name   = "nextMoveMarker";
            nextMove.Height = 10;
            nextMove.Width  = 10;
            nextMove.Fill   = new SolidColorBrush(Colors.White);

            nextMove.SetValue(Grid.RowProperty, 0);
            nextMove.SetValue(Grid.ColumnProperty, numPeg - 1);

            turnContainer.Children.Add(nextMove);
        }
コード例 #2
0
        // called from NextMove() if a new turn has been detected
        // at the end of a turn, check the turn pegs against the solution pegs
        public void CalculateTurnEnd()
        {
            // going to create two lists and compare
            List <Ellipse> turnPegs = new List <Ellipse>();
            // find the correct pegContainer: named turnXpegs
            PegContainer pegContainer = FindName("turn" + current_turn + "pegs") as PegContainer;

            Debug.WriteLine(pegContainer.Name);

            // get each colour from the current turn,
            // compare these colours against the solution colours and indexes
            // simply find any Ellipses that have a name starting with
            // turnXpeg where X is the turn number
            string queryString = "turn" + current_turn + "peg";

            Debug.WriteLine(queryString);
            foreach (var item in pegContainer.Children)
            {
                if (item.GetType() == typeof(Ellipse))
                {
                    Ellipse peg = (Ellipse)item;
                    if (peg.Name.StartsWith(queryString))
                    {
                        //Debug.WriteLine);
                        turnPegs.Add(new Ellipse
                        {
                            Fill = peg.Fill
                        });
                    }
                }
            }
            if (turnPegs.Count == solutionList.Count)
            {
                // list is the correct size
                Debug.WriteLine("Checking turn " + current_turn + " values!");
                CompareLists(turnPegs);
            }
            else
            {
                // error
                Debug.WriteLine("turn " + current_turn + " error!");
            }


            // if it is the last turn
            // TODO: Game Over?
            if (BLACK_PEGS_ADDED == NUM_PEGS_PER_TURN)
            {
                // You Won
                this.solution.Visibility = Visibility.Visible;
            }
            else if (current_turn == NUM_TURNS)
            {
                this.solution.Visibility = Visibility.Visible;
                // Game Over - did not win
                // Show the solution
            }
        }
コード例 #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();
        }
コード例 #4
0
        public TurnContainer(int turnNumber)
        {
            this.turnNumber = turnNumber;
            this.Padding    = new Thickness(5);

            this.BorderBrush     = MainPage.BORDER_BG;
            this.BorderThickness = new Thickness(MainPage.BORDER_THICKNESS);

            this.Background = MainPage.SECONDARY_BG;

            this.Orientation         = Orientation.Horizontal;
            this.HorizontalAlignment = HorizontalAlignment.Right;

            this.Name = "turn" + turnNumber;

            this.feedBackContainer = new FeedbackContainer(this);
            this.Children.Add(feedBackContainer);

            this.pegContainer = new PegContainer(this, pegContainerSize);
            this.Children.Add(this.pegContainer);

            //MainPage.TURN_CONTAINER_WIDTH = this.Width;
        }
コード例 #5
0
        private void BuildTheBoard()
        {
            // clear the board
            this.boardGrid.Children.Clear();

            // add stackpanel to grid 1, 0 - colspan 2 - name it "spTurns"
            StackPanel spTurns = new StackPanel();

            spTurns.SetValue(Grid.ColumnProperty, 0);
            spTurns.SetValue(Grid.RowProperty, 1);

            // add a button for debugging - check the solution
            Button btn = new Button();

            btn.Content = "Reveal";
            this.boardGrid.Children.Add(btn);
            // add its handler
            btn.Tapped += btn_Tapped;

            // create the solution peg container
            // TODO: don't add the solution yet as it may need to be loaded from AppData
            // so create the solution in method SetSolution()
            this.solution            = new PegContainer(spTurns, 4);
            this.solution.Name       = "solution";
            this.solution.Background = SECONDARY_BG;
            this.solution.SetValue(Grid.ColumnProperty, 0);
            this.solution.SetValue(Grid.RowProperty, 0);
            this.solution.HorizontalAlignment = HorizontalAlignment.Right;
            // TODO: calculate total size of a turncontainer
            //  - (and then) set a left padding here
            this.solution.Padding = new Thickness(
                60,
                MainPage.PEG_CONTAINER_PADDING,
                MainPage.PEG_CONTAINER_PADDING,
                MainPage.PEG_CONTAINER_PADDING);

            this.solution.BorderBrush     = BORDER_BG;
            this.solution.BorderThickness = new Thickness(BORDER_THICKNESS);
            this.boardGrid.Children.Add(this.solution);

            // for each turn (numTurns), add a turn container to spTurns - decrementing loop
            // add each turn container to the stackpanel
            // turn1 is at the bottom of the stack panel, so
            // reverse the loop
            for (int i = NUM_TURNS; i >= 1; i--)
            {
                // turns begin at 10, end at 1
                spTurns.Children.Add(new TurnContainer(i));
            }

            this.boardGrid.Children.Add(spTurns);

            // build and add the control panel element, passing the
            // current turn and peg values
            // add this to a stackpanel
            StackPanel    spColourPaletteContainer = new StackPanel();
            ColourPalette cpColourPalette          = new ColourPalette(this, current_turn, current_peg);

            cpColourPalette.Name   = "colourPallette";
            cpColourPalette.Margin = new Thickness(5);
            spColourPaletteContainer.SetValue(Grid.ColumnProperty, 1);
            spColourPaletteContainer.SetValue(Grid.RowProperty, 1);
            spColourPaletteContainer.Children.Add(cpColourPalette);
            this.boardGrid.Children.Add(spColourPaletteContainer);
        }