2021-05-27 13:43:42 +02:00
|
|
|
package input;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The class handling the parsing of one input.
|
|
|
|
* @author Victor
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
public class Inputs {
|
|
|
|
private static final int numberOfInputs = 8;
|
|
|
|
private static boolean[] tab;
|
|
|
|
|
|
|
|
public Inputs() {
|
|
|
|
this.tab = new boolean[numberOfInputs];
|
|
|
|
for(int i = 0; i < numberOfInputs; i ++) {
|
|
|
|
this.tab[i] = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* record one input
|
|
|
|
* @param i the integer value corresponding to the tab location
|
|
|
|
*/
|
2021-05-27 14:13:02 +02:00
|
|
|
public void recordOneInput(Button b) {
|
|
|
|
int i = b.toInt();
|
2021-05-27 13:43:42 +02:00
|
|
|
this.tab[i] = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Check if a specific input (for example UP) has been recorded
|
|
|
|
* @param i the integer value corresponding to the input
|
|
|
|
* @return
|
|
|
|
*/
|
|
|
|
public boolean containsInput(Button b) {
|
|
|
|
return this.tab[b.toInt()];
|
|
|
|
}
|
|
|
|
|
2021-05-27 14:13:02 +02:00
|
|
|
/**
|
|
|
|
* Check if a number of inputs are contained simultaneously
|
|
|
|
* @param in a number of inputs. Check if those are containes in this
|
|
|
|
* @return true if all inputs of in are also in this
|
|
|
|
*/
|
|
|
|
public boolean containsInputs(Inputs in) {
|
|
|
|
for(int i = 0; i < numberOfInputs; i++) {
|
|
|
|
if(this.tab[i] != in.getInputs()[i]) {return false;}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Check if a number of inputs are contained simultaneously, in the form of an array of Buttons
|
|
|
|
* @param bs a number of inputs. Check if those are contained in this
|
|
|
|
* @return true if all inputs of in are also in this
|
|
|
|
*/
|
|
|
|
public boolean containsButtonTab(Button[] bs) {
|
|
|
|
for(int i = 0; i < bs.length; i++) {
|
|
|
|
if(!this.containsInput(bs[i])) { return false;}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2021-05-27 13:43:42 +02:00
|
|
|
public boolean[] getInputs() {
|
|
|
|
return this.tab;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|