Made the interactive D8 entropy reader more forgiving for a better UX
This commit is contained in:
		
							parent
							
								
									4fd4bb407b
								
							
						
					
					
						commit
						6c781accb0
					
				|  | @ -12,15 +12,31 @@ public class InteractiveDice8EntropyGenerator extends InteractiveEntropyGenerato | |||
|     @Override | ||||
|     protected String readNextEventSetString() { | ||||
| 
 | ||||
|         String eventSetString = ""; | ||||
|         Pattern eventSetPattern = Pattern.compile(String.format("[1-8]{%d}", eventsPerEventSet)); | ||||
|         StringBuilder eventSetBuffer = new StringBuilder(); | ||||
|         int remainingEvents = eventsPerEventSet; | ||||
|         Pattern eventSetPattern = Pattern.compile("[1-8]+"); | ||||
| 
 | ||||
|         while (!eventSetPattern.matcher(eventSetString).matches()) { | ||||
|             System.out.print("Input 11 x 8-sided dice rolls [1-8]: "); | ||||
|             eventSetString = inputScanner.next(); | ||||
|         while (remainingEvents > 0) { | ||||
| 
 | ||||
|             System.out.printf("Input %d x 8-sided dice rolls [1-8]: ", remainingEvents); | ||||
| 
 | ||||
|             String nextInput = inputScanner.next(); | ||||
| 
 | ||||
|             if (!eventSetPattern.matcher(nextInput).matches()) { | ||||
|                 System.out.printf( | ||||
|                         "Invalid input! Enter %d-digit sequence of digits from 1 to 8 (for example, 8765375812)" + System.lineSeparator(), | ||||
|                         remainingEvents); | ||||
|                 continue; | ||||
|             } | ||||
| 
 | ||||
|             eventSetBuffer.append(nextInput); | ||||
|             remainingEvents -= nextInput.length(); | ||||
|         } | ||||
| 
 | ||||
|         return eventSetString; | ||||
|         if (remainingEvents < 0) | ||||
|             System.out.printf("NOTE: Discarding the %d extra dice roll(s) entered" + System.lineSeparator(), -remainingEvents); | ||||
| 
 | ||||
|         return eventSetBuffer.substring(0, eventsPerEventSet); | ||||
|     } | ||||
| 
 | ||||
|     @Override | ||||
|  |  | |||
		Loading…
	
		Reference in New Issue
	
	Block a user