Monday, October 14, 2013

Hangman game

HangmanGame.java
  1 package hangmangame;
  2 
  3 import java.util.Random;
  4 import java.util.Scanner;
  5 
  6 public class HangmanGame {
  7 
  8     public static void main(String[] args) {
  9         
 10         Random rand = new Random();
 11         Scanner scan = new Scanner(System.in);
 12     
 13         String word, guess, convertDashArray;
 14         char check;
 15         int random = 0, counter = 0;
 16         boolean hanged = false;
 17         boolean matched = false;
 18 
 19         String[] alphabetArray = {" A ", " B ", " C ", " D ", " E ", " F ", " G ", " H ", " I ", " J ", " K ", " L ", " M ",
 20                                   " N ", " 0 ", " P ", " Q ", " R ", " S ", " T ", " U ", " V ", " W ", " X ", " Y ", " Z "};
 21         
 22         String[] wordsArray = {"elephant", "star", " candy", "wings", "shopping", "steak", "couch", "toy", "cat", "mouse",
 23                                "elevator", "taxi", "airplane", "bus", "car", "flower", "cheese", "apple", "orange", "coat",
 24                                "running", "sweater", "blanket", "chocolate", "chicken", "computer", "rice", "dance", "doll",
 25                                "duck", "alligator", "snake", "calculator", "castle", "balloon", "laptop", "turtle", "pencil",
 26                                "fridge", "police", "antartica", "dinner", "fire", "cookie", "pizza", "church", "village",
 27                                "pistachio", "reptile", "rose", "apartment", "random", "words", "dancing", "soccer", "hockey",
 28                                "panther", "christmas", "bookworm", "buffalo", "glowworm", "ivory", "microwave", "oryx", "antelope",
 29                                "arabian", "knight", "rickshaw", "january", "february", "march", "april", "may", "june", "july",
 30                                "august", "september", "october", "november", "december", "dragon", "panda", "kungfu", "karate",
 31                                "shark", "dolphin", "seagulls", "salmon", "crab", "whale", "leopard", "lion", "cheetah", "hippopotamus",
 32                                "calendar", "racoon", "google", "yahoo", "amazon", "lamborghini", "ferrari", "lotus", "toyota", "honda",
 33                                "eskimo", "igloo", "eagle", "helicopter", "globe", "jamaica", "korea", "indonesia", "japan", "nigeria",
 34                                "india", "pakistan", "america", "brazil", "canada", "mexico", "switzerland", "ghana", "bangladesh", "pen",
 35                                "iceland", "greenland", "cranberry", "honey", "money", "california", "texas", "virginia", "Illinois",
 36                                "chicago", "massachusetts", "pennsylvania", "alaska", "florida", "louisiana", "arizona", "kentucky",
 37                                "maryland", "colorado", "georgia", "tennessee", "iowa", "nebraska", "missouri", "burger", "brownie",
 38                                "machine", "mechanic", "teacher", "student", "student", "office", "glass", "friend", "chair", "bed", "pug",
 39                                "beagle", "bulldog", "chihuahua", "boxer", "pomeranian", "poodle", "dachshund", "bible", "easter", "button",
 40                                "gymnast", "clown", "ventriloquist", "piano", "violin", "guitar", "blueberry", "envelope", "tiger",
 41                                "passport", "navigate", "swimming", "dinosaur", "marshmallow", "pink", "fish", "vegetable", "potato",
 42                                "plant", "bench", "window", "curtain", "plate", "yogurt", "spinach", "grass", "tomato", "smart", "parrot",
 43                                "sparrow", "cloud", "jeep", "bicycle", "account", "salad", "onion", "book", "manager", "vacation", "turkey",
 44                                "afghanistan", "iran", "iraq", "libya", "morocco", "spain", "germany", "scotland", "argentina", "australia",
 45                                "bahamas", "austria", "bahrain", "cambodia", "nigeria", "kuwait", "croatia", "denmark", "fiji", "france",
 46                                "greece", "indonesia", "ireland", "italy", "israel", "jordan", "kazakhstan", "kenya", "madagascar", "micronesia",
 47                                "mauritius", "nepal", "oman", "philippines", "seychelles", "zinbabwe", "vietnam", "venezuela", "qatar", "oman",
 48                                "excavator", "truck", "hedgehog", "deer", "bear", "rabbit", "tractor", "bulldozer", "treadmill", "wine"};
 49 
 50         char[] dashArray;
 51 
 52         random = rand.nextInt(wordsArray.length);
 53         word = wordsArray[random];
 54         
 55         dashArray = new char[word.length()];   
 56         
 57         System.out.println("------------------: HANGMAN GAME INSTRUCTIONS :------------------");
 58         System.out.println("1. You can enter either a letter or try to guess the word any time.");
 59         System.out.println("2. You have six chances before the hangman is hanged (you fail).");
 60         System.out.println("3. If you try to guess the word, but the guess is wrong, program will read the first letter only.");
 61         System.out.println("4. If you guess the word correctly, you win.");
 62         
 63         System.out.println();
 64 
 65         System.out.print("Letters available: ");
 66         
 67         for(int c=0; c<alphabetArray.length; c++)
 68         {
 69             System.out.print(alphabetArray[c]);
 70         }
 71         
 72         System.out.println();
 73 
 74         for(int a=0; a<dashArray.length; a++)
 75         {
 76             dashArray[a] = '-';
 77             System.out.print(dashArray[a]);           
 78         }
 79         
 80         System.out.print("\t" + word.length() + " letters!");
 81         
 82         while(hanged == false)
 83         {        
 84             System.out.println();
 85             
 86             System.out.print("Enter a guess (letter or word): ");
 87             guess = scan.nextLine();
 88             check = guess.charAt(0);
 89 
 90             for(int b=0; b<dashArray.length; b++)
 91             {                
 92                 if(check == word.charAt(b))                    
 93                 {                    
 94                     alphabetArray[(int) Character.toUpperCase(check) - 65] = " ";
 95                     
 96                     dashArray[b] = guess.charAt(0);
 97                     
 98                     matched = true;
 99                 }
100                 
101                 else
102                 {
103                     alphabetArray[(int) Character.toUpperCase(check) - 65] = " ";
104                 }
105 
106                     System.out.print(dashArray[b]);   
107             }  
108             
109             if(matched == false)
110             {
111                 counter++;
112             }
113             
114             matched = false;
115             
116             convertDashArray = new String(dashArray);
117             
118             if(word.equals(guess) || convertDashArray.equals(word))  
119                 {
120                     System.out.println("\tGood guess, you win!");
121                    
122                     hanged = true;
123                     
124                     break;
125                 }
126 
127             System.out.println();   
128             
129             if(counter == 0)
130             {
131                 System.out.println("\t\t\t\t\t _____");
132                 System.out.println("\t\t\t\t\t |   |");
133                 System.out.println("\t\t\t\t\t     |");
134                 System.out.println("\t\t\t\t\t     |");
135                 System.out.println("\t\t\t\t\t     |");
136                 System.out.println("\t\t\t\t\t_____|");
137             }
138             
139             else if(counter == 1)  
140             {
141                 System.out.println("\t\t\t\t\t _____");
142                 System.out.println("\t\t\t\t\t |   |");
143                 System.out.println("\t\t\t\t\t 0   |");
144                 System.out.println("\t\t\t\t\t     |");
145                 System.out.println("\t\t\t\t\t     |");
146                 System.out.println("\t\t\t\t\t_____|");
147                 hanged = false;
148             }
149             
150             else if(counter == 2)
151             {
152                 System.out.println("\t\t\t\t\t _____");
153                 System.out.println("\t\t\t\t\t |   |");
154                 System.out.println("\t\t\t\t\t 0   |");
155                 System.out.println("\t\t\t\t\t |   |");
156                 System.out.println("\t\t\t\t\t     |");
157                 System.out.println("\t\t\t\t\t_____|");
158                 hanged = false;                
159             }
160             
161             else if(counter == 3)
162             {
163                 System.out.println("\t\t\t\t\t _____");
164                 System.out.println("\t\t\t\t\t |   |");
165                 System.out.println("\t\t\t\t\t 0   |");
166                 System.out.println("\t\t\t\t\t/|   |");
167                 System.out.println("\t\t\t\t\t     |");
168                 System.out.println("\t\t\t\t\t_____|");
169                 hanged = false;                
170             }
171             
172             else if(counter == 4)
173             {                
174                 System.out.println("\t\t\t\t\t _____");
175                 System.out.println("\t\t\t\t\t |   |");
176                 System.out.println("\t\t\t\t\t 0   |");
177                 System.out.println("\t\t\t\t\t/|\\  |");
178                 System.out.println("\t\t\t\t\t     |");
179                 System.out.println("\t\t\t\t\t_____|");
180                 hanged = false; 
181                 
182             }
183             
184             else if(counter == 5)
185             {
186                 System.out.println("\t\t\t\t\t _____");
187                 System.out.println("\t\t\t\t\t |   |");
188                 System.out.println("\t\t\t\t\t 0   |");
189                 System.out.println("\t\t\t\t\t/|\\  |");
190                 System.out.println("\t\t\t\t\t/    |");
191                 System.out.println("\t\t\t\t\t_____|");
192                 hanged = false;                 
193             }
194             
195             else if(counter == 6)
196             {
197                 System.out.println("\t\t\t\t\t _____");
198                 System.out.println("\t\t\t\t\t |   |");
199                 System.out.println("\t\t\t\t\t 0   |");
200                 System.out.println("\t\t\t\t\t/|\\  |");
201                 System.out.println("\t\t\t\t\t/ \\  |");
202                 System.out.println("\t\t\t\t\t_____|");
203                 System.out.println("\tSorry you lost, the word was: " + word);
204                 hanged = true;                    
205             }
206             
207             System.out.println();
208             
209             System.out.print("Letters available: ");
210             
211             for(int d=0; d<alphabetArray.length; d++)
212             {                         
213                 switch (guess) 
214                 {
215                     case "a":
216                         alphabetArray[0] = " ";
217                         break;
218                     case "b":
219                         alphabetArray[1] = " ";
220                         break;
221                     case "c":
222                         alphabetArray[2] = " ";
223                         break;
224                     case "d":
225                         alphabetArray[3] = " ";
226                         break;
227                     case "e":
228                         alphabetArray[4] = " ";
229                         break;
230                     case "f":
231                         alphabetArray[5] = " ";
232                         break;
233                     case "g":
234                         alphabetArray[6] = " ";
235                         break;
236                     case "h":
237                         alphabetArray[7] = " ";
238                         break;
239                     case "i":
240                         alphabetArray[8] = " ";
241                         break;
242                     case "j":
243                         alphabetArray[9] = " ";
244                         break;
245                     case "k":
246                         alphabetArray[10] = " ";
247                         break;
248                     case "l":
249                         alphabetArray[11] = " ";
250                         break;
251                     case "m":
252                         alphabetArray[12] = " ";
253                         break;
254                     case "n":
255                         alphabetArray[13] = " ";
256                         break;
257                     case "o":
258                         alphabetArray[14] = " ";
259                         break;
260                     case "p":
261                         alphabetArray[15] = " ";
262                         break;
263                     case "q":
264                         alphabetArray[16] = " ";
265                         break;
266                     case "r":
267                         alphabetArray[17] = " ";
268                         break;
269                     case "s":
270                         alphabetArray[18] = " ";
271                         break;
272                     case "t":
273                         alphabetArray[19] = " ";
274                         break;
275                     case "u":
276                         alphabetArray[20] = " ";
277                         break;
278                     case "v":
279                         alphabetArray[21] = " ";
280                         break;
281                     case "w":
282                         alphabetArray[22] = " ";
283                         break;
284                     case "x":
285                         alphabetArray[23] = " ";
286                         break;
287                     case "y":
288                         alphabetArray[24] = " ";
289                         break;
290                     case "z":
291                         alphabetArray[25] = " ";
292                         break;
293                 }
294                                 
295                System.out.print(alphabetArray[d]);
296             }
297         }  
298     }
299 }

See the video here:

Friday, October 4, 2013

Rock, paper, scissors, lizard or spock Graphics game

Main Java class

Images used

RPSLSgui.java
 1 package rpslsgui;
 2 
 3 import javax.swing.JFrame;
 4 
 5 
 6 public class RPSLSgui {
 7 
 8     public static void main(String[] args) {
 9         
10         JFrame frame = new JFrame("Rock, Paper, Scissors, Lizard or Spock ( tonynsx@gmail.com )");
11         frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
12         frame.getContentPane().add(new RPSLSpanel());
13         frame.setResizable(false);
14         frame.pack();
15         frame.setVisible(true);
16     }
17 }
18 

RPSLS panel gui class

RPSLSpanel.java
  1 package rpslsgui;
  2 
  3 import java.awt.Color;
  4 import java.awt.Dimension;
  5 import java.awt.Font;
  6 import java.awt.event.MouseEvent;
  7 import java.awt.event.MouseListener;
  8 import javax.swing.ImageIcon;
  9 import javax.swing.JLabel;
 10 import javax.swing.JPanel;
 11 import java.util.Random;
 12 
 13 public class RPSLSpanel extends JPanel{
 14     
 15     Random rand = new Random();
 16     
 17     int comp, winScore, loseScore, tieScore;
 18     
 19     ImageIcon[] imageArray = {new ImageIcon("rock.jpg"), new ImageIcon("paper.jpg"), new ImageIcon("scissors.jpg"),
 20                               new ImageIcon("lizard.jpg"), new ImageIcon("spock.jpg")};
 21     JLabel title, instruction, option1, option2, option3, option4, option5, player, computer, playerTitle, computerTitle, wins, loses, ties, wL, lL, tL;
 22     JPanel imagePanel, playerPanel, computerPanel, scorePanel;
 23     
 24     public RPSLSpanel()
 25         {
 26             imagePanel = new JPanel();
 27             playerPanel = new JPanel();
 28             computerPanel = new JPanel();
 29             scorePanel = new JPanel();
 30             
 31             title = new JLabel("Please click on the image to make a choice, then computer will make a random choice.");
 32             instruction = new JLabel(new ImageIcon("howto.jpg"));
 33             
 34             option1 = new JLabel(new ImageIcon("rock.jpg"));
 35             option1.addMouseListener(new mouseListener());
 36             option2 = new JLabel(new ImageIcon("paper.jpg"));
 37             option2.addMouseListener(new mouseListener());
 38             option3 = new JLabel(new ImageIcon("scissors.jpg"));
 39             option3.addMouseListener(new mouseListener());
 40             option4 = new JLabel(new ImageIcon("lizard.jpg"));
 41             option4.addMouseListener(new mouseListener());
 42             option5 = new JLabel(new ImageIcon("spock.jpg"));
 43             option5.addMouseListener(new mouseListener());
 44             
 45             player = new JLabel(new ImageIcon("blank.jpg"));
 46             computer = new JLabel(new ImageIcon("blank.jpg"));
 47             
 48             playerTitle = new JLabel("PLAYER");
 49             computerTitle = new JLabel("COMPUTER");
 50             
 51             wins = new JLabel("Wins:");
 52             wins.setForeground(Color.red);
 53             wins.setFont(new Font("Helvetica", Font.BOLD, 36));
 54             loses = new JLabel("Loses:");
 55             loses.setForeground(Color.red);
 56             loses.setFont(new Font("Helvetica", Font.BOLD, 36));
 57             ties = new JLabel("Ties:");
 58             ties.setForeground(Color.red);
 59             ties.setFont(new Font("Helvetica", Font.BOLD, 36));
 60             wL = new JLabel(""+winScore);
 61             wL.setFont(new Font("Helvetica", Font.BOLD, 36));
 62             lL = new JLabel(""+loseScore);
 63             lL.setFont(new Font("Helvetica", Font.BOLD, 36));
 64             tL = new JLabel(""+tieScore);
 65             tL.setFont(new Font("Helvetica", Font.BOLD, 36));
 66             
 67             add(instruction);
 68             add(title);
 69             
 70             imagePanel.add(option1);
 71             imagePanel.add(option2);
 72             imagePanel.add(option3);
 73             imagePanel.add(option4);
 74             imagePanel.add(option5);
 75             add(imagePanel);
 76             imagePanel.setBackground(Color.WHITE);
 77             
 78             playerPanel.add(playerTitle);
 79             playerPanel.add(player);
 80             computerPanel.add(computerTitle);
 81             computerPanel.add(computer);            
 82             add(playerPanel);
 83             add(computerPanel);
 84             playerPanel.setBackground(Color.WHITE);
 85             computerPanel.setBackground(Color.WHITE);
 86             
 87             scorePanel.add(wins);
 88             scorePanel.add(wL);
 89             scorePanel.add(loses);
 90             scorePanel.add(lL);
 91             scorePanel.add(ties);
 92             scorePanel.add(tL);
 93             add(scorePanel);
 94             scorePanel.setBackground(Color.WHITE);
 95             
 96             winScore = loseScore = tieScore = 0;
 97             
 98             setPreferredSize(new Dimension(550, 575));
 99             setBackground(Color.WHITE);
100         }    
101     public class mouseListener implements MouseListener
102     {
103 
104         @Override
105         public void mouseClicked(MouseEvent e) 
106         {
107             if(e.getSource() == option1)
108             {
109                 player.setIcon(imageArray[0]);
110                 comp = rand.nextInt(imageArray.length)+0;
111                 computer.setIcon(imageArray[comp]);
112             }
113             if(e.getSource() == option2)
114             {
115                 player.setIcon(imageArray[1]);
116                 comp = rand.nextInt(imageArray.length)+0;
117                 computer.setIcon(imageArray[comp]);
118             }
119             if(e.getSource() == option3)
120             {
121                 player.setIcon(imageArray[2]);
122                 comp = rand.nextInt(imageArray.length)+0;
123                 computer.setIcon(imageArray[comp]);
124             }
125             if(e.getSource() == option4)
126             {
127                 player.setIcon(imageArray[3]);
128                 comp = rand.nextInt(imageArray.length)+0;
129                 computer.setIcon(imageArray[comp]);
130             }
131             if(e.getSource() == option5)
132             {
133                 player.setIcon(imageArray[4]);
134                 comp = rand.nextInt(imageArray.length)+0;
135                 computer.setIcon(imageArray[comp]);
136             }
137             
138             // calculating wins
139             if(player.getIcon() == imageArray[4] && computer.getIcon() == imageArray[2] ||
140                player.getIcon() == imageArray[2] && computer.getIcon() == imageArray[1] ||
141                player.getIcon() == imageArray[1] && computer.getIcon() == imageArray[0] ||
142                player.getIcon() == imageArray[0] && computer.getIcon() == imageArray[3] ||
143                player.getIcon() == imageArray[3] && computer.getIcon() == imageArray[4] ||
144                player.getIcon() == imageArray[1] && computer.getIcon() == imageArray[3] ||
145                player.getIcon() == imageArray[1] && computer.getIcon() == imageArray[4] ||
146                player.getIcon() == imageArray[0] && computer.getIcon() == imageArray[2] ||
147                player.getIcon() == imageArray[4] && computer.getIcon() == imageArray[0] ||
148                player.getIcon() == imageArray[3] && computer.getIcon() == imageArray[1])
149             {
150                 winScore++;
151                 wL.setText(""+winScore);
152             }
153             
154             // calculating loses
155             if(player.getIcon() == imageArray[0] && computer.getIcon() == imageArray[1] ||
156                player.getIcon() == imageArray[0] && computer.getIcon() == imageArray[4] ||
157                player.getIcon() == imageArray[1] && computer.getIcon() == imageArray[2] ||
158                player.getIcon() == imageArray[2] && computer.getIcon() == imageArray[0] ||
159                player.getIcon() == imageArray[2] && computer.getIcon() == imageArray[3] ||
160                player.getIcon() == imageArray[2] && computer.getIcon() == imageArray[4] ||
161                player.getIcon() == imageArray[3] && computer.getIcon() == imageArray[0] ||
162                player.getIcon() == imageArray[3] && computer.getIcon() == imageArray[2] ||
163                player.getIcon() == imageArray[4] && computer.getIcon() == imageArray[1] ||
164                player.getIcon() == imageArray[4] && computer.getIcon() == imageArray[3])
165             {
166                 loseScore++;
167                 lL.setText(""+loseScore);
168             }
169             
170             // if they're both same
171             if(player.getIcon() == computer.getIcon())
172             {
173                 tieScore++;
174                 tL.setText(""+tieScore);
175             } 
176         }
177 
178         @Override
179         public void mousePressed(MouseEvent e) {}
180 
181         @Override
182         public void mouseReleased(MouseEvent e) {}
183 
184         @Override
185         public void mouseEntered(MouseEvent e) {}
186 
187         @Override
188         public void mouseExited(MouseEvent e) {}   
189     }
190 }
191 
192 
193 

Rock, paper, scissors, lizard or spock , text based game

The rules of Rock-paper-scissors-lizard-Spock are:
* Spock smashes scissors, scissors cut paper
* Paper covers rock, rock crushes lizard
* Lizard poisons Spock, Lizard eats paper
* Rock crushes scissors, scissors decapitates lizard
* Spock vaporizes rock, Paper disproves Spock


RPSLS.java
  1 /*
  2  * Tony Antony
  3  * CSIT 210 - Project 2 (RPSLS.Java)
  4  */
  5 
  6 package rpsls;
  7 
  8 import java.util.Scanner;
  9 import java.util.Random;
 10 
 11 public class RPSLS {
 12 
 13     public static void main(String[] args) {
 14         
 15         Scanner scan = new Scanner(System.in);
 16         Random rand = new Random();
 17         
 18         String guess;
 19         int comp, wins, losses, ties, bestOf;
 20         
 21         wins = losses = ties = 0;
 22         
 23         String playAgain = "y";
 24         
 25         System.out.println("\tThe rules of Rock-paper-scissors-lizard-Spock are:");
 26         System.out.println("\t\t*\tSpock smashes scissors, scissors cut paper");
 27         System.out.println("\t\t*\tPaper covers rock, rock crushes lizard");
 28         System.out.println("\t\t*\tLizard poisons Spock, Lizard eats paper");
 29         System.out.println("\t\t*\tRock crushes scissors, scissors decapitates lizard");
 30         System.out.println("\t\t*\tSpock vaporizes rock, Paper disproves Spock");
 31         System.out.println();
 32         
 33         while(playAgain.equals("y"))
 34         {        
 35             comp = rand.nextInt(5)+1;
 36             
 37             System.out.print("Please enter rock, paper, scissors, lizard or Spock: ");
 38             guess = scan.nextLine();
 39             System.out.print("The computer selected: ");
 40 
 41             switch(comp)
 42             {
 43                 case 1:
 44                     System.out.print("Rock");
 45                     break;
 46                 case 2:
 47                     System.out.print("Paper");
 48                     break;
 49                 case 3:
 50                     System.out.print("Scissors");
 51                     break;
 52                 case 4:
 53                     System.out.print("Lizard");
 54                     break;
 55                 case 5:
 56                     System.out.print("Spock");
 57                     break;
 58             }
 59             
 60             // calculating the wins
 61             if(guess.equalsIgnoreCase("spock") && comp == 3 || guess.equalsIgnoreCase("scissors") && comp == 2 ||
 62                guess.equalsIgnoreCase("paper") && comp == 1 || guess.equalsIgnoreCase("rock") && comp == 4 || 
 63                guess.equalsIgnoreCase("lizard") && comp == 5 || guess.equalsIgnoreCase("paper") && comp == 4 ||
 64                guess.equalsIgnoreCase("paper") && comp == 5 || guess.equalsIgnoreCase("rock") && comp == 3 ||
 65                guess.equalsIgnoreCase("spock") && comp == 1 || guess.equalsIgnoreCase("lizard") && comp == 2)
 66             {
 67                 System.out.println(" --- You win!");
 68                 wins++;
 69             }    
 70             
 71             // calculting the losses
 72             if(guess.equalsIgnoreCase("rock") && comp == 2 || guess.equalsIgnoreCase("rock") && comp == 5 ||
 73                guess.equalsIgnoreCase("paper") && comp == 3 || guess.equalsIgnoreCase("scissors") && comp == 1 || 
 74                guess.equalsIgnoreCase("scissors") && comp == 4 || guess.equalsIgnoreCase("scissors") && comp == 5 ||
 75                guess.equalsIgnoreCase("lizard") && comp == 1 || guess.equalsIgnoreCase("lizard") && comp == 3 ||
 76                guess.equalsIgnoreCase("spock") && comp == 2 || guess.equalsIgnoreCase("spock") && comp == 4)
 77             {
 78                 System.out.println(" --- You lose!");
 79                 losses++;
 80             }
 81             
 82             // calculating the ties, if they're both same
 83             if(guess.equalsIgnoreCase("rock") && comp == 1 || guess.equalsIgnoreCase("paper") && comp == 2 || 
 84                guess.equalsIgnoreCase("scissors") && comp == 3 || guess.equalsIgnoreCase("lizard") && comp == 4 || 
 85                guess.equalsIgnoreCase("spock") && comp == 5)
 86             {
 87                 System.out.println(" --- It's a tie!");
 88                 ties++;                
 89             }
 90 
 91             // asking the user if they want to play again, if not, exit the while loop show score
 92             System.out.println();
 93             System.out.print("Do you want to play again? ");
 94             playAgain = scan.nextLine();
 95             System.out.println();
 96         }
 97         
 98         // showing the score
 99         System.out.println("Wins - " + wins);
100         System.out.println("Losses - " + losses);
101         System.out.println("Ties - " + ties);
102     }
103 }
104