Ejemplo n.º 1
0
        public void GameButton_Click(object sender, RoutedEventArgs e)
        {
            if (true == wingame)
            {
                MessageBox.Show("You have to restart again to play game");
                return;
            }

            GameButton      btn      = sender as GameButton;
            GameButtonState btnState = new GameButtonState(btn.Id, btn);
            // int digit = Convert.ToInt32(btn.Content.ToString());
            int row   = ((int)btn.GetValue(Grid.RowProperty));
            int col   = ((int)btn.GetValue(Grid.ColumnProperty));
            int digit = row * nRows + col;

            btn.Position    = digit;
            btnState.Oldpos = btn.Position;
            //record into undo/redo stack before moving.
            btn.Move();
            btnState.Newpos = btn.Position;
            gameUndoStack.Push(btn);
            gameReplayList.Add(btnState);

            Title = gameUndoStack.Count.ToString();
        }//end GameButton_Click
Ejemplo n.º 2
0
 void undoItem_Click(object sender, RoutedEventArgs e)
 {
     try
     {
         //fromgamestatelist remove lastitem
         GameButton btn = gameUndoStack.Pop();
         btn.Move();
         Title = gameUndoStack.Count.ToString();
     }
     catch (Exception ex)
     {
         MessageBox.Show("Game Board Is in Original State!, No further undo possible");
     }
 }
Ejemplo n.º 3
0
        void ResetBoard()
        {
            //reset content on buttons
            int counter = 0;

            foreach (GameButton btn in grid1.Children)
            {
                btn.SetInSquare((btn.Id + 1)); //1based index
                counter++;
                if ((nSquares - 1) == counter)
                {
                    break;
                }
            }

            //randomizetiles to intial position
            RandomizeTiles();
            GameButton.InitializeEmptySquares(nSquares - 1);
        }
Ejemplo n.º 4
0
        public void CreateNumberGrid()
        {
            for (int i = 0; i < nRows; i++)
            {
                RowDefinition rowdef = new RowDefinition();
                //rowdef.Height = GridLength.Auto;
                grid1.RowDefinitions.Add(rowdef);
            }

            for (int i = 0; i < nCols; i++)
            {
                ColumnDefinition coldef = new ColumnDefinition();
                //coldef.Width = GridLength.Auto;
                grid1.ColumnDefinitions.Add(coldef);
            }

            GameButton.InitializeEmptySquares(nSquares - 1);

            //surround it with border
        }
Ejemplo n.º 5
0
        public void CreateTiles()
        {
            int tileCount = 1;

            for (int r = 0; r < nRows; r++)
            {
                for (int c = 0; c < nCols; c++)
                {
                    if (tileCount == (nSquares))
                    {
                        break;
                    }
                    //both id and position are initially same
                    GameButton btn = new GameButton(r * nRows + c, r * nCols + c);
                    btn.Content          = r * nRows + c + 1;
                    btn.Click           += new RoutedEventHandler(GameButton_Click);
                    btn.PropertyChanged += new System.ComponentModel.PropertyChangedEventHandler(btn_PropertyChanged);
                    grid1.Children.Add(btn);
                    Grid.SetRow(btn, r);
                    Grid.SetColumn(btn, c);
                    tileCount++;
                }
            }
        }
Ejemplo n.º 6
0
 public GameButtonState(int id, GameButton btn)
 {
     _id         = id;
     _gameButton = btn;
 }