- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在开发俄罗斯方 block 程序。我正在重用一个功能完美的 Tron 程序来制作它。在 Tron 程序中,GUI 工作得很好,但在 Tetris 程序中,我无法弹出任何 GUI 窗口,甚至网格也不行。我还需要弹出另一个窗口来告诉设置的控件。如果您尝试的话,非常感谢。下面我给大家提供两套方案
俄罗斯方 block
public class Board extends JPanel {
private static final long serialVersionUID = 1l;
public static boolean death = false;
public static int score = 0;
public static String direction;
public static int numberTetris = 1;
public static final int numRows = 10;
public static final int numCols = 18;
public static final int size = 20;
public static int[][] grid = new int[10][218];
public Board(Tetris tempTetris){
grid[10][18] = 8;
setPreferredSize(new Dimension(numCols * size, numRows * size));
setBackground(Color.DARK_GRAY);
}
//Erases the grid to be filled with zeros
public static void restart(int[][] gr){
for (int i = 0; i <= numCols; i++){
for (int j = 1; j <= numRows; j++){
grid[i][j] = 0;
}
}
Piece.nextTetris();
}
//Swts the graphics component
public void paintComponent(Graphics g){
super.paintComponent(g);
g.drawString("score: " + score, 10, 10);
g.setColor(Color.DARK_GRAY);
g.drawRect(0, 0 , getWidth() - 1, getHeight() - 1);
for (int x = 0; x < numCols; x++){
for (int y = 0; y < numRows; y++){
g.drawLine(x * size, 0, x * size, getHeight());
g.drawLine(0, y * size, getWidth(), y * size);
}
}
}
//Fills in the spaces
private void drawTile(int x, int y, int type, Graphics g){
x *= size;
y *= size;
switch (type){
case 1:
if (Piece.type == 1){
//ZShape
g.setColor(Color.ORANGE);
if (Piece.pieceDirection == 270 || Piece.pieceDirection == 90){
g.fillRect(Piece.centerX - 1, Piece.centerY, size, size);
g.fillRect(Piece.centerX, Piece.centerY, size, size);
g.fillRect(Piece.centerX, Piece.centerY - 1, size, size);
g.fillRect(Piece.centerX + 1, Piece.centerY - 1, size, size);
}
if (Piece.pieceDirection == 180 || Piece.pieceDirection == 0){
g.fillRect(Piece.centerX + 1, Piece.centerY + 1, size, size);
g.fillRect(Piece.centerX + 1, Piece.centerY, size, size);
g.fillRect(Piece.centerX, Piece.centerY, size, size);
g.fillRect(Piece.centerX, Piece.centerY - 1, size, size);
}
}else if (Piece.type == 2){
//"SShape;
g.setColor(Color.BLUE);
if (Piece.pieceDirection == 270 || Piece.pieceDirection == 90){
g.fillRect(Piece.centerX + 1, Piece.centerY, size, size);
g.fillRect(Piece.centerX, Piece.centerY, size, size);
g.fillRect(Piece.centerX, Piece.centerY - 1, size, size);
g.fillRect(Piece.centerX - 1, Piece.centerY - 1, size, size);
}
if (Piece.pieceDirection == 180 || Piece.pieceDirection == 0){
g.fillRect(Piece.centerX, Piece.centerY + 1, size, size);
g.fillRect(Piece.centerX, Piece.centerY, size, size);
g.fillRect(Piece.centerX + 1, Piece.centerY, size, size);
g.fillRect(Piece.centerX + 1, Piece.centerY - 1, size, size);
}
}else if (Piece.type == 3){
//LineShape;
g.setColor(Color.RED);
if (Piece.pieceDirection == 270 || Piece.pieceDirection == 90){
g.fillRect(Piece.centerX - 2, Piece.centerY, size, size);
g.fillRect(Piece.centerX - 1, Piece.centerY, size, size);
g.fillRect(Piece.centerX, Piece.centerY, size, size);
g.fillRect(Piece.centerX + 1, Piece.centerY, size, size);
}
if (Piece.pieceDirection == 180 || Piece.pieceDirection == 0){
g.fillRect(Piece.centerX, Piece.centerY + 1, size, size);
g.fillRect(Piece.centerX, Piece.centerY, size, size);
g.fillRect(Piece.centerX, Piece.centerY - 1, size, size);
g.fillRect(Piece.centerX, Piece.centerY - 2, size, size);
}
}else if (Piece.type == 4){
//TShape;
g.setColor(Color.GREEN);
if (Piece.pieceDirection == 270){
g.fillRect(Piece.centerX - 1, Piece.centerY, size, size);
g.fillRect(Piece.centerX, Piece.centerY, size, size);
g.fillRect(Piece.centerX + 1, Piece.centerY, size, size);
g.fillRect(Piece.centerX, Piece.centerY - 1, size, size);
}
if (Piece.pieceDirection == 90){
g.fillRect(Piece.centerX - 1, Piece.centerY, size, size);
g.fillRect(Piece.centerX, Piece.centerY, size, size);
g.fillRect(Piece.centerX + 1, Piece.centerY, size, size);
g.fillRect(Piece.centerX, Piece.centerY + 1, size, size);
}
if (Piece.pieceDirection == 180){
g.fillRect(Piece.centerX, Piece.centerY + 1, size, size);
g.fillRect(Piece.centerX, Piece.centerY, size, size);
g.fillRect(Piece.centerX, Piece.centerY - 1, size, size);
g.fillRect(Piece.centerX - 1, Piece.centerY, size, size);
}
if (Piece.pieceDirection == 0){
g.fillRect(Piece.centerX, Piece.centerY + 1, size, size);
g.fillRect(Piece.centerX, Piece.centerY, size, size);
g.fillRect(Piece.centerX, Piece.centerY - 1, size, size);
g.fillRect(Piece.centerX + 1, Piece.centerY, size, size);
}
}else if (Piece.type == 5){
//SqaureShape;
g.setColor(Color.YELLOW);
if (Piece.pieceDirection == 270 || Piece.pieceDirection == 180 || Piece.pieceDirection == 90 || Piece.pieceDirection == 0){
g.fillRect(Piece.centerX - 1, Piece.centerY, size, size);
g.fillRect(Piece.centerX, Piece.centerY, size, size);
g.fillRect(Piece.centerX - 1, Piece.centerY - 1, size, size);
g.fillRect(Piece.centerX, Piece.centerY - 1, size, size);
}
}else if (Piece.type == 6){
//LShape;
g.setColor(Color.DARK_GRAY);
if (Piece.pieceDirection == 270){
g.fillRect(Piece.centerX - 1, Piece.centerY - 1, size, size);
g.fillRect(Piece.centerX - 1, Piece.centerY, size, size);
g.fillRect(Piece.centerX, Piece.centerY, size, size);
g.fillRect(Piece.centerX + 1, Piece.centerY, size, size);
}
if (Piece.pieceDirection == 90){
g.fillRect(Piece.centerX - 1, Piece.centerY, size, size);
g.fillRect(Piece.centerX, Piece.centerY, size, size);
g.fillRect(Piece.centerX + 1, Piece.centerY, size, size);
g.fillRect(Piece.centerX + 1, Piece.centerY + 1, size, size);
}
if (Piece.pieceDirection == 180){
g.fillRect(Piece.centerX - 1, Piece.centerY + 1, size, size);
g.fillRect(Piece.centerX, Piece.centerY + 1, size, size);
g.fillRect(Piece.centerX, Piece.centerY, size, size);
g.fillRect(Piece.centerX, Piece.centerY - 1, size, size);
}
if (Piece.pieceDirection == 0){
g.fillRect(Piece.centerX, Piece.centerY + 1, size, size);
g.fillRect(Piece.centerX, Piece.centerY, size, size);
g.fillRect(Piece.centerX, Piece.centerY - 1, size, size);
g.fillRect(Piece.centerX + 1, Piece.centerY - 1, size, size);
}
}else if (Piece.type == 7){
//MirroredLShape;
g.setColor(Color.MAGENTA);
if (Piece.pieceDirection == 270){
g.fillRect(Piece.centerX - 1, Piece.centerY, size, size);
g.fillRect(Piece.centerX, Piece.centerY, size, size);
g.fillRect(Piece.centerX + 1, Piece.centerY, size, size);
g.fillRect(Piece.centerX + 1, Piece.centerY - 1, size, size);
}
if (Piece.pieceDirection == 90){
g.fillRect(Piece.centerX - 1, Piece.centerY + 1, size, size);
g.fillRect(Piece.centerX - 1, Piece.centerY, size, size);
g.fillRect(Piece.centerX, Piece.centerY, size, size);
g.fillRect(Piece.centerX + 1, Piece.centerY, size, size);
}
if (Piece.pieceDirection == 180){
g.fillRect(Piece.centerX, Piece.centerY + 1, size, size);
g.fillRect(Piece.centerX, Piece.centerY, size, size);
g.fillRect(Piece.centerX, Piece.centerY - 1, size, size);
g.fillRect(Piece.centerX - 1, Piece.centerY - 1, size, size);
}
if (Piece.pieceDirection == 0){
g.fillRect(Piece.centerX + 1, Piece.centerY + 1, size, size);
g.fillRect(Piece.centerX, Piece.centerY + 1, size, size);
g.fillRect(Piece.centerX, Piece.centerY, size, size);
g.fillRect(Piece.centerX, Piece.centerY - 1, size, size);
}
}
break;
//Used pieces
case 2:
g.setColor(Color.BLACK);
g.fillRect(x, y, size, size);
break;
//The grid
case 3:
g.setColor(Color.WHITE);
break;
}
//Pretty much refreshes the board
public static void repaint(){
for (int i = 0; i <= numCols; i++){
for (int j = -1; j >= numRows; j--){
if (grid[i][j] == 2){
drawTile(i, j, 2, g);
}else if (grid[i][j] == 0){
drawTile(i, j, 3, g);
}
}
}
}
}
public class Piece extends JFrame {
public static final long serialVersionUID = 1L;
public Board board;
public static final int x = 1;
public static final int y = 1;
public static int centerX = 10;
public static int centerY = 10;
public static final int north = 90;
public static final int east = 0;
public static final int south = 270;
public static final int west = 180;
public static int pieceDirection = south;
public static int pieceCount;
public static Piece[][] piece1 = new Piece[x][y];
public static Piece[][] piece2 = new Piece[x][y];
public static Piece[][] piece3 = new Piece[x][y];
public static Piece[][] piece4 = new Piece[x][y];
public static int a;
public static String pieceName;
public static int[][] usedPieceCoords = new int[Board.numRows][Board.numCols];
public static int type;
/*
* type = 1 == ZShape
type = 2 == SShape
type = 3 == LineShape
type = 4 == TShape
type = 5 == SquareShape
type = 6 == LShape
type = 7 == MirroredLShape
*/
public static final int firstCenterX = 4;
public static final int firstCenterY = -1;
//Constructs a piece obeject at a certain pair of coordinates
public Piece(int X, int Y, int num){
centerX = X;
centerY = Y;
type = num;
}
//Checks if the piece has gone out of set bounds, I still haven't done anything to it, but advice would be helpful
public static boolean checkCollision(){
if (centerX == 20 || centerY == 20 || centerX == -1 || centerY == -1){
Tetris.gameOver = true;
Board.death = true;
Tetris.gameOver();
}
return false;
}
//Makes a new tetris and puts it in the game
public static void nextTetris(){
a = (int)(Math.random());
Piece centerPiece = new Piece(firstCenterX, firstCenterY, a);
}
//I intend to increase speed until it hits the piece under it
public static void drop() {
}
//Moves the piece one space to the right
public static void moveRight() {
Board.grid[centerX][centerY] = 0;
centerX =+ 1;
}
//Moves the piece one space to the left
public static void moveLeft() {
Board.grid[centerX][centerY] = 0;
Board.grid[centerX - 1][centerY] = 1;
}
//Rotates the piece 90 degrees clockwise
public static void turnPiece(){
pieceDirection -= 90;
if (Tetris.tetrisName == ""){
}
}
}
public class Tetris extends JFrame {
private static final long serialVersionUID = 1L;
private Board board;
public static int speed = 250;
public static int segmentCount = 4;
public static boolean gameOver = false;
public static boolean start = false;
public static String tetrisName;
//Makes a tetris object, still to define it more as creating a certain object based on Piece.type
public Tetris(){
super("Tetris");
setLayout(new BorderLayout());
setDefaultCloseOperation(EXIT_ON_CLOSE);
setResizable(false);
this.board = new Board(this);
add(board, BorderLayout.CENTER);
//the key listeners
addKeyListener(new KeyAdapter() {
public void keyPressed(KeyEvent e) {
switch(e.getKeyCode()){
case KeyEvent.VK_W:
case KeyEvent.VK_UP:
Piece.turnPiece();
break;
case KeyEvent.VK_S:
case KeyEvent.VK_DOWN:
speed =+ 10;
break;
case KeyEvent.VK_A:
case KeyEvent.VK_LEFT:
Piece.moveLeft();
break;
case KeyEvent.VK_D:
case KeyEvent.VK_RIGHT:
Piece.moveRight();
break;
case KeyEvent.VK_SPACE:
Piece.drop();
}
}
});
pack();
setLocationRelativeTo(null);
setVisible(true);
runGame();
}
//The delay portion and the starting of the game
public void runGame(){
while (gameOver == false){
try{
Thread.sleep(150);
}
catch(Exception e){}
if (start){
//self-collision check
if (Board.grid[Piece.centerX][Piece.centerY] >= -1){
gameOver = true;
Board.death = true;
gameOver();
}
board.repaint();
}
}
}
//This just outprints "GAME OVER" to the consule when it is called
public static void gameOver(){
System.out.println("GAME OVER");
}
//This outputs the number that the certain name corresponds to
public int getType(String tetrisName){
if (tetrisName == "ZShape"){
Piece.type = 1;
}else if (tetrisName == "SShape"){
Piece.type = 2;
}else if (tetrisName == "LineShape"){
Piece.type = 3;
}else if (tetrisName == "TShape"){
Piece.type = 4;
}else if (tetrisName == "SquareShape"){
Piece.type = 5;
}else if (tetrisName == "LShape"){
Piece.type = 6;
}else if (tetrisName == "MirroredLShape"){
Piece.type = 7;
}
return Piece.type;
}
//Making a new piece, tetris, and board
public static void main(String[] args){
int a = (int)(Math.random() * 7);
Piece centerPiece = new Piece(Piece.firstCenterX, Piece.firstCenterY, a);
Tetris tetris = new Tetris();
new Board(tetris);
}}
创
public class Snake extends JFrame{
private static final long serialVersionUID = 1L;
private Board board;
public static int a = 10;
public static int b = 10;
public static int c;
public static int d;
public static int flag = 0;
public static int headX = 3;
public static int headY = 20;
public static int speed = 100;
public static String snakeDirection = "east";
public static int segmentCount;
public static int segmentCount2;
public static boolean gameOver = false;
public static boolean gameOver2 = false;
public static boolean start = false;
public static boolean start2 = false;
public static int[][] segments = new int[2][400];
public static int[][] segments2 = new int[2][400];
public static int headX2 = 37;
public static int headY2 = 20;
public static String snakeDirection2 = "west";
//Creates Snake
public static void main(String[] args) {
Snake snake = new Snake();
new Board(snake);
}
public Snake(){
super("Snake");
setLayout(new BorderLayout());
setDefaultCloseOperation(EXIT_ON_CLOSE);
setResizable(false);
this.board = new Board(this);
add(board, BorderLayout.CENTER);
addKeyListener(new KeyAdapter(){
public void keyPressed(KeyEvent e){
switch (e.getKeyCode()){
// checks if keys are pressed
case KeyEvent.VK_UP:
if(snakeDirection != "south"){
snakeDirection = "north";
start = true;
}
break;
case KeyEvent.VK_W:
if(snakeDirection2 != "south"){
snakeDirection2 = "north";
start2 = true;
}
break;
case KeyEvent.VK_DOWN:
if(snakeDirection != "north") {
snakeDirection = "south";
start = true;
}
break;
case KeyEvent.VK_S:
if(snakeDirection2 != "north") {
snakeDirection2 = "south";
start2 = true;
}
break;
case KeyEvent.VK_LEFT:
if(snakeDirection != "east") {
snakeDirection = "west";
start = true;
}
break;
case KeyEvent.VK_A:
if(snakeDirection2 != "east") {
snakeDirection2 = "west";
start2 = true;
}
break;
case KeyEvent.VK_RIGHT:
if(snakeDirection != "west") {
snakeDirection = "east";
start = true;
}
break;
case KeyEvent.VK_D:
if(snakeDirection2 != "west") {
snakeDirection2 = "east";
start2 = true;
}
break;
}
}
});
pack();
setLocationRelativeTo(null);
setVisible(true);
runGame();
}
public void runGame(){
while(gameOver == false) {
segmentCount = Board.numberSegments;
try {
Thread.sleep(speed);
} catch (Exception e) {
}
if(start) {
//checks to see if the snake collided with itself
if(Board.grid[headX][headY] == 1){
gameOver = true;
Board.death = true;
gameOver();
}
if(Board.grid[headX2][headY2] == 1){
gameOver = true;
Board.death = true;
gameOver();
}
// changes depending on which direction the snake is going
if(snakeDirection.equals("north")) {
headY -= 1;
System.out.println("Player 111(Coord):" + headX + " " + headY);
if(checkCollision() == true){
while (segmentCount > 0){
segments[0][segmentCount] = segments[0][segmentCount - 1];
segments[1][segmentCount] = segments[1][segmentCount - 1];
segmentCount -= 1;
}
segments[0][0] = headX;
segments[1][0] = headY + 1;
}
}
if(snakeDirection2.equals("north")) {
System.out.println("Player 222(Coord):" + headX2 + " " + headY2);
headY2 -= 1;
if(checkCollision() == true){
while (segmentCount2 > 0){
segments2[0][segmentCount2] = segments2[0][segmentCount2 - 1];
segments2[1][segmentCount2] = segments2[1][segmentCount2 - 1];
segmentCount2 -= 1;
}
segments2[0][0] = headX2;
segments2[1][0] = headY2 + 1;
}
}
if(snakeDirection.equals("east")){
headX += 1;
System.out.println("Player 111(Coord):" + headX + " " + headY);
if(checkCollision() == true){
while(segmentCount > 0){
segments[0][segmentCount] = segments[0][segmentCount - 1];
segments[1][segmentCount] = segments[1][segmentCount - 1];
segmentCount -= 1;
}
segments[0][0] = headX - 1;
segments[1][0] = headY;
}
}
if(snakeDirection2.equals("east")){
headX2 += 1;
System.out.println("Player 222(Coord):" + headX2 + " " + headY2);
if(checkCollision() == true){
while(segmentCount2 > 0){
segments2[0][segmentCount2] = segments2[0][segmentCount2 - 1];
segments2[1][segmentCount2] = segments2[1][segmentCount2 - 1];
segmentCount2 -= 1;
}
segments2[0][0] = headX2 - 1;
segments2[1][0] = headY2;
}
}
if(snakeDirection.equals("south")){
headY += 1;
System.out.println("Player 111(Coord):" + headX + " " + headY);
if(checkCollision() == true){
while(segmentCount > 0){
segments[0][segmentCount] = segments[0][segmentCount - 1];
segments[1][segmentCount] = segments[1][segmentCount - 1];
segmentCount -= 1;
}
segments[0][0] = headX;
segments[1][0] = headY - 1;
}
}
if(snakeDirection2.equals("south")){
headY2 += 1;
System.out.println("Player 222(Coord):" + headX2 + " " + headY2);
if(checkCollision() == true){
while(segmentCount2 > 0){
segments2[0][segmentCount2] = segments2[0][segmentCount2 - 1];
segments2[1][segmentCount2] = segments2[1][segmentCount2 - 1];
segmentCount2 -= 1;
}
segments2[0][0] = headX2;
segments2[1][0] = headY2 - 1;
}
}
if(snakeDirection.equals("west")){
headX -= 1;
System.out.println("Player 111(Coord):" + headX + " " + headY);
if(checkCollision() == true){
while(segmentCount > 0){
segments[0][segmentCount] = segments[0][segmentCount - 1];
segments[1][segmentCount] = segments[1][segmentCount - 1];
segmentCount -= 1;
}
segments[0][0] = headX + 1;
segments[1][0] = headY;
}
}
if(snakeDirection2.equals("west")){
headX2 -= 1;
System.out.println("Player 222(Coord):" + headX2 + " " + headY2);
if(checkCollision() == true){
while(segmentCount2 > 0){
segments2[0][segmentCount2] = segments2[0][segmentCount2 - 1];
segments2[1][segmentCount2] = segments2[1][segmentCount2 - 1];
segmentCount2 -= 1;
}
segments2[0][0] = headX2 + 1;
segments2[1][0] = headY2;
}
}
board.repaint();
//sees i the game is still going
if(!gameOver) {
segmentCount = Board.numberSegments;
if(Board.grid[headX][headY] != 0) {
gameOver = true;
Board.death = true;
gameOver();
}
Board.grid[headX][headY] = 2;
//Board.grid[segments[0][segmentCount]][segments[1][segmentCount]] = 0;
//while(segmentCount > 0) {
//Board.grid[segments[0][segmentCount]][segments[1][segmentCount]] = 1;
//segmentCount -= 1;
//}
if(Board.grid[headX2][headY2] != 0) {
gameOver = true;
Board.death = true;
gameOver();
}
Board.grid[headX2][headY2] = 12;
Board.grid[segments2[0][segmentCount2]][segments2[1][segmentCount2]] = 10;
while(segmentCount2 > 0) {
Board.grid[segments2[0][segmentCount2]][segments2[1][segmentCount2]] = 11;
segmentCount2 -= 1;
}
board.repaint();
}
}
}
}
//makes sure the game is over
public void gameOver(){
System.out.println("GGGGGAAAAAAAMMMMMMMEEEEEEE OOOOOOVVVVVEEEEERRRR");
for(int i = 0; i < 20; i++){
System.out.println(segments2[0][i] + " " + segments2[1][i]);
}
}
//checks to see if the snake collided with the boarder
public boolean checkCollision(){
if(headX == 41 || headY == 41 || headX == -1 || headY == -1){
gameOver = true;
Board.death = true;
gameOver();
return false;
}
return true;
}
public boolean checkCollision2(){
if(headX2 == 41 || headY2 == 41 || headX2 == -1 || headY2 == -1){
gameOver2 = true;
Board.death = true;
gameOver();
return false;
}
return true;
}
}
public class Board extends JPanel{
private static final long serialVersionUID = 1l;
public static int x = 10;
public static int y = 10;
public static int a = 10;
public static int b = 10;
public static int n = 10;
public static int m = 10;
public static int s;
public static int sg;
public static int erase = 20;
public static int erase2 = 20;
public static boolean death = false;
public static boolean death2 = false;
public static int segmentAdd;
public static int score = 0;
public static boolean touchedFruit = false;
public static boolean isFruit = false;
public static String direction;
public static String direction2;
public static int numberSegments = 5;
public static int numberSegments2 = 5;
public static String bodyDirection;
public static String tailDirection;
public static String bodyDirection2;
public static String tailDirection2;
public static final int num_rows = 40;
public static final int num_cols = 40;
public static int size = 15;
public static int [][] grid = new int[40][40];
//makes board
public Board(Snake tempSnake){
grid[10][10] = 0;
setPreferredSize(new Dimension(num_cols * size, num_rows * size));
setBackground(Color.WHITE);
}
public void paintComponent(Graphics g){
super.paintComponent(g);
deathTracker(g);
for(int i = 0; i < 40; i++){
for(int j = 0; j < 40; j++){
if(grid[i][j] != 0){
drawTile(i,j,grid[i][j],g);
}
}
}
//bodyTracker(g);
//bodyTracker2(g);
System.out.println("Player 111:" + (numberSegments + 2));
System.out.println("Player 222:" + (numberSegments2 + 2));
g.setColor(Color.WHITE);
g.drawRect(0, 0, getWidth()-1, getHeight()-1);
for(int x = 0; x < num_cols; x++){
for(int y = 0; y < num_cols; y++){
g.drawLine(x * size, 0, x * size, getHeight());
g.drawLine(0, y * size, getWidth(), y * size);
}
}
}
private void drawTile(int x, int y, int type, Graphics g){
x *= size;
y *= size;
switch(type){
case 1:
g.setColor(Color.GREEN);
g.fillRect(x, y, size, size);
break;
case 2:
g.setColor(Color.RED);
g.fillRect(x, y, size, size);
break;
case 3:
g.setColor(Color.GREEN);
g.fillRect(x, y, size, size);
break;
case 4:
g.setColor(Color.RED);
g.fillRect(x, y, size, size);
break;
case 11:
g.setColor(Color.PINK);
g.fillRect(x, y, size, size);
break;
case 12:
g.setColor(Color.MAGENTA);
g.fillRect(x, y, size, size);
break;
case 10:
g.setColor(Color.CYAN);
g.fillRect(x, y, size, size);
break;
}
}
private void drawTile2(int x, int y, int type, Graphics g){
x *= size;
y *= size;
switch(type){
case 11:
g.setColor(Color.RED);
g.fillRect(x, y, size, size);
break;
case 12:
g.setColor(Color.RED);
g.fillRect(x, y, size, size);
break;
case 10:
g.setColor(Color.RED);
g.fillRect(x, y, size, size);
break;
}
}
public void bodyTracker(Graphics g){
if(!Snake.gameOver){
s = numberSegments;
numberSegments += 1;
drawTile(Snake.headX, Snake.headY, grid[Snake.headX][Snake.headY], g);
while(s >= 0){
if(s > 0){
drawTile(Snake.segments[0][s], Snake.segments[1][s], grid[Snake.segments[0][s]][Snake.segments[1][s]], g);
}
if(s == 0){
drawTile(Snake.segments[0][s], Snake.segments[1][s], 4, g);
}
s -= 1;
}
}
}
public void bodyTracker2(Graphics g){
if(!Snake.gameOver){
sg = numberSegments2;
numberSegments2 += 1;
drawTile2(Snake.headX2, Snake.headY2, grid[Snake.headX2][Snake.headY2], g);
while(sg >= 0){
if(sg > 0){
drawTile2(Snake.segments2[0][sg], Snake.segments2[1][sg], grid[Snake.segments2[0][sg]][Snake.segments2[1][sg]], g);
}
if(s == 0){
drawTile2(Snake.segments2[0][sg], Snake.segments2[1][sg], 4, g);
}
sg -= 1;
}
}
}
public void deathTracker(Graphics g){
if (death = true){
erase = 20;
while(erase > 0 && erase2 > 0){
drawTile(erase, erase2, 0, g);
erase -= 1;
if(erase == 0){
erase2 -= 1;
}
}
}
}}
最佳答案
您的俄罗斯方 block 程序有两个 JFrame,但都没有正确创建。 “Piece”绝对不应该是JFrame。阅读“Swing 教程”,一旦您知道如何创建无功能的 GUI 窗口,请重试。
关于java - 俄罗斯方 block 程序的 GUI 出现故障,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21640332/
我有一个无 GUI 的服务器(没有任何桌面环境或 Ubuntu 服务器的新鲜 Debian,没有 X 服务器,先验)。 我考虑安装 docker 并拉取一个基于官方 Ubuntu 的容器,并在其上添加
我正在构建一个带有临时用户名系统的简单聊天服务器。当屏幕弹出时,首先会出现一个简单的屏幕,询问您的用户名。你可以放入任何你想要的东西,这纯粹是暂时的(我也在尝试)。代码告诉程序继续,将用户名保存到代码
我想将来自其他类的图像显示到 QLabel 中,但要通知 GUI 有一个新的框架可用。我需要从非 GUI 类和非 GUI 线程发出信号。 有什么办法吗? 最佳答案 signal 可以从任何继承QObj
我正在用 Java 编写一个图形用户界面,它有一些按钮,其中一个按钮是选项。我想要它,所以当您单击选项时,它会将 gui 更改为我的选项 gui,而不是在另一个窗口中打开它。 我该怎么做? 最佳答案
标题说明了一切...我和我的 friend 正在这样做,我们不知道为什么 Ball.java 实际上没有在 gamePanel 中制作球,然后制作 GUI。顺便说一句,这是 8 球台球。这是代码: 驱
我正在使用 GUI 构建器,我想知道是否有一种简单的方法可以通过当前主窗口打开寄存器窗口(引用下面的页面)。我正在尝试通过菜单栏来执行此操作。 我一整天都在尝试,因为 GUI Builder 生成了一
我有一个程序使用了许多隐藏的 GUI 组件。例如,所有菜单项和打印机对话框/组件(仅占用至少 50 毫秒)。总的来说,我猜整个程序启动的大约 300 毫秒(或 40%)要归功于所有隐藏的东西。 我想做
我对 GUI 构建比较陌生。 我想制作一个带有按钮(我已经有了)的 GUI,用户可以按下该按钮并选择一个图像,然后动态地将该图像加载到面板中的 GUI 中。我希望每次用户浏览图像时图像都动态变化。 到
我有两年使用 Java 和 Visual Studio 进行企业应用程序编程的经验,而且我是 Python 和 wxPython 的新手。所以我的问题是:wxPython 能否为我提供足够丰富的 GU
这是我启动 mkvtoolnix-gui 时遇到的错误: mkvtoolnix-gui: symbol lookup error: mkvtoolnix-gui: undefined symbol:
我在初始屏幕上有一些最近使用的存储库,我想删除它们,因为我不再使用它们了。如何删除它们? 操作系统 = Windows 7 我查看了注册表并搜索了 git 目录,但找不到最近使用列表的存储位置。 最佳
我正在尝试在 matlab、GUI 中用户输入点作为输入和它们之间的连接。 我有 5 个 matlab 文件 - screen1.m、screen2.m、screen3.m、screen4.m、glo
我用java制作了一个客户端/服务器程序,我已经按照我想要的方式使用cmd完美地工作了,现在我正在尝试将代码的客户端转换为GUI,但是我在打印时遇到问题客户端消息并从文本字段和服务器消息读取客户端输入
我正在制作一种 CRUD 应用程序(Java GUI,MYSQL)我应该: 将数据从数据库加载到List(例如),然后将List加载到GUI 将数据从数据库加载到对象(具有 SQL 表等属性)和对象到
我正在开发一个有 5 个图形用户界面窗口的 Java 应用程序,其中一个是问候窗口或主窗口,我已经完成了所有逻辑部分的工作,我已经完成了 99.99%,唯一剩下的就是我如何以这种方式编码,当我点击一个
我目前正在开发 GUI。 我选择将我的 GUI 基于 bluej 项目 - Scribble。 当您创建 ScribbleGUI 对象时,DrawDemo 类会创建一个同时自动打开的 Canvas 。
在这里阅读了很多关于多进程、管道等的内容后,我还没有找到答案,但如果它已经存在,我深表歉意。 我有一个外围硬件,我正在尝试为其创建一个 GUI。我想让 GUI 使用来自外围设备的数据不断更新,同时仍保
我想做的是将 GUI 从一个单独文件中的类链接到另一个类。我的第一个类是一个主菜单,它将显示一些链接到另一个窗口的按钮。第二个类显示不同的窗口,但我现在遇到的问题是我不知道如何链接第一个类中的按钮来调
我的 GUI 代码中有一个奇怪的行为。如果用户在短时间内产生大量事件,则可能会发生正在运行的事件处理程序方法被另一个事件处理程序方法中断。由于一切都在同一个线程(GUI 线程)中运行,所以一切都应该按
这是一个涉及风格的问题。我正在寻找可以帮助我解决常见 GUI 设计问题 的想法。该应用程序是在 Winforms 中完成的,宁愿使用 WPF,该应用程序已经完成,但我是一个完美主义者,在与其他人合作时
我是一名优秀的程序员,十分优秀!