⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 board.java

📁 This the OXO example code plus the presentation. It is intended to provide you with some clues about
💻 JAVA
字号:
/** * Represents a OXO board .  * Each square can either be blank or hold a value *  * @author Ian Bradley  * @version 1.0 March 2008 */public class Board{        private final String BLANK = "";        private String [][] board;    /**     * Constructor for objects of class Board     */    public Board()    {        board = new String[3][3];        for ( int r = 0 ; r < 3 ; r++ )            for ( int c = 0 ; c < 3 ; c++ )                board[r][c] = BLANK;    }    /**     * Sets a cell of the board to a specific character.     *      * @param  coord   the Coord of the cellrow     * @param  ch  the value for the cell     */    public void setCell( Coord coord, String ch)    {        board[coord.getRow()][coord.getColumn()] = ch;    }        /**     * Gets the value held in the given cell.     *      * @param  coord row column pair for cell     * @return the value for the cell     */    public String getCellValue( Coord coord)    {         return board[coord.getRow()][coord.getColumn()] ;    }        /**     * tests to see if there is still space on the board.     *      * @return true if spaces otherwise false      */    public boolean stillSpace()    {        for ( int r = 0 ; r < board.length ; r++ )            for ( int c = 0 ; c < board[r].length ; c++ )                 if (board[r][c].equals(BLANK))                    return true;        return false;    }        /**     * checks for a win.     *      * @return true if a winning line otherwise false     */    public boolean checkWin()    {        return checkRows() || checkColumns() || checkDiagonals();    }        private boolean checkRows()    {        for (int r = 0 ; r < board.length ; r++ )            if ( !( board[r][0].equals(BLANK) ))                if ( ( board[r][0] == board[r][1] ) && ( board[r][1] == board[r][2] ))                    return true;       return false;    }        private boolean checkColumns()    {        for (int c = 0 ; c < board.length ; c++ )            if ( !( board[0][c].equals(BLANK)))                if ( ( board[0][c] == board[1][c] ) && ( board[1][c] == board[2][c] ))                    return true;       return false;    }        private boolean checkDiagonals()    {        if ( !( board[0][0].equals(BLANK) ))           if ( (board[0][0] == board[1][1] ) && ( board[1][1] == board[2][2]) )            return true;        if ( !(board[0][2].equals(BLANK) ))           if ( (board[0][2] == board[1][1] ) && ( board[1][1] == board[2][0]) )            return true;            return false;    }        public Coord getFirstEmptyCell()    {        for ( int r = 0 ; r < board.length ; r++ )            for ( int c = 0 ; c < board[r].length ; c++ )                 if ((board[r][c].equals(BLANK) ))                    return new Coord(r,c);        return null;    }                     }

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -