Étape 1: configuration
Étape 1 :
Open Java Eclipse (https://eclipse.org/downloads/)
Étape 2 :
Copiez ce code :
package com.rps.ZemByte ;
import java.awt.* ; import java.awt.event.* ; import java.util.Random ;
Import javax.swing.* ;
public class Main
{
JFrame RPS ;
JButton roche, papier, ciseaux, VersionButton ;
JTextField HRPS ;
JTextField SDRC ;
JTextField résultats ;
JTextField Counter ;
JPanel hInput ;
char hChoice = ' ' ;
char cChoice = ' ' ;
Char [] cc = {'R', 'P', les de '} ;
int r3 ;
cravate d’int = 0 ;
int ordinateurGagne = 0 ;
int humanwins = 0 ;
JTextArea Chat ;
RGen aléatoire = new Random() ;
Main() public
{
RPS = new JFrame ("roche, papier, ciseaux, Pointless") ;
RPS.setSize (600, 600) ;
Roche = new JButton("Rock") ;
Papier = new JButton("Paper") ;
Ciseaux = new JButton("Scissors") ; Chat = new JTextArea(12,25) ; VersionButton = new JButton ("Version 0.0.7") ;
hInput = new JPanel() ; HRPS = new JTextField(20) ;
CRP = new JTextField(20) ; Résultats = new JTextField(20) ; Compteur = new JTextField(30) ;
Rock.addActionListener (new ActionListener()
{
public void actionPerformed (ActionEvent e)
{
HRPS.setText ("vous : Rock") ;
hChoice = « R » ;
Play() ;
}
});
Paper.addActionListener (new ActionListener()
{
public void actionPerformed (ActionEvent e)
{
HRPS.setText ("vous : papier") ;
hChoice = « P » ;
Play() ;
}
});
Scissors.addActionListener (new ActionListener()
{
public void actionPerformed (ActionEvent e)
{
HRPS.setText ("vous : ciseaux") ;
hChoice = les de ' ;
Play() ;
}
});
hInput.setLayout (new 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 (« Welcome to » + "".replaceAll("\\s+","\n") + "Rock ! Papier ! Ciseaux ! ".replaceAll("\\s+","\n") +" ".replaceAll("\\s+","\n") +" ".replaceAll("\\s+","\n") +" chat: "+" ".replaceAll("\\s+","\n") +":: Player1 rejoint le jeu ") ;
}
Private Sub play()
{
R3 = rGen.nextInt(3) ; cChoice = cc [r3] ;
Switch (cChoice)
{
case « R » :
CRPS.setText ("ordinateur : Rock") ;
rupture ;
case « P » :
CRPS.setText ("ordinateur : papier") ;
rupture ;
de l’affaire ":
CRPS.setText ("Computer : taillecrayons") ;
rupture ;
}
if(hChoice == cChoice) {cravate ++;} si (hChoice == 'R' & & cChoice == les de ') {humanwins ++;} si (hChoice == 'P' & & cChoice == 'R') {humanwins ++;} si (hChoice == de ' & & cChoice == 'P') {humanwins ++;} si (cChoice == 'R' & & hChoice == les de ') {ordinateurGagne ++;} si (cChoice == 'P' & & hChoice == 'R') {ordinateurGagne ++;} si (cChoice == les de ' & & hChoice == 'P') {ordinateurGagne ++;} Counter.setText ("liens =" + cravate + "| Joueur gagne = "+ humanwins +" | Victoires de l’ordinateur = "+ ordinateurGagne);}
Public Shared Sub main (String [] args) {}
try {}
() UIManager.setLookAndFeel
UIManager.getCrossPlatformLookAndFeelClassName()) ;
} catch (Exception e) {}
Application principale = nouveau Main() ;
}
}