-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMemoryGame.java
More file actions
97 lines (73 loc) · 2.56 KB
/
MemoryGame.java
File metadata and controls
97 lines (73 loc) · 2.56 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
package memoryGame;
import java.util.Scanner;
import java.util.Timer;
import java.util.TimerTask;
import java.util.Random;
public class MemoryGame {
public static void main(String[] args) {
// TODO Auto-generated method stub
System.out.println("Welcome to Memory Game! \n \n");
String instruction = "-Instruction- \nThere is a stone in one of the 3 upside down cups\n"
+ "It will be shuffled and your task is to know where is the stone among the 3 cups";
System.out.println(instruction);
System.out.println("Enter any key to start shuffling, q to quit");
String quit = "q";
Scanner start = new Scanner(System.in);
String q = start.nextLine();
boolean ref = q.equals(quit);
System.out.println("Enter your name: ");
start = new Scanner(System.in);
String name = start.nextLine();
Player player = new Player();
player.addName(name);
System.out.println("Hello, " + player.name + "\nStart the game by entering any key, q to quit\n" );
start = new Scanner(System.in);
q = start.nextLine();
ref = q.equals(quit);
while(!ref) {
try{
int cups = 3;
int[] answers = new int[3];
int[] numberShowing = new int[3];
for(int j = 1;j<=cups;j--) {
numberShowing[j] = showNumbers();
System.out.println("Shuffling.....");
System.out.println("your guess is cup: ");
Scanner answer= new Scanner(System.in);
int ans = answer.nextInt();
answers[j] = ans;
if(answers[j]!=numberShowing[j]){
System.out.println("Wrong!");
System.out.println("Press enter key to shuffle the cups again or q to quit");
start = new Scanner(System.in);
q = start.nextLine();
ref = q.equals(quit);
}else{
System.out.println("Correct!");
System.out.println("Press enter key to shuffle the cups again or q to quit");
start = new Scanner(System.in);
q = start.nextLine();
ref = q.equals(quit);
continue;
}
}
}
catch(Exception e){
System.out.println("Error, Make sure to put correct number from 1-3");
System.out.println("Press enter key to shuffle the cups again or q to quit");
start = new Scanner(System.in);
q = start.nextLine();
ref = q.equals(quit);
continue;
}
}
}
public static int showNumbers() {
int number;
int min = 1;
int max = 3;
Random random = new Random();
number = ((int)(Math.random()*(max-min+1)+min));
return number;
}
}