-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCommandLineInterface.java
More file actions
53 lines (48 loc) · 1.83 KB
/
CommandLineInterface.java
File metadata and controls
53 lines (48 loc) · 1.83 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
import static cs1.Keyboard.*;
import java.util.*;
public class CommandLineInterface{
private SongList songs;
private Contestant player;
public CommandLineInterface(){
player = new Contestant();
songs = null;
}
public void play(){
System.out.println("Welcome to GuessThatTune!");
System.out.print("Please input your name:");
player.changeName(readString());
System.out.print("How many rounds would you like to play?:");
player.setNumRounds(readInt());
System.out.print("Where are your songs? For this directory, type \"here\" or type a custom path:");
String path = readString();
if (path.equals("here") || path.equals("Here"))
songs = new SongList(".");
else
songs = new SongList(path);
System.out.println("Perfect! Let's get started! You'll hear 10 seconds of a song and you can then guess which song it was.");
for (int i = 0; i < player.getNumRounds(); i++){
ArrayList<String> songList= songs.get4RandomSongs();
int song = (int)(Math.random() * 4);
AdvancedMP3 musicPlayer = new AdvancedMP3(songs.getSongPath(songList.get(song)));
musicPlayer.play(380);
for (int j = 0; j < 4; j++){
System.out.println(j + ": " + songList.get(j));
}
System.out.print("Please enter the corresponding number to your guess:");
int guess = readInt();
musicPlayer.close();
if (guess == song){
System.out.println("Correct!");
player.addScore();
}
else
System.out.println("I'm sorry, the correct answer was " + songList.get(song));
System.out.println("-------------------");
}
System.out.println("Congratulations, you've completed " + player.getNumRounds() + " rounds and got " + Math.round(player.getScore() * 1.0 / player.getNumRounds() * 100) + " percent correct!");
}
public static void main(String[] args) {
CommandLineInterface game = new CommandLineInterface();
game.play();
}
}