¿Cuál es el código fuente del juego móvil Play Bricks J2ME?
* Archivo: ControlPanel.java
* Usuario:acacia gratis
* Fecha: 2004.12.3
* Describir : Implementación Java de Tetris
*/
importar javax.swing.*;
importar javax.swing.border importar java.awt.event *. ;
/**
* Clase ControlPanel, heredada de JPanel.
* En la parte superior se muestran la ventana de vista previa, el nivel, la puntuación y los botones de control.
*Se utiliza principalmente para controlar el progreso del juego.
*/
clase ControlPanel extiende JPanel {
JTextField privado
tfLevel = new JTextField("" + ErsBlocksGame.
tfLevel = nuevo JTextField("" + ErsBlocksGame.DEFAULT_LEVEL ),
tfScore = nuevo JTextField("0");
JButton privado
btPlay = nuevo JButton("Reproducir"),
btPause = nuevo JButton("Pausa"),
btStop = nuevo JButton("Pausa"),
btStop = new JButton("Stop"),
btTurnLevelUp = new JButton("Gire fuerte"),
btTurnLevelDown = new JButton("Gire fácil");
TipPanel privado plTipBlock = nuevo TipPanel();
JPanel privado plInfo = nuevo JPanel(nuevo GridLayout(4, 1));
JPanel privado plButton = nuevo JPanel( new GridLayout(5, 1));
temporizador privado
juego ErsBlocksGame privado;
borde de borde privado = new EtchedBorder(
EtchedBorder.RAISED, Color.white, new Color(148, 145, 140));
/**
* Constructor de la clase ControlPanel
* @param game ErsBlocksGame, una referencia de instancia de la clase ErsBoxesGame,
* facilita el control directo del comportamiento de la clase ErsBoxesGame.
setBorder(borde);
plInfo.add(new JLabel("Nivel"));
plInfo.add(tfLevel); nuevo JLabel("Puntuación"));
plInfo.add(tfScore;
plInfo.setBorder(borde);
tfLevel.setEdditable(falso)
tfScore.setEditable(false);
plButton.add(btPlay);
plButton.add(btPause); plButton.add(btStop);
plButton.add(btTurnLevelUp);
plButton.add(btTurnLevelDown
plButton.setBorder(borde); /p>
add(plTip);
add(plInfo);
add(plButton);
addKeyListener(new ControlKeyListener());
btPlay.
addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent ae) {
game.playGame();
})
});
btPause.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent ae) {
if (btPause.getText (). es igual(new String("Pausa")) {
juego.pauseGame();
} else {
juego.resumeGame(); >
}
}
}
}
}
} btStop.addActionListener); (new ActionListener() {
public void actionPerformed(ActionEvent ae) {
game.stopGame();
}
}
}>});
btTurnLevelUp.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent ae) {
intente {
int nivel = Integer.parseInt(tfLevel.getText());
if (nivel < ErsBlocksGame.MAX_LEVEL)
tfLevel.setText(" " + (nivel + 1));
} catch (NumberFormatException e) {
}
requestFocus();
}
});
btTurnLevelDown.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent ae) {
prueba {
int nivel = Integer.parseInt(tfLevel.getText());
if (nivel > 1)
tfLevel.setText("" + (nivel - 1)) ;
}Catch (NumberFormatException e) {
}
requestFocus()
}
}
adComponentListener(new ComponentAdapter() {
componente vacío públicoResized(ComponentEvent ce) {
plTipBlock.fanning();
}).
});
temporizador = nuevo Temporizador(500, nuevo ActionListener(
) {
public void actionPerformed(ActionEvent ae) {
tfScore.setText("" + game.getScore());
int scoreForLevelUpdate =
p>p>
game.getScoreForLevelUpdate =
tfScore.setText("" + game.getScore())getScoreForLevelUpdate()
if (scoreForLevelUpdate >=; ErsBlocksGame.PER_LEVEL_SCORE
p>
&& scoreForLevelUpdate > 0)
game.levelUpdate()
}
juego. nivelUpdate().
});
timer.start()
}
/**
* Establece el estilo de la ventana de vista previa,
* @param style int, correspondiente a los 28 valores en STYLES de la clase ErsBlock
*/ p>
public void setTipStyle(int estilo) {
plTipBlock.setStyle(estilo
}
/**
<); p>* Obtiene el nivel de juego establecido por el usuario.* @return int, nivel de dificultad, 1 - ErsBlocksGame.MAX_LEVEL
*/
public int getLevel() {
int nivel = 0;
prueba {
nivel = Integer.parseInt(tfLevel.getText());
} captura (NumberFormatException e) {
}
}
}
nivel de retorno;
}
/**
* Permite al usuario modificar el nivel de dificultad del juego.
* @param nivel Nivel de dificultad del juego modificado
*/
public void setLevel(int nivel) {
if (nivel > 0 && nivel < 11) tfLevel. setText("" + nivel
}
/**
public void setLevel(int nivel) {
if (nivel > 0 && nivel < 11) tfLevel.
/**
* Establece el estado del botón de inicio.
*/
public void setPlayButtonEnable(boolean enable) {
btPlay.setEnabled(enable);
p>public void setPauseButtonLabel(pausa booleana) {
btPause.setText(pausa ? "Pausa" : "Continuar"
}
/**
* Restablecer panel de control
*/
public void reset() {
tfScore.setText("0 " );
plTipBlock.setStyle(0);
}
/**
* Recalcular cuadros[] en TipPanel [] Tamaño de cuadrados pequeños y medianos
*/
public void fanning() {
plTipBlock.fanning()
}BOXES_COLS; ];
estilo int privado, boxWidth, boxHeight;
private boolean isTiled = false
/**
* Ventana de vista previa. Constructor de clase
*/
*/
public TipPanel() {
for (int i = 0; i < boxes.i++) {
for (int j = 0; j < cajas[i].length; j++)
cajas[i][j] = new ErsBox(false); p>}
}
}
/**
* Constructor de clase de ventana de vista previa
* @ param backColor Color, el color de fondo de la ventana
* @param frontColor Color, el color de primer plano de la ventana
*/
public TipPanel(Color backColor , Color colorfrontal) {
this();
this.
this.frontColor =
}
this.backColor = backColor;
this.frontColor = frontColor.
/**
* Establece el estilo del cuadrado de la ventana de vista previa p>
* @param style int, correspondiente a los 28 valores en la clase ErsBlock STYLES
*/
public void setStyle( int style) {
este.estilo = estilo;
repintar();
}
/**
* Sobrecarga la función de dibujar componentes en la clase JComponent.
* @param g Entorno del dispositivo de gráficos
*/
public void paintComponent(Gráficos g) {
super.paintComponent(g );
if (!isTiled) fanning ();
int key = 0x8000
for (int i = 0; i < boxes.length; i++) {
for (int j = 0; j < boxes[i].
Color color = ((( clave y estilo) ! = 0) ? frontColor : backColor)
g.setColor(color);
g.fill3DRect(j * boxWidth, i * boxHeight,
boxWidth, boxHeight, true); p>
g.fill3DRect(j * boxWidth, i * boxHeight,
boxWidth, boxHeight, true); p>
clave >>= 1;
}
}
}
/**
* Ajusta automáticamente el tamaño del cuadro según el tamaño de ventana
*/
public void fanning() {
boxWidth = getSize().width / ErsBlock.BOXES_COLS
; boxHeight = getSize().height / ErsBlock.BOXES_ROWS;
isTiled = true
}
p>
}
}
}
clase privada ControlKeyListener extiende KeyAdapter {
public void keyPressed(KeyEvent ke) {
if (!game. isPlaying()) return;
ErsBlock block = game.getCurBlock();
switch (ke.getKeyCode()) {
case KeyEvent.VK_DOWN:
block.moveDown();
VK_LEFT:
block.moveLeft();
romper; >case KeyEvent.VK_UP:
block.turnNext();
romper
romper
predeterminado:
descanso
}
}
}
}
.}