! Con una puntuación alta, me arrodillé y pedí ayuda para escribir un informe de diseño de curso JAVA para un pequeño programa simple (¡¡detalles !!)
Importar javax.swing.*;
Importar Java.awt.*;
Importar Java.awt.event.*;
Importar Java.awt.event.*;< / p>
La clase pública Lianliankan implementa ActionListener
{
JFrame host
Contenedor thisContainer
JPanel centerPanel; , panel sur, panel norte//Subpanel
Botón de diamantes JButton[][]= new JButton[6][5] //Matriz de botones de juego
JButton exitButton, resetButton, newButton//Botones salir, reordenar y reiniciar
JLabel fraccional able = new JLabel(" 0 "); // Etiqueta fraccionaria
JButton primerBotón, segundoBotón//Grabar por separado Botón seleccionado dos veces .
int grid[][]= new int[8][7]; //Almacena la posición del botón del juego
Información de expresión booleana estática = false //Determina si; el botón está seleccionado.
int x0=0, y0=0, x=0, y=0, fristMsg=0, secondMsg=0, validarLV//Las 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 Lianliankan");
este contenedor = mainframe . getcontentpane();
este contenedor .setlayout()
panel central = new JPanel(); > panel sur = nuevo JPanel();
panel norte = nuevo JPanel();
thisContainer.add(centerPanel, "Centro");
thisContainer . add(southPanel, "South");
thisContainer.add(northPanel, "North");
panel central (new GridLayout(6, 5));
for(int cols = 0; cols lt6; cols ){
for(int filas = 0; número de filas lt5; filas ){
diamantes botón[ columnas][filas]= new JButton(string . value of(grid[cols 1][rows 1]);
Botón rombo [columna][fila].
addActionListener(this);
panel central . add(botón de diamantes[cols][filas]);
}
}
botón de salida = nuevo JButton(" salir ");
botón de salida addactionlistener(this);
botón de reinicio = nuevo JButton(" reagrupar ");
botón de reinicio . addactionlistener(this);
NewlyButton=new JButton("Un juego más");
nuevo botón . panel sur . agregar(botón de salida);
panel sur .add(botón de reinicio);
panel sur (botón recién);
etiqueta de fracción. settext(string . value of(integer . parse int(fraction lable . gettext())));
panel norte . add(fractional able);
mainframe establece límites. (280100500450);
mainframe set visible(true);
}
public void randomBuild() {
int randoms, cols, filas
for(int twins = 1; twins lt=15; twins) {
randoms = (int)(math . random()* 25 1); p> p>
for(int like = 1; similar lt=2; like) {
cols =(int)(math . random()* 6 1);
filas =(int)(matemáticas. aleatorio()* 5 1);
while(grid[cols][filas]! =0) {
cols =(int)(matemáticas. aleatorio()* 6 1);
filas =(int)(matemáticas. aleatorio()* 5 1);
}
este . grid[cols][rows]= aleatorios;
}
}
}
Fracción pública (){
etiqueta de fracción . settext(string . valor de(entero . parse int(etiqueta de fracción . gettext()) 100));
}
Recarga de vacío público() {
int save[]= new int[30];
int n=0, cols, filas
int grid[][]= nuevo
int[8][7];
for(int I = 0; i lt=6; i) {
for(int j = 0; j lt=5; j ) {
if(this.grid[i][j]!=0) {
guardar[n]= this .grid[I][j];
n;
}
}
}
n = n-1;
this.grid = grid
while(n gt;=0) {
cols =(int)(math . random()* 6 1);
filas =(int)(matemáticas. aleatorio()* 5 1);
mientras(grid[cols][filas]!=0) {
cols =(int) (math. random()* 6 1);
filas = (int)(math. random()* 5 1); grid[cols][rows]= save[n];
n-;
}
mainframe establecido visible(false);
pressInformation = false//La información del clic del botón aquí debe clasificarse como inicial.
init();
for(int I = 0;i lt6;i){
for(int j = 0;j lt5;j) {
if(grid[I 1][j 1]= = 0)
Botón rombo [i][j]. set visible(false);
}
}
}
estimación de anulación pública incluso(int placeX, int placeY, JButton bz ) {
if(pressInformation==false) {
x = lugarX
y = lugarY
segundo mensaje = cuadrícula[x ][y];
segundoBotón = bz
pressInformation = true
}
else{
x0 = x;
y0 = y;
fristMsg = segundoMsg
primerBotón = segundoBotón
x = lugarX
y = placeY
segundo mensaje = grid[x][y];
segundoBotón = bz
if(primer mensaje = = segundo mensaje amp; amp ¡Segundo botón! =primerBotón){
小();
}
}
}
Público void xiao() {// ¿Se puede eliminar en la misma situación? Análisis cuidadoso, no notas.
if((x0 = = x amp; amp(y0 = = y 1 | | y0 = = y-1))| |((x0 = = x 1 | | x0 = = x-1 ) amp; amp(y0 = = y)){//Determina si son adyacentes
Remove();
}
En caso contrario{< /. p>
for(j = 0; j lt7; j ) {
If (grid[x0][j]==0){ //Determine qué botón en la primera fila es el botón vacío.
If (y gtJ) {//Si la coordenada Y del segundo botón es mayor que la coordenada Y del botón vacío, el primer botón está a la izquierda del segundo botón.
p >for(I = y-1;i gt= j;I-){//Determine si hay un botón desde el lado izquierdo del segundo botón hasta el primer botón
. if (grid[ x][i]! =0) {
k = 0
Romper
}
else; { k = 1 ;} //K=1 indica que se ha pasado la primera verificación
}
if (k==1) {
. line passone();
}
}
if(y lt; J){ //Si la coordenada Y del segundo botón es menor que la Coordenada Y del botón vacío, entonces el botón A está a la derecha del segundo botón
for(I = y 1; I lt= j; I){ // Determina si hay un botón. entre el lado izquierdo del segundo botón y el primer botón.
if (grid[x][i]!=0){
k = 0
Romper
}<; /p>
else { k = 1;}
}
if (k==1){
paso de línea(); p>
p>
}
}
if (y==j ) {
línea passone();
}
}
si (k==2) {
si (x0==x) {
Eliminar ();
}
if (x0 ltx) {
for(n = x0; n lt= x-1; n ) {
if (grid[n][j]!=0) {
k = 0;
Romper;
}
if (grid[n][j]= = 0 amp; ampn==x-1) {
Eliminar();
}
}
}
if (x0 gtx) {
for(n = x0; n gt= x 1; n - ) {
if (grid[n][j]!=0) {
k = 0;
Romper;
}
if (grid[n][j]= = 0 amp; ampn==x 1) {
Eliminar();
}
} p>
}
}
}
for(I = 0;ilt8;I) {//columna
if (grid[i][y0]==0) {
if(x gt; i) {
for(j = x-1; j gt= I ; j - ) {
if (grid[j][y]!=0) {
k = 0;
Romper;
}
else { k = 1;}
}
if (k==1) {
rowPassOne( ) ;
}
}
if(x lt; i) {
for(j = x 1; j lt= I ; j ) {
if (grid[j][y]!=0) {
k = 0;
Romper;
}
else { k = 1;}
}
if (k==1) {
rowPassOne( ) ;
}
}
if (x==i) {
rowPassOne();
}
}
si (k==2){
si (y0==y) {
eliminar() ;
}
if (y0 lty) {
for(n = y0; n lt= y-1; n ) {
if (cuadrícula[i][n]! =0) {
k = 0;
Romper
}
if(cuadrícula[I][n]= = 0 amperios; ampn==y-1) {
Eliminar();
}<
/p>
}
}
if (y0 gty) {
for(n = y0; n gt= y 1; n - ) {
if (grid[i][n]!=0) {
k = 0
Romper
}
if(grid[I][n]= = 0 amp; ampn==y 1) {
Remove();
} p >
}
}
}
}
}
}
Public void linePassOne(){
If (y0 gtJ){ //El primer botón está en la misma línea y el botón vacío está a la izquierda.
for(I = y0-1;I gt= j;I-){//Determina si hay un botón entre el primer botón y el botón vacío de la izquierda.
if(grid[x0][i]!=0) {
k = 0
Romper
}
else { k = 2 } //K=2 indica que la segunda verificación ha pasado.
}
}
If (y0 ltJ){ //El primer botón está entre el primer botón y el segundo.
for(I = y0 1;i lt= j;i){
if(grid[x0][i]!=0) {
k = 0;
Romper
}
si no { k = 2;}
}
}
}
public void rowPassOne(){
if (x0 gti) {
for(j = x0-1; j gt= I; j - ) {
if (grid[j][y0]!=0) {
k = 0;
Romper ;
}
si no { k = 2;}
}
}
si (x0 lti ) {
for(j = x0 1; j lt= I; j ) {
if (grid[j][y0]!=0) {
k = 0;
Romper
}
si no { k = 2;}
}
}
}
Eliminación de anulación pública(){
primer botón establecido visible(falso);
segundo botón establecido. visible(falso);
Puntuación();
pressInformation = false
k = 0;
Cuadrícula[x0] [y0 ]= 0;
grid[x][y]= 0;
}
acción de anulación pública realizada (evento de acción e){ p>
if(e . getsource()= = nuevo botón){
int grid[][]= new int[8][7];
this. grid
compilación aleatoria();
mainframe establecido visible(falso);
pressInformation = false
init();
}
if(e.getSource()==exitButton)
sistema salida(0);
if( e. getSource()==resetButton)
Sobrecarga();
for(int cols = 0; cols lt6; cols ){
for( int filas = 0; número de filas lt5; filas ){
if(e . getsource()= = botón de diamantes[cols][filas])
estimateEven(columna 1, fila 1. botón de diamantes[columna][fila]);
}
}
}
Public static void main(String[ ] args ) {
Lianliankanllk = Nuevo Lianliankan();
llk . randombuild()
llk .init();
}
}
//998 líneas antiguas
//318 líneas nuevas
Referencia:
/question/36439800.html ? es=qrl3