Advertisement
Guest User

Untitled

a guest
May 24th, 2018
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.24 KB | None | 0 0
  1. /*
  2. * return 1 if can move right, 2 if can move left, 0 if cant move
  3. */
  4. public int canMoveHorz(int carId){
  5. int xPos = 0;
  6. int yPos = 0;
  7. int length = 0;
  8. int retVal = 0;
  9. for(Vehicle v: this.getVehicles()) {
  10. if(v.getCarID() == carId) {
  11. xPos =v.getCurrColumn();
  12. yPos =v.getCurrRow();
  13. length = v.getLength();
  14. }
  15. }
  16. //check right movement
  17. if(xPos+length >= 0 && xPos+length <= 5) {
  18. if(this.array[xPos+length][yPos] == 0) {
  19. retVal = 1;
  20. }
  21. }
  22. //check left movement
  23. else if(xPos-1 >= 0 && xPos-1 <= 5) {
  24. if(this.array[xPos-1][yPos] == 0) {
  25. retVal = 2;
  26. }
  27. }
  28. else {
  29. }
  30. return retVal;
  31. }
  32.  
  33.  
  34. public int canMoveVert(int carId){
  35. int xPos = 0;
  36. int yPos = 0;
  37. int length = 0;
  38. int retVal = 0;
  39. for(Vehicle v: this.getVehicles()) {
  40. if(v.getCarID() == carId) {
  41. xPos =v.getCurrColumn();
  42. yPos =v.getCurrRow();
  43. length = v.getLength();
  44. }
  45. }
  46. //check down movement
  47. if(xPos+length >= 0 && xPos+length <= 5) {
  48. if(this.array[xPos][yPos+length] == 0) {
  49. retVal = 1;
  50. }
  51. }
  52. //check up movement
  53. else if(xPos-1 >= 0 && xPos-1 <= 5) {
  54. if(this.array[xPos][yPos-1] == 0) {
  55. retVal = 2;
  56. }
  57. }
  58. else {
  59. }
  60. return retVal;
  61. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement