Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //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
- void willie_travels(Point& willie,char school_board[][WIDTH], float& nothing,float& fall1,float& bruise,float& found1)
- 110 {
- 111 int oldY = willie.m_yCoord;
- 112 int oldX = willie.m_yCoord;
- 113 int newY, newX;
- 114 switch(rand()%4)
- 115 {
- 116 case LEFT:
- 117 newY = oldY;
- 118 newX = oldX -1;
- 119 break;
- 120 case RIGHT:
- 121 newY = oldY;
- 122 newX = oldX +1;
- 123 break;
- 124 case UP:
- 125 newY= oldY -1;
- 126 newX = oldX;
- 127 case DOWN:
- 128 newY = oldY +1;
- 129 newX = oldX;
- 130 break;
- 131 }
- 132 if(newY >= 0 && newY < HEIGHT && newX >=0 && newX <WIDTH)
- 133 {
- 134 switch(school_board[newY][newX])
- 135 {
- 136 case cEmpty: //if the space is empty
- 137 school_board[oldY][oldX] = cEmpty;
- 138 school_board[newY][newX] = Willie;
- 139 willie.m_yCoord = newY;
- 140 willie.m_xCoord = newX;
- 141
- 142 nothing++;
- 143 break;
- 144 case Window: //he hits the window
- 145 school_board[oldY][oldX] = cEmpty;
- 146 fall1++;
- 147 break;
- 148 case Wall: //hits the wall
- 149 bruise++; //need to incriment bruise as well as nothing
- 150 nothing++;
- 151 break;
- 152 case Lunch: //finds the lunch
- 153 school_board[oldY][oldX] = Lunch;
- 154 found1++;
- 155 break;
- 156 default:
- 157 cout<<"entering default here"<<endl;
- 158 cout<<school_board[oldY][oldX]<<endl;
- 159
- 160 }
- 161 }
- 162 else
- 163 cout<<"Not in scope newY is: "<<newY<<"Newx is : "<<newX<<endl;
- 164 display_board(school_board);
- 165 //TODO: when its not within the scope of the board what do you do.
- 166 //TODO: ask what happensn when the movement is not in the scope.
- 167 cout<<"Found: "<<found1<<endl;
- 168 cout<<"bruise: "<<bruise<<endl;
- 169 cout<<"fell: "<<fall1<<endl;
- 170 cout<<"Nothign: "<<nothing<<endl;
- 171
- 172 }
Add Comment
Please, Sign In to add comment