Paso 1: configuración
Paso 1:
Abierto de Java de Eclipse (https://eclipse.org/downloads/)
Paso 2:
Copia este código:
paquete com.rps.ZemByte;
Import java.awt.*; Import java.awt.event.*; Import java.util.Random;
Import javax.swing.*;
clase principal
{
JFrame RPS;
JButton roca, papel, tijeras, VersionButton;
PRDs JTextField;
JTextField CRPS;
Resultados de JTextField;
Contador de JTextField;
JPanel hInput;
char hChoice = ' ';
char cfavorecida = ' ';
Char [] cc = {'R', 'P', de '};
int r3;
lazo de int = 0;
int computerwins = 0;
int humanwins = 0;
JTextArea Chat;
RGen aleatorio = new Random();
público Main()
{
RPS = new JFrame ("roca, papel, tijeras, Pointless");
RPS.setSize (600, 600);
Roca = nuevo JButton("Rock");
Papel = nuevo JButton("Paper");
Tijeras = nuevo JButton("Scissors"); Chat = nuevo JTextArea(12,25); VersionButton = new JButton ("versión 0.0.7");
hInput = new JPanel(); PRDs = nuevo JTextField(20);
CRP = nuevo JTextField(20); Resultados = new JTextField(20); Contador = nuevo JTextField(30);
Rock.addActionListener (new ActionListener()
{
público void actionPerformed (ActionEvent e)
{
HRPS.setText ("usted: Rock");
hChoice = 'R';
Play();
}
});
Paper.addActionListener (new ActionListener()
{
público void actionPerformed (ActionEvent e)
{
HRPS.setText ("usted: papel");
hChoice = 'P';
Play();
}
});
Scissors.addActionListener (new ActionListener()
{
público void actionPerformed (ActionEvent e)
{
HRPS.setText ("usted: tijeras");
hChoice = de ';
Play();
}
});
hInput.setLayout (nuevo FlowLayout()); hInput.add(VersionButton);
hInput.add(HRPS);
hInput.add(CRPS); hInput.add(Counter);
hInput.add(Rock);
hInput.add(Paper);
hInput.add(Scissors); hInput.add(Chat);
RPS.setResizable(true); RPS.setExtendedState(JFrame.MAXIMIZED_BOTH); RPS.getContentPane () Add (hInput, BorderLayout.CENTER);
RPS.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
RPS.pack();
RPS.setVisible(true); RPS.setResizable(false); Chat.setText ("Bienvenido a" + "".replaceAll("\\s+","\n") + "Rock! ¡ Papel! Tijeras! ".replaceAll("\\s+","\n") +" ".replaceAll("\\s+","\n") +" ".replaceAll("\\s+","\n") +" charla: "+" ".replaceAll("\\s+","\n") +":: Player1 se unió al juego ");
}
play() void privado
{
R3 = rGen.nextInt(3); cfavorecida = cc [r3];
interruptor (cfavorecida)
{
caso 'R':
CRPS.setText ("Informática: Rock");
rotura;
caso 'P':
CRPS.setText ("Informática: papel");
rotura;
de caso ':
CRPS.setText ("Informática: Scisssors");
rotura;
}
if(hChoice == cChoice) {tie ++;} si (hChoice == 'R' & & cfavorecida == de ') {humanwins ++;} si (hChoice == 'P' & & cfavorecida == 'R') {humanwins ++;} si (hChoice == de ' & & cfavorecida == 'P') {humanwins ++;} si (cfavorecida == 'R' & & hChoice == de ') {computerwins ++;} si (cfavorecida == 'P' & & hChoice == 'R') {computerwins ++;} si (cfavorecida == de ' & & hChoice == 'P') {computerwins ++;} Counter.setText ("los lazos =" + lazo + "| Jugador gana = "+ humanwins +" | Computadora Wins = "+ computerwins);}
el principal vacío estático público (String [] args) {}
trate de {}
UIManager.setLookAndFeel (
UIManager.getCrossPlatformLookAndFeelClassName());
} catch (excepción e) {}
Aplicación principal = new Main();
}
}