Cómo utilizar JAVA para programar todo el proceso de diseño de un juego conectado
importjavax.swing.*;
importjava.awt.*;
importjava.awt.event.
publicclass LianLianKan implementa ActionListener {
JFrame mainFrame; // mainPanel
Contenedor thisContainer
JPanel centerPanel, SouthPanel, NorthPanel;
JButton DiamondsButton[][ ] = newJButton[6][5];//Matriz de botones del juego
JButton exitButton, resetButton, newButton; //Botones de salida, reorganización y reinicio
JLabel fraccionalable = newJLabel( "0"); // Etiqueta de puntuación
JButton firstButton, secondButton; // Graba los botones seleccionados dos veces
// Almacena la posición del botón del juego (en realidad solo 6 líneas aquí) 5 columnas Pero estamos usando 8 filas y 7 columnas.
Esto es lo mismo que en este panel donde los botones también están rodeados
// 0 botones en una capa, por lo que puedes darte cuenta de que los dos botones cerca del borde del panel se pueden eliminar)
int grid[][] = new int[8][7];
static boolean pressInformation = false // Determina si el botón está seleccionado
int x0; = 0, y0 = 0 , x = 0, y = 0, firstMsg = 0, secondMsg = 0, validarLV; // Coordenadas de posición del botón del juego
int i, j, k, n / / Control del método de eliminación
public void init() {
mainFrame = new JFrame("JKJ Connect");
thisContainer = mainFrame.getContentPane();
thisContainer.setLayout(new BorderLayout());
centerPanel = nuevo JPanel();
surPanel = nuevo JPanel();
northPanel = new JPanel( );
thisContainer.add(centerPanel)("JKJ Connect");
if (grid[j][y] != 0) {
k = 0;
romper;
} más {
k = 1;
}
}
if (k == 1) {
filaPassOne()
}
}<; /p>
if ( x < i) {// El segundo botón está encima del botón vacío
for (j = x + 1; j <= i; j++) {
if ( grid[j][y] ! = 0) {
k = 0;
break;
} else {
k = 1;
}
}
if (k == 1) {
rowPassOne();
}
}
if ( x == i) {// El segundo botón se usa con este botón vacío
rowPassOne ();
}
}
si ( k == 2) {
si (y0 == y) {/ /segundo El botón está en la misma columna que el primer botón
remove();
}
if (y0 < y) { // los segundos botones están ubicados a la derecha del primer botón
for (n = y0; n <= y - 1; n++) {
if (grid[i][ norte] ! = 0) {
k = 0;
romper;
}
if (grid[i][n] == 0 && n == y -1) {
eliminar();
}
}
}
if (y0 & gt; y) {// El segundo botón está a la izquierda del primer botón
> for (n = y0; n >= y + 1; n--) {
if (grid[i][n] != 0) {
k = 0 ;
break;
}
if (grid[i][n] == 0 && n == y +1) {
eliminar();
}
}
}
}
}
p> }/--------------------------------para
}/ -------------else
}/------------xiao
public void linePassOne() {
if (y0 > j) { // El primer botón y el botón vacío de la izquierda
for (i = y0 - 1; i >= j; i--) { // Determinar si hay botones entre el primer botón y el botón vacío de la izquierda
if (grid[x0][i] != 0) {
k = 0;
break;
} else {
k = 2;
}// K=2 significa que la segunda verificación pasó
}
}
}
if (y0 < j) { // El lado derecho del primer botón está vacío botón
for (i = y0 + 1; i <= j; i++) {
if (grid[x0][i] != 0) {
k = 0;
romper;
} más {
k = 2;
}
}
}
}
public void rowPassOne() {
if (x0 >.i) {// primer botón Debajo de su botón de espacio
for (j = x0 - 1; j >= i; j--) {
if (grid[j][y0] != 0) {
k = 0;
romper;
} más {
k = 2;
}
}
}
if (x0 <i) {/// El primer botón está encima del botón de espacio en la misma columna que este p>
for (j = x0 + 1; j <= i; j++) {
if (grid[j][y0] ! = 0) {
k = 0;
romper;
} más {
k = 2;
}
}
}
}
public void remove() {
firstButton.setVisible (falso);
fracción();
pressInformation = false;
k = 0;
grid[x0] [y0 ] = 0;
grid[x][y] = 0;
}
acción nula pública realizada (ActionEvent e)
{
if (e.getSource() == newButton) {
int grid[][] = new int[8][7];
this.grid = grid;
randomBuild();
mainFrame.setVisible(false);
pressInformation = false
init; ();
}
if (e.getSource() == exitButton)
System.exit(0);
Sistema.salir(0);