Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * return 1 if can move right, 2 if can move left, 0 if cant move
- */
- public int canMoveHorz(int carId){
- int xPos = 0;
- int yPos = 0;
- int length = 0;
- int retVal = 0;
- for(Vehicle v: this.getVehicles()) {
- if(v.getCarID() == carId) {
- xPos =v.getCurrColumn();
- yPos =v.getCurrRow();
- length = v.getLength();
- }
- }
- //check right movement
- if(xPos+length >= 0 && xPos+length <= 5) {
- if(this.array[xPos+length][yPos] == 0) {
- retVal = 1;
- }
- }
- //check left movement
- else if(xPos-1 >= 0 && xPos-1 <= 5) {
- if(this.array[xPos-1][yPos] == 0) {
- retVal = 2;
- }
- }
- else {
- }
- return retVal;
- }
- public int canMoveVert(int carId){
- int xPos = 0;
- int yPos = 0;
- int length = 0;
- int retVal = 0;
- for(Vehicle v: this.getVehicles()) {
- if(v.getCarID() == carId) {
- xPos =v.getCurrColumn();
- yPos =v.getCurrRow();
- length = v.getLength();
- }
- }
- //check down movement
- if(xPos+length >= 0 && xPos+length <= 5) {
- if(this.array[xPos][yPos+length] == 0) {
- retVal = 1;
- }
- }
- //check up movement
- else if(xPos-1 >= 0 && xPos-1 <= 5) {
- if(this.array[xPos][yPos-1] == 0) {
- retVal = 2;
- }
- }
- else {
- }
- return retVal;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement