私はあなたがルーズまたはドローに勝った回数が表示されるファイルを作成する方法に少し行き詰まっています。好き:
| Wins: | 234 |
| Looses:| 234 |
| Draws: | 434 |
つまり、プレスペーパーと私が答えに勝った場合、勝ちの量に1を加えます...など...
| Wins: | 235 |
| Looses:| 234 |
| Draws: | 434 |
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class gui extends JFrame implements ActionListener
{
public JLabel JWoL,JWoLPlayer,JWoLPC,JNumWin,JNumLose,JNumTie;
public static void main(String[] args)
{
gui theWindow = new gui();
theWindow.show();
}
public gui()
{
Button butRock = new Button("Rock");
butRock.addActionListener(this);
Button butPaper = new Button("Paper");
butPaper.addActionListener(this);
Button butScissors = new Button("Scissors");
butScissors.addActionListener(this);
JWoLPlayer = new JLabel();
JWoLPC = new JLabel();
JWoL= new JLabel();
JLabel rpsPlayer= new JLabel("Your Choice:");
JLabel rpsComputer= new JLabel("Computers Choice:");
setTitle("| RoPaS GAME |");
JPanel ButtPan=new JPanel();
ButtPan.setLayout(new GridLayout(1,3));
ButtPan.add(butRock);
ButtPan.add(butPaper);
ButtPan.add(butScissors);
JPanel LabelsPan=new JPanel();
LabelsPan.setLayout(new GridLayout(7,1));
LabelsPan.add(rpsPlayer);
LabelsPan.add(JWoLPlayer);
LabelsPan.add(rpsComputer);
LabelsPan.add(JWoLPC);
JPanel WLPan=new JPanel();
WLPan.setLayout(new BorderLayout());
WLPan.add(JWoL,"Center");
JPanel TwoPanesN1=new JPanel();
TwoPanesN1.setLayout(new BorderLayout());
TwoPanesN1.add(LabelsPan,"West");
TwoPanesN1.add(WLPan,"East");
getContentPane().setLayout(new GridLayout(2,1));
getContentPane().add(ButtPan);
getContentPane().add(TwoPanesN1);
Font fontDisplay = new Font("Arial", Font.PLAIN, 22);
JWoL.setFont(fontDisplay);
setSize(400,200);
setVisible(true);
setResizable(false);
addWindowListener(new WindowAdapter() {public void windowClosing(WindowEvent ev){System.exit(0);}});
}
public void Play(String PlayerChoice)
{
String PCchoice=PCansw();
JWoLPC.setText(PCchoice);
if(PlayerChoice.equals(PCchoice))
JWoL.setText(" Tie |");
else if(PlayerChoice.equals("Rock"))
if(PCchoice.equals("Paper"))
JWoL.setText(" You Lose |");
else
JWoL.setText(" You Win |");
else if(PlayerChoice.equals("Paper"))
if(PCchoice.equals("Scissors"))
JWoL.setText(" You Lose |");
else
JWoL.setText(" You Win |");
else if(PlayerChoice.equals("Scissors"))
if(PCchoice.equals("Rock"))
JWoL.setText(" You Lose |");
else
JWoL.setText(" You Win |");
}
public String PCansw()
{
String rpsPC2="";
int rpsPC=(int)(Math.random( )*3)+1;
if(rpsPC==1)
rpsPC2= "Rock";
else if(rpsPC==2)
rpsPC2= "Paper";
else if(rpsPC==3)
rpsPC2= "Scissors";
return rpsPC2;
}
public void actionPerformed(ActionEvent e)
{
if(e.getActionCommand().equals("Exit"))
System.exit(0);
else
{
JWoLPlayer.setText(e.getActionCommand());
Play(e.getActionCommand());
}
}
}