//Player class //Players are classes // Can move Up, Left, Right, Down // Knows position and if it's crashed. // Also knows what direction it's moving in. // //Board class //The enitre board is an array also a class // 17 Rows X 76 cols (78 total on screen, 2 for border) // Can tell if a certain square is occupied or out of range // Can put a number in it's array to mean a space is occupied #include "common.h" #include "Player.h" #include "Board.h" #include "getchars.h" #include //#include void Banner(); //Prints initial screen char Get_Move(); //Gets a key from the keyboard void Process_Move(char, Player*, Player*); void Win(int who); void Inst(); //Instructions //ofstream out; int main() { // out.open("out.txt"); set_keypress(); //Allows a single keypress to be read echo_off(); //Doesn't echo keypress to the screen Banner(); char in; while (isready(KEYBOARD)) cin.get(in); //Clear the buffer while (!isready(KEYBOARD)) ; //Do nothing until key is pressed cin.get(in); switch (in) { case 'i': case 'I' : Inst(); break; default : break; } bool PLAY_AGAIN =true; while (PLAY_AGAIN) { //Main prg loop Board TheBoard; TheBoard.Draw(); Player one(START_X1,START_Y1,RIGHT); Player two(START_X2,START_Y2,LEFT); char move; while (!one.Crashed() && !two.Crashed()) { //Play routine goes here. // Come up with appropriate # of times to scan keyboard // If a key is pressed correctly, change direction // otherwise continue in same direction move = Get_Move(); //out << move << ' ' << int(move) <Set_Dir(UP); break; case UP2 : two->Set_Dir(UP); break; case DOWN1 : one->Set_Dir(DOWN); break; case DOWN2 : two->Set_Dir(DOWN); break; case RIGHT1 : one->Set_Dir(RIGHT); break; case RIGHT2 : two->Set_Dir(RIGHT); break; case LEFT1 : one->Set_Dir(LEFT); break; case LEFT2 : two->Set_Dir(LEFT); break; default : break; //cout << "Error in PROCESS_MOVE. move=" << move << flush; break; } //End of switch } void Banner() { cls(); for (int i=0; i<=79; i++) {cout<<'*';} for (int i=0; i<=6; i++) { cout << '*'; for (int x=1; x<=78; x++) {cout <<' ';} cout << '*'; } cout<< "* SSSSSS U U RRRRRR RRRRRR OOOOOO U U N N DDDDD *\n"; cout<< "* S U U R R R R O O U U NN N D D *\n"; cout<< "* SSSSSS U U RRRRR RRRRR O O U U N N N D D *\n"; cout<< "* S U U R R R R O O U U N N N D D *\n"; cout<< "* SSSSSS UUUUUU R R R R OOOOOO UUUUUU N NN DDDDD *\n"; for (int i=0; i<=9; i++) { cout << '*'; for (int x=1; x<=78; x++) {cout <<' ';} cout << '*'; } for (int i=0; i<=79; i++) {cout<<'*';} cout << flush; gotoxy(18,30); cout << "I - Instructions"; gotoxy(19,30); cout << "Any other to play" << flush; } char Get_Move() { char move = 'Q'; for (int i=1; i<=5000; i++) { if (isready(KEYBOARD)) { cin.get(move); break; } //End of if } //End of for //gotoxy (15,30); cout << int(move) << flush; //out << "In Get_Move, move ="<