#include using namespace std; /* Need a robot class, which deals with moving it over a space. Collision function needs to return a value on where it will be next. The world class will have an instance of the robot, which will then check that new position against something that 'exists' in the world. For example, using an IF...: Keyboard takes in input and then calls something in the World class. This function runs a function from the robot instance in it, and checks to see if it collides. If it doesn't, it calls the next function in the robot class, which moves it, and then it calls a function to print the coordinates. */ class Robot { private: int x; // X Coordinate. int y; // Y Coordinate. public: // Function returning what would be the next coord. // It must figure out which direction the person entered. int newPos( char Direction ); // Must have a function to set the values and move the bot. int moveBot( int newCoord, int which ); // Just prints out the coordinates. void printCoords(); } int Robot::newPos( char Direction ) { // Remember, this does nothing about finding the external barrier. // It simply returns it, the world will deal with whether it's actually // allowed or not (such as in if it's in the boundaries of space or not). switch( Direction ) { case "l": case "L": case "<": return x - 1; break; case "r": case "R": case ">": return x + 1; break; case "u": case "U": case "^": return y - 1; break; case "d": case "D": case "v": return y + 1; break; default: return -2; break; }; return -3; // If something went wrong, this is a sort of check. } int Robot::moveBot( int newCoord, int which ) { // When changing the stuff from the World class, this function will be called twice. if( which == 0 ) { x = newCoord; return 1; } else if( which == 1 ) { y = newCoord; return 1; } else { return -1; } // Minor error check. } void Robot::printCoords() { cout << "Robot is at location: << x << ", " << y << "\n"; } class World { private: // Hack: // In a bit, use a class instead and just call three instances that uses random to set the positions randomly. int x_0; // X coordinate for rock 1. int y_0; int x_1; int y_1; int x_2; int y_2; Robot robo; // Chrono Trigger referenceGET. int width; // Of the world. int height; // Again, of the 'world'. public: /* Call the newPos function of the robot and check to see if that would collide with a rock or go out of bounds. Will check to see if this goes well in the main function, hence the int return type. Needs to take in the input from the keyboard to pass along to the robot moving function. */ int MoveBot( char Direction ); void moveRockCollide(); // Will print a message. void moveBoundEnd(); // Reached the end of the world. void moveSuccess(); // Will call the Robot::moveBot function and print a sucess line. } int World::MoveBot( char Direction ) { /* This is the main function of the World First, must make sure that the position it returns is not an error (-2 / -3). Then it must check to make sure that it does not extend beyond the boundaries of the world. Then it must check to make sure that it does collide with a rock. If it does none of the above, call the Robot::MoveBot and Robot::printCoords. However, if it did run into something, it will call the proper function. switch( robo.newPos( Direction ) ) { case 0: // if the return value is 0, must make sure