Corrected classpath, new (and clearer) package arrangement.

This commit is contained in:
François Autin
2021-05-27 17:45:02 +02:00
parent b98d1908f6
commit de721b59ab
17 changed files with 42 additions and 29 deletions

View File

@ -0,0 +1,19 @@
package gameplay.input;
public enum Button {
UP, DOWN, LEFT, RIGHT, A, B, C, D;
public int toInt() {
switch (this) {
case UP : return 0;
case DOWN : return 1;
case LEFT : return 2;
case RIGHT : return 3;
case A : return 4;
case B : return 5;
case C : return 6;
case D : return 7;
default : return -1;
}
}
}

View File

@ -0,0 +1,80 @@
package gameplay.input;
public class InputBuffer {
/**
* a list of various inputs being recorded, such as inputs pressed at each frame
* Each element is a tab where each element represent a possible input
* (UP, Down, Right, Left, A, B, C, D)
* if the value at the corresponding index is true, then the input is pressed
* By default, no input is pressed.
*/
private Inputs[] inputList;
/*
* the size of the input buffer
*/
private int size;
/*
* the current position in the tab of the last newest input recorded
* This should never bee accessed outside of this class.
*/
private int pos;
/**
* base constructor of the InputBuffer. Creates a buffer of size 1, with every input empty
*/
public InputBuffer() {
this.size = 1;
this.pos = 0;
this.inputList = new Inputs[1];
}
public InputBuffer(int size) {
this.size = size;
this.pos = 0;
this.inputList = new Inputs[this.size];
for(int i = 0; i < this.size; i++) {
this.inputList[i] = new Inputs();
}
}
/**
* @return the latest added inputs
*/
public Inputs getLatestInputs() {
return this.inputList[this.pos];
}
/**
* Sets the last input without moving the current position
* @param inputs
*/
private void setLatestInputs(Inputs inputs) {
this.inputList[pos] = inputs;
}
/**
* advances the current position to the next one (goes back to the first if at the end
*/
private void nextPos() {
this.pos++;
if(this.pos == size) {this.pos = 0;}
}
/**
* record a new input in the
* @param inputs a size 8 tab of inputs
*/
private void recordInputs(Inputs inputs) {
this.nextPos();
this.setLatestInputs(inputs);
}
}

View File

@ -0,0 +1,66 @@
package gameplay.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
*/
public void recordOneInput(Button b) {
int i = b.toInt();
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()];
}
/**
* 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;
}
public boolean[] getInputs() {
return this.tab;
}
}