Guest User

Untitled

a guest
Feb 19th, 2018
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.18 KB | None | 0 0
  1. //This is the only function I have problems with, It doesn't incriment things properly, and it also gets out of the scope and goes to my default case in my second switch statement. as well as accesses my else statement on line 162
  2.  void willie_travels(Point& willie,char school_board[][WIDTH], float& nothing,float& fall1,float& bruise,float& found1)
  3. 110 {
  4. 111   int oldY = willie.m_yCoord;
  5. 112   int oldX = willie.m_yCoord;
  6. 113   int newY, newX;
  7. 114   switch(rand()%4)
  8. 115   {
  9. 116     case LEFT:
  10. 117       newY = oldY;
  11. 118       newX = oldX -1;
  12. 119       break;
  13. 120     case RIGHT:
  14. 121       newY = oldY;
  15. 122       newX = oldX +1;
  16. 123       break;
  17. 124     case UP:
  18. 125       newY= oldY -1;
  19. 126       newX = oldX;
  20. 127     case DOWN:
  21. 128       newY = oldY +1;
  22. 129       newX = oldX;
  23. 130       break;
  24. 131   }
  25. 132   if(newY >= 0 && newY < HEIGHT && newX >=0 && newX <WIDTH)
  26. 133   {
  27. 134     switch(school_board[newY][newX])
  28. 135     {
  29. 136       case cEmpty: //if the space is empty
  30. 137         school_board[oldY][oldX] = cEmpty;
  31. 138         school_board[newY][newX] = Willie;
  32. 139         willie.m_yCoord = newY;
  33. 140         willie.m_xCoord = newX;
  34. 141
  35. 142         nothing++;
  36. 143         break;
  37. 144       case Window: //he hits the window
  38. 145         school_board[oldY][oldX] = cEmpty;
  39. 146         fall1++;
  40. 147         break;
  41. 148       case Wall: //hits the wall
  42. 149         bruise++; //need to incriment bruise as well as nothing
  43. 150         nothing++;
  44. 151         break;
  45. 152       case Lunch: //finds the lunch
  46. 153         school_board[oldY][oldX] = Lunch;
  47. 154         found1++;
  48. 155         break;
  49. 156       default:
  50. 157         cout<<"entering default here"<<endl;
  51. 158         cout<<school_board[oldY][oldX]<<endl;
  52. 159
  53. 160     }
  54. 161   }
  55. 162   else
  56. 163    cout<<"Not in scope newY is:  "<<newY<<"Newx is : "<<newX<<endl;
  57. 164   display_board(school_board);
  58. 165     //TODO: when its not within the scope of the board what do you do.
  59. 166       //TODO: ask what happensn when the movement is not in the scope.
  60. 167   cout<<"Found: "<<found1<<endl;
  61. 168   cout<<"bruise: "<<bruise<<endl;
  62. 169   cout<<"fell: "<<fall1<<endl;
  63. 170   cout<<"Nothign: "<<nothing<<endl;
  64. 171
  65. 172 }
Add Comment
Please, Sign In to add comment