private void MouseClicked(object sender, MouseEventArgs e)
        {
            var board = (TicTacToeGui)sender;
            var index = (int[])board.Tag;

            if (e.Button == MouseButtons.Left)
            {
                int row = e.Y / (board.Height / TicTacToe.ROWS);
                int col = e.X / (board.Width / TicTacToe.COLS);

                if (UltimateTicTacToe.LastMove[0] >= 0)
                {
                    Boards[UltimateTicTacToe.LastMove[0], UltimateTicTacToe.LastMove[1]].ShowLastMove = false;
                }

                if (UltimateTicTacToe.Play(index[0], index[1], row, col))
                {
                    board.Played(row, col);

                    board.ShowLastMove = true;

                    Parent.Text = string.Format("Ultimate Tic Tac Toe (Turn: {0}, Moves: {1})", UltimateTicTacToe.GameTurn, UltimateTicTacToe.Moves);
                }
                else
                {
                    Boards[UltimateTicTacToe.LastMove[0], UltimateTicTacToe.LastMove[1]].ShowLastMove = true;
                }

                if (UltimateTicTacToe.GameOver)
                {
                    winAnimation.Start();
                    Parent.Text = string.Format("Ultimate Tic Tac Toe (Won: {0}, Moves: {1})", UltimateTicTacToe.Winner, UltimateTicTacToe.Moves);
                }
            }
        }
        public void NewGame()
        {
            UltimateTicTacToe.NewBoard();

            for (int row = 0; row < TicTacToe.ROWS; ++row)
            {
                for (int col = 0; col < TicTacToe.COLS; ++col)
                {
                    Boards[row, col].NewGame(UltimateTicTacToe.Boards[row, col]);
                }
            }

            winAnimation = new Animation(500);
        }
Пример #3
0
        public UltimateTicTacToe(UltimateTicTacToe clone)
        {
            Boards         = new TicTacToe[ROWS, COLS];
            PlayableBoards = new bool[ROWS, COLS];
            Winner         = clone.Winner;
            GameTurn       = clone.GameTurn;
            LastMove       = new int[] { clone.LastMove[0], clone.LastMove[1] };

            for (int row = 0; row < ROWS; ++row)
            {
                for (int col = 0; col < COLS; ++col)
                {
                    Boards[row, col]         = clone.Boards[row, col].Clone;
                    PlayableBoards[row, col] = clone.PlayableBoards[row, col];
                }
            }
        }
        public UltimateTicTacToeGui()
        {
            InitializeComponent();
            UltimateTicTacToe = new UltimateTicTacToe();

            Boards = new TicTacToeGui[TicTacToe.ROWS, TicTacToe.COLS];

            for (int row = 0; row < TicTacToe.ROWS; ++row)
            {
                for (int col = 0; col < TicTacToe.COLS; ++col)
                {
                    Boards[row, col]                   = new TicTacToeGui(UltimateTicTacToe.Boards[row, col], false);
                    Boards[row, col].Parent            = this;
                    Boards[row, col].MouseClickEnabled = false;
                    Boards[row, col].ShowLastMove      = false;
                    Boards[row, col].MouseClick       += MouseClicked;
                    Boards[row, col].Tag               = new int[] { row, col };
                }
            }

            winAnimation   = new Animation(500);
            Menu[0].Click += (sender, e) => NewGame();
        }