Write a program that lets the user play the game of Rock, Paper, Scissors against the computer. The program should work as follows: When the program begins, a random integer number in the range of 1 through 3 is generated. If the number is 1, then the computer has chosen rock.
I'm new to programming and I'm trying to write a very simple Rock, Paper, Scissors game in Java. It will compile and run fine, but I am looking to say something like 'Invalid move. Try again.' or something along those lines for when the user (personPlay) does not enter a correct character (r, p, or s). What would be the best way to do so? For example, if you enter a 'q', it should print 'Invalid move.' Thank you so much in advance!
}
Rock Paper Scissors Game Java
skaffmanclosed as too broad by davidism, skaffman, Radiodef, WilQu, GenericJonMar 30 '15 at 12:37
Please edit the question to limit it to a specific problem with enough detail to identify an adequate answer. Avoid asking multiple distinct questions at once. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.
5 Answers
I would recommend making Rock, Paper and Scissors objects. The objects would have the logic of both translating to/from Strings and also 'knowing' what beats what. The Java enum is perfect for this.
The parseType
method can return null
if the String is not a valid type. And you code can check if the value is null and if so, print 'invalid try again' and loop back to re-read the Scanner.
Furthermore, your type enum can determine what beats what by having each Type
object know:
Logmein hamachi download cnet. each type will implement this method differently to see what beats what:
Then in your code
dkatzeldkatzelBefore we try to solve the invalid character problem, the lack of curly braces around the if
and else if
statements is wreaking havoc on your program's logic. Change it to this:
Much clearer! It's now actually a piece of cake to catch the bad characters. You need to move the else
statement to somewhere that will catch the errors before you attempt to process anything else. So change everything to:
Why not check for what the user entered and then ask the user to enter correct input again?
eg:
for the other modifications, please check my total code at pastebin
Get drivers and downloads for your Dell Vostro 3500. Download and install the latest drivers, firmware and software. Dell vostro 3500 graphics card driver download. Display Warranty For Your Vostro 3500: view all: Viewing To Of. Dell Refurbished: 15.6-inch High Definition Flat LCD Screen for Select Dell Inspiron / Vostro / XPS Laptops. Dell Price: $104.99: Usually Ships: in 8-10 days: More Detail: Dell. Dell Refurbished: High Definition Flat LCD Screen - 15.6' for Select Dell Inspiron. Lifetime warranty, Free returns. Dell VOSTRO 3500 REPLACEMENT LAPTOP LCD SCREENS FROM $43.99. Make sure that new replacement screen has same SIZE, RESOLUTION, BACKLIGHT TYPE as your original screen! Screen Installation instructions for Dell VOSTRO 3500. Install Dell Vostro 3500 laptop drivers for Windows 10 x64, or download DriverPack Solution software for automatic drivers intallation and update.
SrihariSrihariRock Paper Scissors Javascript Game With Images
packageedu.witc.guts; |
importjava.awt.BorderLayout; |
importjava.awt.Color; |
importjava.awt.FlowLayout; |
importjava.awt.GridLayout; |
importjava.awt.event.ActionEvent; |
importjava.awt.event.ActionListener; |
importjavax.swing.BorderFactory; |
importjavax.swing.JButton; |
importjavax.swing.JComboBox; |
importjavax.swing.JFrame; |
importjavax.swing.JLabel; |
importjavax.swing.JOptionPane; |
importjavax.swing.JPanel; |
importjavax.swing.border.Border; |
publicclassBetPanelextendsJFrame{ |
//[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[ |
//VARIABLES[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[ |
//[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[ |
publicint userMoney =10; |
publicint compMoney =10; |
publicint winCount =0; |
publicint lossCount =0; |
publicint tieCount =0; |
privateint maxBet =0; |
protectedint userBet =0; |
protectedint compBet =0; |
protectedint betPool =0; |
privateString arrayOfBets[]; |
//[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[ |
//FORM ELEMENTS[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[ |
//[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[ |
privateJPanel BetContainerPanel =newJPanel(); //TOP PANEL of GAME |
privateJPanel LeftPanel =newJPanel(); //USER |
privateJPanel RightPanel =newJPanel(); //COMP |
privateJPanel BottomPanel =newJPanel(); //SCORE |
privateBorder paddingBorder =BorderFactory.createEmptyBorder(2,4,2,6); |
privateBorder recessedBorder =BorderFactory.createLoweredBevelBorder(); |
privateBorder blackLineBorder =BorderFactory.createMatteBorder(1, 1, 1, 1, Color.BLACK); |
privateJLabel lblLabelUserName =newJLabel('Player: '); |
privateJLabel lblUserName; |
privateJLabel lblUserName2; |
privateJLabel lblLabelUserMoney =newJLabel('Current Money: '); |
privateJLabel lblUserMoney =newJLabel(String.valueOf(userMoney)); |
privateJLabel lblLabelUserBet =newJLabel('Current Bet: '); |
JComboBox cmbBetAmount; |
protectedJButton btnLockBet =newJButton('Lock Bet'); |
privateJLabel lblCompName =newJLabel('Mr. Hyde'); |
privateJLabel lblLabelCompMoney =newJLabel('Current Money: '); |
privateJLabel lblCompMoney =newJLabel(String.valueOf(compMoney)); |
privateJLabel lblLabelCompBet =newJLabel('Current Bet: '); |
privateJLabel lblCompBet =newJLabel(String.valueOf(compBet)); |
privateJButton btnRules =newJButton('Game Rules'); |
privateJLabel lblLabelScore =newJLabel('SCORE'); |
privateJLabel lblUserScore =newJLabel(''); |
privateJLabel lblTieGame =newJLabel(''); |
privateJLabel lblCompScore =newJLabel(''); |
//[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[ |
//CONSTRUCTOR[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[ |
//[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[ |
publicBetPanel(){ |
getUserName(); |
createBetEventListeners(); |
createUserPanel(); |
createCompPanel(); |
createScorePanel(); |
createContainer(); |
promptRules(); |
add(BetContainerPanel, BorderLayout.NORTH); |
} |
//[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[ |
//EVENTS[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[ |
//[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[ |
publicvoidcreateBetEventListeners(){ |
btnRules.addActionListener(newActionListener(){ |
publicvoidactionPerformed(ActionEvente){ |
displayRules(); |
} |
}); |
} |
//[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[ |
//PANELS[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[ |
//[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[ |
publicvoidcreateContainer(){ |
BetContainerPanel.setLayout(newBorderLayout()); |
BetContainerPanel.add(LeftPanel, BorderLayout.WEST); |
BetContainerPanel.add(RightPanel, BorderLayout.EAST); |
BetContainerPanel.add(BottomPanel, BorderLayout.SOUTH); |
} |
publicvoidcreateUserPanel(){ |
assignMaxBet(); |
assignCompBet(); |
LeftPanel.setLayout(newFlowLayout()); |
LeftPanel.add(lblLabelUserName); |
lblUserName.setBorder(BorderFactory.createCompoundBorder(recessedBorder,paddingBorder)); |
LeftPanel.add(lblUserName); |
LeftPanel.add(lblLabelUserMoney); |
lblUserMoney.setBorder(BorderFactory.createCompoundBorder(recessedBorder,paddingBorder)); |
LeftPanel.add(lblUserMoney); |
LeftPanel.add(lblLabelUserBet); |
LeftPanel.add(cmbBetAmount); |
LeftPanel.add(btnLockBet); |
} |
publicvoidcreateCompPanel(){ |
RightPanel.setLayout(newFlowLayout()); |
lblCompName.setBorder(BorderFactory.createCompoundBorder(recessedBorder,paddingBorder)); |
RightPanel.add(lblCompName); |
RightPanel.add(lblLabelCompMoney); |
lblCompMoney.setBorder(BorderFactory.createCompoundBorder(recessedBorder,paddingBorder)); |
RightPanel.add(lblCompMoney); |
RightPanel.add(lblLabelCompBet); |
lblCompBet.setBorder(BorderFactory.createCompoundBorder(recessedBorder,paddingBorder)); |
RightPanel.add(lblCompBet); |
RightPanel.add(btnRules); |
} |
publicvoidcreateScorePanel(){ |
BottomPanel.setLayout(newGridLayout(2,3,5,5)); |
BottomPanel.setBorder(BorderFactory.createCompoundBorder(blackLineBorder, paddingBorder)); |
BottomPanel.add(lblUserName2); |
lblLabelScore.setHorizontalTextPosition(JLabel.CENTER); |
BottomPanel.add(lblLabelScore); |
BottomPanel.add(newJLabel('Mr. Hyde')); |
lblUserScore.setBorder(BorderFactory.createCompoundBorder(recessedBorder,paddingBorder)); |
BottomPanel.add(lblUserScore, BorderLayout.WEST); |
lblTieGame.setBorder(BorderFactory.createCompoundBorder(recessedBorder,paddingBorder)); |
BottomPanel.add(lblTieGame, BorderLayout.CENTER); |
lblCompScore.setBorder(BorderFactory.createCompoundBorder(recessedBorder,paddingBorder)); |
BottomPanel.add(lblCompScore, BorderLayout.EAST); |
} |
//[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[ |
//BETS[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[ |
//[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[ |
publicvoidassignMaxBet(){ |
if (userMoney >=5){maxBet=5;} |
elseif(userMoney 0){}//recap the game. game finished. |
else maxBet = userMoney; |
arrayOfBets =newString[maxBet]; //define the limit of the array |
for(int i =0;i<maxBet;i++){arrayOfBets[i] =String.valueOf(i+1);} //fill the array |
cmbBetAmount =newJComboBox(arrayOfBets); //fill the combo box |
} |
publicvoidassignCompBet(){ //assigns a value of 1-5 for computer bet |
int compDraw =0; |
if (compMoney >=5) compDraw =5; |
elseif(compMoney 0){}//recap the game. game finished. |
else compDraw = compMoney; |
compBet = (int) Math.round((Math.random()*compDraw) +1); |
} |
publicvoidgatherBets(){ |
userBet = (int) cmbBetAmount.getSelectedItem(); |
betPool = userBet + compBet; |
userMoney -= userBet; |
compMoney -= compBet; |
} |
//[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[ |
//RULES[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[ |
//[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[ |
publicvoidpromptRules(){ |
int option =0; |
option =JOptionPane.showConfirmDialog(null, 'Would you like to read the rules?'); |
if(option JOptionPane.YES_OPTION){ |
displayRules(); |
} |
} |
publicvoiddisplayRules(){ |
String rulesMsg ='Rock crushes scissors (rock wins)n'+ |
'Rock crushes lizard (rock wins)n'+ |
'Paper disproves Spock (paper wins)n'+ |
'Paper covers rock (paper wins)n'+ |
'Scissors cuts paper (scissors wins)n'+ |
'Scissors decapitate lizard (scissors wins)n'+ |
'Lizard poisons Spock (lizard wins)n'+ |
'Lizard eats paper (lizard wins)n'+ |
'Spock smashes scissors (Spock wins)n'+ |
'Spock vaporizes rock (Spock wins)n'+ |
'Tie if both choices are the samenn'+ |
'User must bet before choosing their selection!'; |
JOptionPane.showMessageDialog(null, rulesMsg); |
} |
publicvoidgetUserName(){ |
String str =JOptionPane.showInputDialog(null, 'Enter your name : ', 'User Name', JOptionPane.OK_OPTION); |
if(str !=null) { |
int confirmName =JOptionPane.showConfirmDialog(null, 'You entered the text : '+ str +', keep as user name?', 'Confirm', JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE); |
if (confirmName JOptionPane.YES_OPTION){ |
lblUserName =newJLabel(str); |
lblUserName2 =newJLabel(str); |
} |
else getUserName(); |
} |
} |
} |
packageedu.witc.guts; |
importjava.awt.BorderLayout; |
importjava.awt.GridLayout; |
importjava.awt.event.ActionEvent; |
importjava.awt.event.ActionListener; |
importjavax.swing.ImageIcon; |
importjavax.swing.JButton; |
importjavax.swing.JPanel; |
publicclassChoicePanelextendsBetPanel{ |
publicint userChoice =0; |
publicint compChoice =0; |
publicImageIcon choicesImg[] = { |
newImageIcon('images/weapons/0.gif'), |
newImageIcon('images/weapons/1.gif'), |
newImageIcon('images/weapons/2.gif'), |
newImageIcon('images/weapons/3.gif'), |
newImageIcon('images/weapons/4.gif'), |
newImageIcon('images/weapons/5.gif')}; |
privateJPanel ChoicePanel =newJPanel(); //top panel |
privateJButton btnRock =newJButton(choicesImg[1]); |
privateJButton btnPaper =newJButton(choicesImg[2]); |
privateJButton btnScissors =newJButton(choicesImg[3]); |
privateJButton btnLizard =newJButton(choicesImg[4]); |
privateJButton btnSpock =newJButton(choicesImg[5]); |
publicChoicePanel(){ |
disableButtons(); |
createChoiceEventListeners(); |
createChoicePanel(); |
add(ChoicePanel, BorderLayout.CENTER); |
} |
publicvoidcreateChoiceEventListeners(){ |
btnRock.addActionListener(newActionListener() { //On press disable the option to change bet, and assign the user bet |
@Override |
publicvoidactionPerformed(ActionEventarg0) { |
userChoice =1; |
disableButtons(userChoice); |
} |
}); |
btnPaper.addActionListener(newActionListener() { //On press disable the option to change bet, and assign the user bet |
@Override |
publicvoidactionPerformed(ActionEventarg0) { |
userChoice =2; |
disableButtons(userChoice); |
} |
}); |
btnScissors.addActionListener(newActionListener() { //On press disable the option to change bet, and assign the user bet |
@Override |
publicvoidactionPerformed(ActionEventarg0) { |
userChoice =3; |
disableButtons(userChoice); |
} |
}); |
btnLizard.addActionListener(newActionListener() { //On press disable the option to change bet, and assign the user bet |
@Override |
publicvoidactionPerformed(ActionEventarg0) { |
userChoice =4; |
disableButtons(userChoice); |
} |
}); |
btnSpock.addActionListener(newActionListener() { //On press disable the option to change bet, and assign the user bet |
@Override |
publicvoidactionPerformed(ActionEventarg0) { |
userChoice =5; |
disableButtons(userChoice); |
} |
}); |
btnLockBet.addActionListener(newActionListener() { //On press disable the option to change bet, and assign the user bet |
@Override |
publicvoidactionPerformed(ActionEventarg0) { |
cmbBetAmount.setEnabled(false); |
btnLockBet.setEnabled(false); |
enableButtons(); |
} |
}); |
} |
publicvoidcreateChoicePanel(){ |
ChoicePanel.setLayout(newGridLayout(1,5)); |
ChoicePanel.add(btnRock); |
ChoicePanel.add(btnPaper); |
ChoicePanel.add(btnScissors); |
ChoicePanel.add(btnLizard); |
ChoicePanel.add(btnSpock); |
} |
publicvoiddisableButtons(){ |
btnRock.setEnabled(false); |
btnPaper.setEnabled(false); |
btnScissors.setEnabled(false); |
btnLizard.setEnabled(false); |
btnSpock.setEnabled(false); |
} |
publicvoiddisableButtons(intnotThis){ |
btnRock.setEnabled(false); |
btnPaper.setEnabled(false); |
btnScissors.setEnabled(false); |
btnLizard.setEnabled(false); |
btnSpock.setEnabled(false); |
switch(notThis){ |
case1: |
btnRock.setEnabled(true); |
break; |
case2: |
btnPaper.setEnabled(true); |
break; |
case3: |
btnScissors.setEnabled(true); |
break; |
case4: |
btnLizard.setEnabled(true); |
break; |
case5: |
btnSpock.setEnabled(true); |
break; |
} |
} |
publicvoidenableButtons(){ |
btnRock.setEnabled(true); |
btnPaper.setEnabled(true); |
btnScissors.setEnabled(true); |
btnLizard.setEnabled(true); |
btnSpock.setEnabled(true); |
} |
} |
packageedu.witc.guts; |
importjavax.swing.ImageIcon; |
importjavax.swing.JFrame; |
importjavax.swing.JPanel; |
publicclassDecisionPanelextendsChoicePanel{ |
privateint winnerChoice =0; //is applied in chooseWinner |
privateString winningActionString =''; //is applied in chooseWinner |
privateint loserChoice =0; //is applied in chooseWinner |
privateString winner =''; |
privateString loser =''; |
privateImageIcon winnerImg =null; |
privateImageIcon loserImg =null; |
privateString choicesString[] = {'','Rock','Paper','Scissors','Lizard','Spock'}; |
privateString actionString[] = {'_______','cuts','covers','poisons','smashes','decapitates','eats','disproves','vaporizes','crushes','ties'}; |
privateJPanel winnerPanel =newJPanel(); |
privateJPanel actionPanel =newJPanel(); |
privateJPanel loserPanel =newJPanel(); |
privateJPanel DecisionContainer =newJPanel(); |
publicDecisionPanel(){ |
compareChoices(); |
createDecisionContainer(); |
createWinnerPanel(); |
createActionPanel(); |
createLoserPanel(); |
this.pack(); |
this.setTitle('Rock,Paper,Scissors,Lizard,Spock'); |
this.setSize(1024,620); |
this.setLocationRelativeTo(null); |
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); |
} |
publicvoidcompareChoices(){ |
switch(userChoice){ |
case1: |
if(compChoice 1){ //Rock vs Rock |
winner ='Player'; |
winnerChoice =1; |
winningActionString = actionString[10]; //Tie |
loser ='Computer'; |
loserChoice =1; |
tieCount +=1; |
userMoney += userBet; |
compMoney += compBet; |
betPool =0; |
break; |
} |
if(compChoice 2){ //Rock vs Paper |
winner ='Computer'; |
winnerChoice =2; |
winningActionString = actionString[2]; //Covers |
compMoney += betPool; |
loser ='Player'; |
loserChoice =1; |
betPool =0; |
lossCount +=1; |
break; |
} |
if(compChoice 3){ //Rock vs Scissors |
winner ='Player'; |
winnerChoice =1; |
winningActionString = actionString[9]; //crushes |
userMoney += betPool; |
loser ='Computer'; |
loserChoice =3; |
betPool =0; |
winCount +=1; |
break; |
} |
if(compChoice 4){ //Rock vs Lizard |
winner ='Player'; |
winnerChoice =1; |
winningActionString = actionString[9]; //crushes |
userMoney += betPool; |
loser ='Computer'; |
loserChoice =4; |
betPool =0; |
winCount +=1; |
break; |
} |
if(compChoice 5){ //Rock vs Spock |
winner ='Computer'; |
winnerChoice =5; |
winningActionString = actionString[8]; //vaporizes |
compMoney += betPool; |
loser ='Player'; |
loserChoice =1; |
betPool =0; |
lossCount +=1; |
break; |
} |
case2: |
if(compChoice 1){ //Paper vs Rock |
winner ='Player'; |
winnerChoice =2; |
winningActionString = actionString[2]; //covers |
userMoney += betPool; |
loser ='Computer'; |
loserChoice =1; |
betPool =0; |
winCount +=1; |
break; |
} |
if(compChoice 2){ //Paper vs Paper |
winner ='Player'; |
winnerChoice =2; |
winningActionString = actionString[10]; //ties |
loser ='Computer'; |
loserChoice =2; |
tieCount +=1; |
userMoney += userBet; |
compMoney += compBet; |
betPool =0; |
break; |
} |
if(compChoice 3){ //Paper vs Scissors |
winner ='Computer'; |
winnerChoice =3; |
winningActionString = actionString[1]; //cuts |
compMoney += betPool; |
loser ='Player'; |
loserChoice =2; |
betPool =0; |
lossCount +=1; |
break; |
} |
if(compChoice 4){ //Paper vs Lizard |
winner ='Computer'; |
winnerChoice =4; |
winningActionString = actionString[6]; //eats |
compMoney += betPool; |
loser ='Player'; |
loserChoice =2; |
betPool =0; |
lossCount +=1; |
break; |
} |
if(compChoice 5){ //Paper vs Spock |
winner ='Player'; |
winnerChoice =2; |
winningActionString = actionString[8]; //disproves |
userMoney += betPool; |
loser ='Computer'; |
loserChoice =5; |
betPool =0; |
lossCount +=1; |
break; |
} |
case3: |
if(compChoice 1){ // Scissors vs Rock |
winner ='Computer'; |
winnerChoice =1; |
winningActionString = actionString[9]; // crushes |
compMoney += betPool; |
loser ='Player'; |
loserChoice =3; |
betPool =0; |
lossCount +=1; |
break; |
} |
if(compChoice 2){ // Scissors vs Paper |
winner ='Player'; |
winnerChoice =3; |
winningActionString = actionString[1]; // cuts |
userMoney += betPool; |
loser ='Computer'; |
loserChoice =2; |
betPool =0; |
winCount +=1; |
break; |
} |
if(compChoice 3){ // Scissors vs Scissors |
winner ='Player'; |
winnerChoice =3; |
winningActionString = actionString[10]; //Ties |
userMoney += userBet; |
loser ='Computer'; |
loserChoice =3; |
compMoney += compBet; |
betPool =0; |
tieCount +=1; |
break; |
} |
if(compChoice 4){ // Scissors vs Lizard |
winner ='Player'; |
winnerChoice =3; |
winningActionString = actionString[5]; // decapitates |
userMoney += betPool; |
loser ='Computer'; |
loserChoice =4; |
betPool =0; |
winCount +=1; |
break; |
} |
if(compChoice 5){ // Scissors vs Spock |
winner ='Computer'; |
winnerChoice =5; |
winningActionString = actionString[4]; // smashes |
compMoney += betPool; |
loser ='Player'; |
loserChoice =3; |
betPool =0; |
lossCount +=1; |
break; |
} |
case4: |
if(compChoice 1){ // Lizard vs Rock |
winner ='Computer'; |
winnerChoice =1; |
winningActionString = actionString[9]; // crushes |
compMoney += betPool; |
loser ='Player'; |
loserChoice =4; |
betPool =0; |
lossCount +=1; |
break; |
} |
if(compChoice 2){ // Lizard vs Paper |
winner ='Player'; |
winnerChoice =4; |
winningActionString = actionString[6]; // eats |
userMoney += betPool; |
loser ='Computer'; |
loserChoice =2; |
betPool =0; |
lossCount +=1; |
break; |
} |
if(compChoice 3){ // Lizard vs Scissors |
winner ='Computer'; |
winnerChoice =3; |
winningActionString = actionString[5]; // |
compMoney += betPool; |
loser ='Player'; |
loserChoice =4; |
betPool =0; |
lossCount +=1; |
break; |
} |
if(compChoice 4){ // Lizard vs Lizard |
winner ='Palyer'; |
winnerChoice =4; |
winningActionString = actionString[10]; // ties |
userMoney += userBet; |
loser ='Computer'; |
loserChoice =4; |
compMoney += compBet; |
betPool =0; |
tieCount +=1; |
break; |
} |
if(compChoice 5){ // Lizard vs Spock |
winner ='Player'; |
winnerChoice =4; |
winningActionString = actionString[3]; // poisons |
userMoney += betPool; |
loser ='Computer'; |
loserChoice =5; |
betPool =0; |
winCount +=1; |
break; |
} |
case5: |
if(compChoice 1){ // Spock vs Rock |
winner ='Player'; |
winnerChoice =5; |
winningActionString = actionString[8]; // vaporizes |
userMoney += betPool; |
loser ='Computer'; |
loserChoice =1; |
betPool =0; |
winCount +=1; |
break; |
} |
if(compChoice 2){ // Spock vs Paper |
winner ='Computer'; |
winnerChoice =2; |
winningActionString = actionString[7]; // disproves |
compMoney += betPool; |
loser ='Player'; |
loserChoice =5; |
betPool =0; |
lossCount +=1; |
break; |
} |
if(compChoice 3){ // Spock vs Scissors |
winner ='Player'; |
winnerChoice =5; |
winningActionString = actionString[4]; // smases |
userMoney += betPool; |
loser ='Computer'; |
loserChoice =3; |
betPool =0; |
winCount +=1; |
break; |
} |
if(compChoice 4){ // Spock vs Lizard |
winner ='Computer'; |
winnerChoice =4; |
winningActionString = actionString[3]; // poisons |
compMoney += betPool; |
loser ='Player'; |
loserChoice =5; |
betPool =0; |
lossCount +=1; |
break; |
} |
if(compChoice 5){ // Spock vs Spock |
winner ='Player'; |
winnerChoice =5; |
winningActionString = actionString[10]; // ties |
userMoney += userBet; |
loser ='Computer'; |
loserChoice =5; |
compMoney += compMoney; |
betPool =0; |
tieCount +=1; |
break; |
} |
} |
winnerImg = choicesImg[winnerChoice]; |
loserImg = choicesImg[loserChoice]; |
} |
publicvoidcreateWinnerPanel(){ |
} |
publicvoidcreateActionPanel(){ |
} |
publicvoidcreateLoserPanel(){ |
} |
publicvoidcreateDecisionContainer(){ |
} |
} |
packageedu.witc.main; |
importjavax.swing.JFrame; |
importedu.witc.guts.DecisionPanel; |
publicclassLaunchGameextendsDecisionPanel{ |
publicstaticvoidmain(String[] args) { |
DecisionPanel newGame =newDecisionPanel(); |
newGame.setVisible(true); |
} |
} |
Make Rock Paper Scissors Game Javascript
packageedu.witc.guts; |
importedu.witc.guts.DecisionPanel; |
publicclassTheGame { |
} |