Exemplo n.º 1
0
        public void DrawChess()
        {
            chessMatrix = new AsiaChessButton[Cons.BOARD_HEIGH, Cons.BOARD_WIDTH];

            Point location;

            for (int i = 0; i < Cons.BOARD_HEIGH; i++)
            {
                for (int j = 0; j < Cons.BOARD_WIDTH; j++)
                {
                    // Swap i, j to normal because it's nature
                    location = new Point(Cons.MARGIN + j * Cons.CELL_SIZE - Cons.CHESS_SIZE / 2, Cons.MARGIN + i * Cons.CELL_SIZE - Cons.CHESS_SIZE / 2);
                    AsiaChessButton chess = new AsiaChessButton()
                    {
                        Location  = location,
                        Size      = new Size(Cons.CHESS_SIZE, Cons.CHESS_SIZE),
                        FlatStyle = FlatStyle.Popup
                    };


                    if (Cons.map[i, j] == Cons.CHESS_VALUE)
                    {
                        chess.BackColor     = Cons.CHESS_COLOR;
                        chess.MyOriginColor = Cons.CHESS_COLOR;
                        chess.ChessValue    = Cons.CHESS_VALUE;
                    }
                    else if (Cons.map[i, j] == Cons.BOSS_VALUE)
                    {
                        chess.BackColor     = Cons.BOSS_COLOR;
                        chess.MyOriginColor = Cons.BOSS_COLOR;
                        chess.ChessValue    = Cons.BOSS_VALUE;
                    }
                    else if (Cons.map[i, j] == Cons.EMPTY_VALUE)
                    {
                        //chess.FlatAppearance.BorderSize = 0;
                        chess.BackColor     = Cons.EMPTY_COLOR;
                        chess.MyOriginColor = Cons.EMPTY_COLOR;
                        chess.ChessValue    = Cons.EMPTY_VALUE;
                    }
                    else
                    {
                        chess.ChessValue = Cons.INVALID_VALUE;
                    }

                    // Handle click
                    chess.RowIndex    = i;
                    chess.ColIndex    = j;
                    chessMatrix[i, j] = chess;

                    if (Cons.map[i, j] == Cons.INVALID_VALUE)
                    {
                        continue;
                    }
                    chess.Click += Chess_Click;
                    this.chessPanel.Controls.Add(chess);
                }
            }
        }
Exemplo n.º 2
0
        public AsiaChessButton getEmptyChess(int rowIndex, int colIndex)
        {
            Point           location = new Point(Cons.MARGIN + colIndex * Cons.CELL_SIZE - Cons.CHESS_SIZE / 2, Cons.MARGIN + rowIndex * Cons.CELL_SIZE - Cons.CHESS_SIZE / 2);
            AsiaChessButton chess    = new AsiaChessButton()
            {
                Location  = location,
                Size      = new Size(Cons.CHESS_SIZE, Cons.CHESS_SIZE),
                FlatStyle = FlatStyle.Popup
            };

            chess.BackColor     = Cons.EMPTY_COLOR;
            chess.MyOriginColor = Cons.EMPTY_COLOR;
            chess.ChessValue    = Cons.EMPTY_VALUE;
            return(chess);
        }
Exemplo n.º 3
0
        public void DrawChessPanel()
        {
            hintChesses     = new List <AsiaChessButton>();
            hintEatChesses  = new List <AsiaChessButton>();
            justMoveChesses = new List <AsiaChessButton>();
            selected_chess  = null;

            chessPanel = new Panel();
            //chessPanel.Enabled = false;
            chessPanel.BorderStyle = BorderStyle.Fixed3D;
            int boardwidth  = 2 * Cons.MARGIN + Cons.CELL_SIZE * Cons.MAX_COL;
            int boardHeight = 2 * Cons.MARGIN + Cons.CELL_SIZE * (Cons.MAX_ROW + Cons.SMALL_DIAMON_HEIGH);

            chessPanel.Width    = boardwidth;
            chessPanel.Height   = boardHeight;
            chessPanel.Location = new Point(20, 20);
            chessPanel.Paint   += ChessPanel_Paint;

            mainForm.Controls.Add(chessPanel);
        }
Exemplo n.º 4
0
        private void DrawChess()
        {
            Point location;

            for (int i = 0; i <= Cons.MAX_COL + Cons.SMALL_DIAMON_HEIGH; i++)
            {
                for (int j = 0; j <= Cons.MAX_ROW; j++)
                {
                    // Swap i, j to normal because it's nature
                    location = new Point(Cons.MARGIN + j * Cons.CELL_SIZE - Cons.CHESS_SIZE / 2, Cons.MARGIN + i * Cons.CELL_SIZE - Cons.CHESS_SIZE / 2);
                    AsiaChessButton chess = new AsiaChessButton()
                    {
                        Location  = location,
                        Size      = new Size(Cons.CHESS_SIZE, Cons.CHESS_SIZE),
                        FlatStyle = FlatStyle.Popup,
                        BackColor = Color.Transparent
                    };

                    if (Cons.map[i, j] == Cons.CHESS_VALUE)
                    {
                        chess.Text = "Tot";
                    }
                    else if (Cons.map[i, j] == Cons.BOSS_VALUE)
                    {
                        chess.Text = "Tuong";
                    }
                    else if (Cons.map[i, j] == Cons.EMPTY_VALUE)
                    {
                    }
                    else
                    {
                        continue;
                    }
                    this.chessPanel.Controls.Add(chess);
                }
            }
        }
Exemplo n.º 5
0
        private void Chess_Click(object sender, EventArgs e)
        {
            AsiaChessButton current_chess = sender as AsiaChessButton;

            #region Check valid turn
            if (
                (current_chess.isBoss() && GAME_TURN != Cons.BOSS_TURN) ||
                (current_chess.isChess() && GAME_TURN != Cons.CHESS_TURN)
                )
            {
                return;
            }
            #endregion

            #region First click on empty chess
            if (selected_chess == null && current_chess.isEmptyChess())
            {
                return;
            }
            #endregion

            #region Select a chess
            if (selected_chess == null && !current_chess.isEmptyChess())
            {
                selected_chess           = current_chess;
                selected_chess.BackColor = Cons.SELECTED_COLOR;
                int i = selected_chess.RowIndex;
                int j = selected_chess.ColIndex;
                hintChesses = getListMove(i, j);
                PaintHintChess(Cons.SHOW_HINT);

                if (current_chess.isBoss())
                {
                    hintEatChesses = getListEat(i, j);
                    PaintHintEatChess(Cons.SHOW_HINT);
                }

                return;
            }
            #endregion

            #region  Re-click chess (unselected)
            if (selected_chess == current_chess)
            {
                selected_chess.BackColor = selected_chess.MyOriginColor;
                selected_chess           = null;
                PaintHintChess(Cons.REMOVE_HINT);

                if (current_chess.isBoss())
                {
                    PaintHintEatChess(Cons.REMOVE_HINT);
                }
                return;
            }
            #endregion

            #region Change selected
            if (selected_chess.ChessValue == current_chess.ChessValue)
            {
                PaintHintChess(Cons.REMOVE_HINT);
                PaintHintEatChess(Cons.REMOVE_HINT);
                RemoveAllHint();

                selected_chess.BackColor = selected_chess.MyOriginColor;
                selected_chess           = current_chess;
                selected_chess.BackColor = Cons.SELECTED_COLOR;

                int i = selected_chess.RowIndex;
                int j = selected_chess.ColIndex;
                hintChesses = getListMove(i, j);
                PaintHintChess(Cons.SHOW_HINT);

                if (current_chess.isBoss())
                {
                    hintEatChesses = getListEat(i, j);
                    PaintHintEatChess(Cons.SHOW_HINT);
                }
                return;
            }
            #endregion

            #region Move chess
            if (!selected_chess.isEmptyChess() && current_chess.isEmptyChess() && hintChesses.Contains(current_chess))
            {
                // Only move if in hint list
                PaintHintChess(Cons.REMOVE_HINT);
                PaintHintEatChess(Cons.REMOVE_HINT);
                RemoveAllJustMove();
                justMoveChesses.Add(selected_chess);

                if (selected_chess.isBoss())
                {
                    current_chess.ChessValue    = Cons.BOSS_VALUE;
                    current_chess.MyOriginColor = Cons.BOSS_COLOR;
                    current_chess.BackColor     = Cons.BOSS_COLOR;
                }
                else
                {
                    current_chess.ChessValue    = Cons.CHESS_VALUE;
                    current_chess.MyOriginColor = Cons.CHESS_COLOR;
                    current_chess.BackColor     = Cons.CHESS_COLOR;
                }

                selected_chess.ChessValue    = Cons.EMPTY_VALUE;
                selected_chess.BackColor     = Cons.JUST_MOVE_COLOR;
                selected_chess.MyOriginColor = Cons.EMPTY_COLOR;

                selected_chess = null;
                ChangeTurn();
                return;
            }
            #endregion

            #region Eat chess
            if (selected_chess.isBoss() && current_chess.isChess() && hintEatChesses.Contains(current_chess))
            {
                PaintHintChess(Cons.REMOVE_HINT);
                PaintHintEatChess(Cons.REMOVE_HINT);
                RemoveAllHint();

                // Selected --> empty
                selected_chess.ChessValue    = Cons.EMPTY_VALUE;
                selected_chess.MyOriginColor = Cons.EMPTY_COLOR;
                selected_chess.BackColor     = Cons.JUST_MOVE_COLOR;

                // current --> boss
                current_chess.ChessValue    = Cons.BOSS_VALUE;
                current_chess.MyOriginColor = Cons.BOSS_COLOR;
                current_chess.BackColor     = Cons.BOSS_COLOR;

                selected_chess = null;
                ChangeTurn();
                return;
            }
            #endregion
        }