Skip to content
Snippets Groups Projects
Select Git revision
  • 837734af5fe7ea736b23f1ec4e652bc3f80b7e6c
  • main default protected
  • 39-retour-utilisateur-sur-le-compteur
3 results

Input.java

Blame
  • Input.java 1.45 KiB
    package bitFight;
    
    
    import java.io.IOException;
    import java.util.ArrayList;
    
    public class Input {
        private String input = "";
        private ArrayList<String> inputRange;
    
        public String getInput() {
            return input;
        }
    
        public ArrayList<String> getInputRange() {
            return inputRange;
        }
    
        public void setInput(String input) throws InvalidInputException {
            this.input = input;
            if (!validInput()) {
                throw new InvalidInputException(getInputRange().toString());
            }
            System.out.println(input);
    
        }
    
        public void newInput(String input) {
            do {
                try {
                    setInput(input);     
                } catch (InvalidInputException e) {
                    try {
                        Display.newPrintln(e.getMessage());
                    } catch (IOException e1) {
                        e1.printStackTrace();
                    }
                }
            }
            while (!validInput());
                
        }
    
        public Input() {
            this.inputRange = new ArrayList<>();
            this.inputRange.add("q"); //Commande pour quitter
            this.inputRange.add("a"); //Commande pour attaquer
            for (Attack a : Attack.values()) this.inputRange.add(a.getName());
            for (Defense d : Defense.values()) this.inputRange.add(d.getName());
        }
    
        public boolean validInput() {
            boolean valid = false;
            for(String s : inputRange) if (s.equals(input)) valid = true;
            return valid;
        }
    }