📄 russioninterface.java~76~
字号:
package russion;/** * <p>Title: RussionCube</p> * <p>Description: TheClassicGame</p> * <p>Copyright: Copyright (c) 2002</p> * <p>Company: Cqu</p> * @author Ghostliang * @version 1.0 */import java.awt.*;public class RussionInterface { private int startX,startY; private Block[][] interBlock; private int totalRow,totalCol; private int blockSize; private Color backGround; public RussionInterface(int totalRow,int totalCol,int blockSize) { this.totalRow = totalRow; this.totalCol = totalCol; this.interBlock = new Block[totalRow][totalCol]; for(int row = 0;row < totalRow;row++) for(int col = 0;col < totalCol;col++) interBlock[row][col] = new Block(); this.blockSize = blockSize; this.backGround = Color.white; this.startX = 0; this.startY = 0; } public void setStartPosition(int x,int y) { startX = x; startY = y; } public void setBlockSize(int newSize) { blockSize = newSize; } public int getBlockSize() { return blockSize; } public int getTotalRow() { return totalRow; } public int getTotalCol() { return totalCol; } public void setBackGround(Color newColor) { backGround = newColor; } public Color getBackGround() { return backGround; } public void setBlock(Block block,int row,int col) { interBlock[row][col] = block; } public Block getBlock(int row,int col) { return interBlock[row][col]; } public boolean canGoLeft(Cube cube) { int row = cube.getStartRow(); int col = cube.getStartCol(); for(int i = 0;i < 4;i++) if((col + cube.getBlock(i).getColumn() - 1) < 0 || this.getBlock(row + (int)cube.getBlock(i).getRow(),col + (int)cube.getBlock(i).getColumn() - 1).isFilled()) return false; return true; } public boolean canGoRight(Cube cube) { int row = cube.getStartRow(); int col = cube.getStartCol(); for(int i = 0;i < 4;i++) if((col + cube.getBlock(i).getColumn() + 1) > totalCol - 1 || this.getBlock(row + (int)cube.getBlock(i).getRow(),col + (int)cube.getBlock(i).getColumn() + 1).isFilled()) return false; return true; } public boolean canGoDown(Cube cube) { int row = cube.getStartRow(); int col = cube.getStartCol(); for(int i = 0;i < 4;i++) if((row + cube.getBlock(i).getRow() + 1) > totalRow - 1 || this.getBlock(row + (int)cube.getBlock(i).getRow() + 1,col + (int)cube.getBlock(i).getColumn()).isFilled()) return false; return true; } public boolean canTranslate(Cube cube) { int row = cube.getStartRow(); int col = cube.getStartCol(); for(int i = 0;i < 4;i++) if(this.getBlock((int)cube.getBlock(i).getColumn() + row,cube.getTotal() - (int)cube.getBlock(i).getRow() - 1 + col).isFilled() || cube.getBlock(i).getColumn() + row > totalRow - 1 || cube.getTotal() - cube.getBlock(i).getRow() + col - 1 < 0 || cube.getTotal() - cube.getBlock(i).getRow() + col - 1 > totalCol - 1) return false; return true; } public void paint(Graphics g) { g.translate(startX,startY); for(int row = 0;row < totalRow;row++) for(int col = 0;col < totalCol;col++) if(interBlock[row][col].isFilled()) { g.setColor(interBlock[row][col].getColor()); g.fillRect(col * 20 + 1,row * 20 + 1,blockSize - 1,blockSize - 1); } else { g.setColor(this.backGround); g.fillRect(col * 20 + 1,row * 20 + 1,blockSize - 1,blockSize - 1); } g.translate(-startX,-startY); } public void setCube(Cube cube) { int total = cube.getTotal(); int row = cube.getStartRow(); int col = cube.getStartCol(); for(int i = 0;i < 4;i++) this.setBlock(new Block(),(int)cube.getBlock(i).getRow() + row,(int)cube.getBlock(i).getColumn() + col); } public boolean rowIsFull(int row) { for(int i = 0;i < totalCol;i++) if(!interBlock[row][i].isFilled()) return false; return true; } public void deleteRow(int row) { for(int i = row;i > 0;i--) for(int j = 0;j < totalCol;j++) interBlock[i][j] = interBlock[i - 1][j]; for(int i = 0;i < totalCol;i++) interBlock[0][i] = new Block(); } public int clearRows() { int rows = 0; for(int i = 0;i < totalRow;i++) if(this.rowIsFull(i)) { this.deleteRow(i); rows++; } return rows; }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -