Red de conocimientos turísticos - Información de alquiler - ¡El juego más difícil jamás visto! Después de salir del programa, el nivel se borra y se espera ayuda en línea. urgente, urgente, urgente

¡El juego más difícil jamás visto! Después de salir del programa, el nivel se borra y se espera ayuda en línea. urgente, urgente, urgente

Este es el código fuente de un juego de Tetris

Aún no está terminado, el código es demasiado largo, usé otro número de teléfono y luego lo pegué

También importé javax.swing.

p>

Importar javax.swing.border.Border; Importar javax.swing.border.EtchedBorder.

/ **

* La clase principal del juego hereda de JFrame Class, responsable del control global del juego.

Incluyendo

* 1. Instancia de la clase de lienzo GameCanvas referenciada

2. Instancia del bloque activo actual (ErsBlock)

* 3. Instancia guardada del panel de control (ControlPanel);

Público ****El uso de Class ErsBlocksGame extiende JFrame {

/ **

* Cada línea Cómo hay muchos puntos* /

final static int PER_LINE_SCORE = 100

/ **

* El número de puntos actualizables en el gráfico* / p>

int estático final PER_LEVEL_SCORE = 100; /

int estático final PER_LINE_SCORE = 100 LEVEL_SCORE = PER_LINE_SCORE * 20; > * El número máximo de niveles es 10 * /

final static int MAX_LEVEL = 10; default

/ **

* series* /

estática final pública que interpreta el DEFAULT_LEVEL = 5;

lienzo GameCanvas privado;

bloque ErsBlock privado

juego booleano privado = FALSE; /p>

Panel de control privado "ctrlPanel"

Barra JMenuBar privada nueva JMenuBar();

JMenu privada

MGAME nuevo JMenu ("Configuración del juego" ),

p>

mControl new JMenu ("Controles del juego")

mWindowStyle = new JMenu ("Estilo de ventana");

JMenuItem privado

miNewGame = nuevo JMenuItem ("Nuevo juego")

miSetBlockColor = nuevo JMenuItem ("Establecer color...."),

miSetBackColor nuevo JMenuItem ("Establecer fondo color...")

miTurnHarder = new JMenuItem ("Subir el nivel"

miTurnEasier = new JMenuItem ("Nivel inferior ajustado")

miExit = nuevo JMenuItem ("Salir")

miPlay = nuevo JMenuItem ("Iniciar juego"),

miPause = nuevo JMenuItem ("Pausa"),

miResume nuevo JMenuItem ("Continuar");

JCheckBoxMenuItem privado

miAsWindows: miAsMotif = nuevo JCheckBo

xMenuItem a ("estilo") ,

miAsMetal = new JCheckBoxMenuItem A ("estilo", true);

/ **

* Estructura de clases principal del juego Función

.

Título de la ventana de cadena de título * /

: public *** ErsBlocksGame (nombre de cadena) {

super (título

// this.setTitle ( "lskdf);

setSize (315, 392 );

y tamaño scrSize = Toolkit.getDefaultToolkit ().getScreenSize();

// Obtener el Tamaño de pantalla

A paralelo setLocation((scrSize.width - getSize() ancho) / 2

(scrSize.height - getSize() alto) / 2

);

createMenu();

ContainerCargo = getContentPane();

contenedor.setLayout(new BorderLayout(6, 0)

Canvas = nuevo); GameCanvas(20, 12);

ctrlPanel new ControlPanel" (este);

Usar Container.add (lienzo, usando BorderLayout.CENTER)

Usar Contenedor .add (ctrlPanel, BorderLayout's.EAST);

página addWindowListener (nuevo WindowAdapter (){

invalidwindowClosing (WindowEvent us){

JOptionPane's about = new JOptionPane's ();

stopGame();

System.exit(0);}

}.

}); /p>

addComponentListener(new ComponentAdapter() {

canvas.fanning();

}

}

}

});

show();

lienzo.fanning(); />}

// Juego "reset"

Reset no válido(){

ctrlPanel.reset()

lienzo. reset();

}BR /> / **

* Determinar si el juego aún está en progreso

_at_ devuelve un valor booleano, todavía ejecutándose verdadero false Detenido* /

Módulo booleano IsPlaying() {

Devolver reproducción

}

/ **

* Bloque actualmente activo

_at_ devuelve, ErsBlock referencia del bloque actualmente activo* /

del getCurBlock "public***" de ErsBlock (){

bloque de retorno

}

/ **

* Al lienzo actual

* _at_return, bloque activo actual en GameCanvas referencia del lienzo actual */

gotGameCanvas getCanvas (){

returns canvas}

/ **

* Iniciar el juego* / public*** invalid

joke (){

> play (

ctrlPanel.setPlayButtonEnable (false); >

miPlay.setEnabled (false);

ctrlPanel.requestFocus();}

/ ** BR /> *Juego en pausa* /

public *** void pausaGame(){

(¡bloque! = NULL) block.pauseMove();

ctrlPanel.setPauseButtonLabel (falso); miPause.setEnabled (false);

p> miResume.

/ **

Sigamos pausando el juego* /

public *** null resumeGame() {

(block = null) block.resumeMove "();

ctrlPanel.setPauseButtonLabel (TRUE);

miPause. setEnabled (VERDADERO);

miResume.setEnabled (falso);

ctrlPanel.requestFocus()

}

( bloque = nulo).

/ **

* El usuario detiene el juego* /

public invalid stopGame() {

play = FALSE

; p >

(¡bloque! = NULL) bloque. stopMove();

miPlay.setEnabled(TRUE);

miPause.setEnabled(TRUE); p > miResume.setEnabled(false);

ctrlPanel setPlayButtonEnable();

ctrlPanel.setPauseButtonLabel(TRUE); / **

*El juego comienza* /

Juego privado no válido() {

Restablecer()

Hit= TRUE

p>

Hilo de hilos=Nuevo Tema (Nuevo Juego());

thread.start()

}

<; p>/ **

/ **

*ReportGameOver* /

private void reportGameOver(){

JOptionPane.showMessageDialog ( this, "¡El juego ha terminado! ")

}

* Crear y configurar el menú de la ventana* /

El privado no válido createMenu() {

bar.add(MGAME);

bar.add(mControl

bar.add( mWindowStyle

);

mGame.add (miNewGame);

mGame.addSeparator();

mGame.add(miSetBlockColor);

> MGAME.add(miTurnHarder);

mGame.add(miTurnEasier);

mGame.addSeparator();

mControl.add(miPause);

mControl.setAccelerator(

KeyStroke.getKeyStroke(KeyEvent.VK_P, KeyEvent.CTRL_MASK)); /p>

miResume.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0));

BR /> miNewGame.addActionListener(new ActionListener()){

void actionPerformed(AE de ActionEvent){

stopGame();

reset();

setLevel(DEFAULT_LEVEL}

});

p>

miSetBlockColor.addActionListener(new ActionListener(){

actionPerformed no válida(AE de ActionEvent){

color newFrontColor =

ColorPicker .ShowDialog( ErsBlocksGame.this,

"setBuildingColorBlock, canvas.getBlockColor ());

(newFrontColor! = NULL)

canvas.setBlockColor(newFrontColor); /> }

});

miSetBackColor.addActionListener(new ActionListener(){

Acción realizada no válida (AE de ActionEvent) {

color newBackColor =

JColorChooser.showDialog( ErsBlocksGame Establece el color de fondo. Esto,

"canvas.getBackgroundColor of ());

of (newBackColor! = NULL )

canvas.setBackgroundColor (newBackColor); <

} });

miTurnHarder.addActionListener(newActionListener(){

acción realizada no válida (AE de ActionEvent){

interpreta curLevel getLevel();

(curLevel <; MAX_LEVEL ) setLevel(curLevel + 1);

}

.

};

miTurnEasier.addActionListener(new ActionListener()); {

acción realizada no válida (AE de ActionEvent){

curLevel = getLevel();

(curLevel> 1) setLevel(curLevel - 1); p>

}.

});

miExit.addActionListener(new ActionListener(){ BR />public*** Acción realizada no válida (AE de ActionEvent){

(0 );

});

}).

});

miPlay.addActionListener(new ActionListener(){

broma();

});

}

}

miPause.addActionListener(new ActionListener(){

acción realizada no válida (AE de ActionEvent){

pausaGame();}

}).

});

miResume.addActionListener(new ActionListener(){

acción realizada no válida (AE de ActionEvent) { BR /> resumeGame ();

}).

});

página miAsWindows.addActionListener (nueva ActionListener(){

actionPerformed no válida ( AE de ActionEvent){ ....../> string PLAF = "com.sun.java.swing.plaf.windows.WindowsLookAndFeel

setWindowStyle(PLAF);

lienzo .fanning();

ctrlPanel.ctrlPanel.fanning();

miAsWindows.setState(TRUE);

miAsMetal.setState(Falso); p>

p>

miAsMotif.setState(False);

} pp

} p>});

miAsMotif.'s método addActionListener (nuevo ActionListener(){

ActionPerformed no válido (AE de ActionEvent){

String PLAF = "com.sun.java.swing.plaf.motif.MotifLookAndFeel";

setWindowStyle (PLAF);

lienzo.fanning();

ctrlPanel.miAsWindows.setState(false);

miAsMetal.setState( false);

miAsMotif.

});

miAsMetal. addActionListener (new ActionListener(){

actionPerformed no válida (AE de

ActionEvent){

String PLAF" javax.swing.plaf.metal.MetalLookAndFeel";

setWindowStyle(PLAF

canvas.fanning(); /p>

ctrlPanel.fanning();

miAsWindows.setState(falso)

miAsMetal.setState(TRUE);

miAsMotif.setState( false);

}

}

}

/ **
p>

_ at_ El parámetro PLAF establece la apariencia de la ventana

* / /

setWindowStyle(string PLAF){

intenta {

UIManager.setLookAndFeel(PLAF)

SwingUtilities.updateComponentTreeUI(this);

} captura (Excepción 5) {

}.

}

}

/ *

* Durante el juego, la interfaz Runnable

* El juego es un gran bucle que se reproduce cada 100 milisegundos

Comprueba si el fragmento actual está en el juego, ya sea al final, y si no,

sigue esperando. Si al final, mira si hay una línea completa

* Si se elimina, el jugador de bonificación genera una aleatoriamente

* El bloque actual caerá automáticamente. * Genera un nuevo mosaico, primero verifica si la línea en el lienzo

está llena y, de ser así, el juego ha terminado.

El juego de clase privada implementa Runnable {

Public*** invalid run(){

// Genera rápidamente un nuevo método

Nivel entero = (INT) (Math.random() * (canvas.getCols() - 3)),

estilo = ErsBlock.STYLES [(INT)(Math.random()* 7) ] [(INT)(Math.random()* 4)]; ....../> while (play){

If (block! = NULL){/ / primer bucle, bloque nulo

(block.isAlive()){

Intentos { tema currentThread().Sleep (100);

} captura (InterruptedException de Internet Explorer) {

es decir.printStackTrace();

}

}

continuar

}

}

}

checkFullLine() // / Comprueba la línea

si está completamente llena (, isGameOver()){/ / Comprueba este juego ¿Debería terminar?

miPlay.setEnabled(TRUE);

setEnabled() de miPause

miResume.setEnabled (false); > ctrlPanel.setPlayButtonEnable (VERDADERO);

ctrlPanel.setPauseButtonLabel (VERDADERO);

reportGameOver ()

informe; / p>

bloque=NewErsBlock(estilo, -1, col, getLevel(),, lienzo

bloque.Inicio()

Columnas= (INT) ( Math.random()*(canvas.getCols() - 3));

Estilo= ErsBlock.STYLES [(INT)(Math.random()* 7)] [(INT)(Matemáticas) . random()* 4)];

ctrlPanel.setTipStyle(style);

}

}

* Verifique el completo. relleno de línea, si se elimina* /

checkFullLine() no válido {

for (int i = 0; I < canvas.

(J = 0; J < canvas.getCols( ); + +){

(,!canvas.getBox(I, J). isColorBox()){

fullLineColorBox = FALSE;

descanso

}

}

}

}

(fullLineColorBox){< / p>

línea = - ;

lienzo.

>

}

}

}

/ **

Determina si el juego ha finalizado según la línea superior registrada . * @ Devuelve un valor booleano que indica que el fin del juego real no es un fin del juego falso * /

isGameOver es (){

(INT I = 0; I

ErsBox box = canvas.getBox(0, I

(box.isColorBox ()) devuelve verdadero;}

Devuelve falso

}

}