在 paintComponent 方法中加入判断游戏是否暂停如果暂停则不进行绘制:javapublic void paintComponentGraphics g superpaintComponentg; forint i=0;iROWS;i++ forint j=0;jCOLS;j++ 判断游戏是否暂停如果暂
public void paintComponent(Graphics g) { super.paintComponent(g); for(int i=0;i<ROWS;i++) { for(int j=0;j<COLS;j++) { ... } } //判断游戏是否暂停,如果暂停则不进行绘制 if(!paused) { if(gameOver) { g.setColor(Color.RED); g.setFont(new Font("宋体", Font.BOLD, 30)); g.drawString("Game Over!", 100, 200); } else { for(int i=0;i<currentPiece.length;i++) { for(int j=0;j<currentPiece[0].length;j++) { if(currentPiece[i][j]!=0) { g.drawImage(currentPiece[i][j].getImage(), (currentCol+j)CELL_SIZE, (currentRow+i)CELL_SIZE, this); } } } for(int i=0;i<ROWS;i++) { for(int j=0;j<COLS;j++) { if(board[i][j]!=0) { g.drawImage(board[i][j].getImage(), jCELL_SIZE, iCELL_SIZE, this); } } } } }
原文地址: http://www.cveoy.top/t/topic/g1pk 著作权归作者所有。请勿转载和采集!