forked from MetroCS/ConsoleGameHub
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNumberGuessGame.java
More file actions
33 lines (32 loc) · 1.1 KB
/
NumberGuessGame.java
File metadata and controls
33 lines (32 loc) · 1.1 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
import java.util.Optional;
/**
* A simple guessing game where the computer selects a number in a
* given range (for example, 1 to 100),
* and the player must guess the number in as few attempts as possible.
* Feedback is given after each guess (e.g., "Too high", "Too low").
* <pre>
* The score can be calculated based on number of attempts or time taken.
* </pre>
* @version 1
*/
class NumberGuessGame implements Game {
/**
*gets the string name.
*@return Number Guess.
*/
public String getName() {
return "Number Guess";
}
/**
*Starts the game and prints game instructions.
*@return an empty optional instance to represent the absence of a score.
*/
public Optional<Integer> play() {
System.out.println("[Playing Number Guessing Game]");
System.out.println("This is a simple game where you"
+ " try and guess the number I pick.");
System.out.println("If you are too high or too low I will let"
+ " you know. Try to do it in the fewest attempts!");
return Optional.empty();
}
}