/*********************************************************** Copyright 2003 Rick Miller - Pulp Free Press This source code accompanies the text C++ For Artists and is provided for instructional purposes only. No warranty concerning the quality of the code is expressed or implied. You are free to use this code in your programs so long as this copyright notice is included in its entirety. **********************************************************/ /********************************************* File: robotrat.cpp Student Name: Project: Class: ...and any additional header info **********************************************/ #include "robotrat.h" #include #include /******************************************** File Scope Variable Declarations ********************************************/ namespace robotrat{ static bool floor[ROWS][COLS] = {}; static PenPosition pen_position = UP; static Direction rats_direction = EAST; static int current_row = 0; static int current_col = 0; } /******************************************** Function Definitions *********************************************/ void displayMenu(){ cout<<" 1. Pen Up"<>spaces; switch(robotrat::pen_position){ case UP: switch(robotrat::rats_direction){ case NORTH: if(robotrat::current_row - spaces) robotrat::current_row -= spaces; else robotrat::current_row = 0; break; case SOUTH: if((robotrat::current_row + spaces) < ROWS) robotrat::current_row += spaces; else robotrat::current_row = (ROWS-1); break; case EAST: if((robotrat::current_col + spaces) < COLS) robotrat::current_col += spaces; else robotrat::current_col = (COLS-1); break; case WEST: if(robotrat::current_col - spaces) robotrat::current_col -= spaces; else robotrat::current_col = 0; break; default: ; } break; case DOWN: switch(robotrat::rats_direction){ case NORTH: if((robotrat::current_row - spaces)<=0) spaces = robotrat::current_row; while(spaces){ robotrat::floor[robotrat::current_row--][robotrat::current_col] = true; --spaces; } break; case SOUTH: if( (robotrat::current_row + spaces) > ROWS) spaces = ((ROWS-1) - robotrat::current_row); while(spaces){ robotrat::floor[robotrat::current_row++][robotrat::current_col] = true; --spaces; } break; case EAST: if((robotrat::current_col + spaces) >= COLS) spaces = ((COLS-1) - robotrat::current_col); while(spaces){ robotrat::floor[robotrat::current_row][robotrat::current_col++] = true; --spaces; } break; case WEST: if(robotrat::current_col - spaces<=0) spaces = robotrat::current_col; while(spaces){ robotrat::floor[robotrat::current_row][robotrat::current_col--] = true; --spaces; } break; default: ; } break; default: ; } } void printFloor(){ for(int i=0; i>input; switch(input){ case '1': setPenUp(); break; case '2': setPenDown(); break; case '3': turnRight(); break; case '4': turnLeft(); break; case '5': move(); break; case '6': printFloor(); break; case '7': programExit(); default : doDefault(); } }