+/EE422C

software design

git clone https://git.julia.blue/+/EE422C

Joseph RyanAdd the rest of the files7e47727

master
913 B35 linesraw
1/**
2 * EE422C Project 2 (Mastermind) submission by
3 * Joseph Ryan
4 * jbr2558
5 * Slip days used: <0>
6 * Spring 2019
7 */
8package assignment2;
9
10import java.util.Scanner;
11
12class Parser {
13    private Scanner s;
14
15    Parser(Scanner s) {
16        this.s = s;
17    }
18
19    String getGuess(int remaining) {
20        while (true) {
21            System.out.println("You have " + remaining + " guess(es) left.");
22            System.out.println("Enter guess:");
23            String input = s.next();
24            if (input.equals("HISTORY")) {
25                return input;
26            }
27            if (input.chars().allMatch(ch -> String.join("", GameConfiguration.colors)
28                    .chars().anyMatch(color -> color == ch)) && input.length() == GameConfiguration.pegNumber) {
29                return input;
30            }
31            System.out.println("INVALID_GUESS");
32            System.out.println();
33        }
34    }
35}