Bug 606

Summary: Failed initialization of ghost algorithms
Product: Group14-Pacman Reporter: Aleksa <ajelaca2-c>
Component: GameAssignee: Omar MOUSTAFA <omoustafa2-c>
Status: RESOLVED FIXED    
Severity: critical CC: tianxyang3-c
Priority: High    
Version: 0.0.1   
Hardware: PC   
OS: Windows   

Description Aleksa 2021-11-24 15:38:22 HKT
I ran Main.java with "Frightened" as the initial mode. I expected to see a maze drawn on the console. Instead, I got this output from the Eclipse:

User Input:
Please, specify your name:
Aleksa
Please specify the difficulty (Easy, Medium, Hard):
Easy

User Output:
java.util.NoSuchElementException: No line found
	at java.base/java.util.Scanner.nextLine(Scanner.java:1651)
	at Game.Mode.initModes(Mode.java:85)
	at Game.Game.gameInit(Game.java:43)
	at Game.Main.main(Main.java:20)
Algorithm file src/Resource/easyAlgorithmData.txt not found
Ghost algorithms init failed!
Comment 1 Aleksa 2021-11-24 15:43:44 HKT
I realized that when I deleted FrightenedWandering from the easyGhostAlgorithm.txt, the scanner.next() was called from boolean initModes(String) in Mode.java, although there is nothing more to read. Thus, a solution is to change the code in boolean initModes(String) like this:


if(scanner.hasNext()) {
	for (int j = 0; j < numGhosts; j++) {
	tempMode.addAlgorithm(scanner.nextLine());
					}
				}