MCPcopy Create free account
hub / github.com/PrajaktaSathe/Java / play

Method play

Programs/Games/GuessTheNumber.java:53–100  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

51 }
52
53 public void play(){
54 setGuessedToNull();
55 int secretNum = generateRand(rng);
56 System.out.println("I am Thinking of a word between 0-"+ rng + ".");
57 Scanner scanGuess;
58 int guess;
59 boolean flag = true;
60 do{
61 System.out.print("Remaining guesses: "+this.guesses+"\nRemaining warnings: "+this.warning + "\nGuessed Numbers: "); printGuessed();
62 scanGuess = inputInt();
63 if(isValid(scanGuess)){
64 guess = scanGuess.nextInt();
65 if(guess == secretNum)
66 {
67 System.out.println("Congratulations! You have guessed the secret number!!");
68 flag = false;
69 }
70 else if ((this.warning) > 0 && (this.guesses > 0)) {
71
72 if(isAlreadyTold(guess)){
73 this.warning--;
74 this.guesses--;
75 System.out.println("You have already guessed this number");
76 }else
77 if(guess < secretNum){
78 this.guesses--;
79 System.out.println("Guessed number is less than secret number.");
80 setAlreadyTold(guess);
81 }else {
82 this.guesses--;
83 System.out.println("Guessed number is greater than secret number.");
84 setAlreadyTold(guess);
85 }
86
87 } else {
88 System.out.println("Game Over!");
89 flag = false;
90 }
91 } else if (this.specialWarning>0){
92 System.out.println("Invalid Input!!!");
93 this.specialWarning--;
94 }else{
95 System.out.println("Invalid Input!!!");
96 this.guesses--;
97 }
98
99 }while(flag);
100 }
101
102 public static void main(String[] args){
103 GuessTheNumber n = new GuessTheNumber();

Callers 1

mainMethod · 0.95

Calls 8

setGuessedToNullMethod · 0.95
generateRandMethod · 0.95
printGuessedMethod · 0.95
inputIntMethod · 0.95
isValidMethod · 0.95
isAlreadyToldMethod · 0.95
setAlreadyToldMethod · 0.95
printMethod · 0.80

Tested by

no test coverage detected