#include #include #include "key.h" const int MAX = 15; //These 2 are for the screen dimensions const int ROW = 66; const char HS_FILE[6]={'f','r','g','h','s','\0'}; const char U = 'P'; //These are for the movement and can be programmed const char u = 'p'; const char D = '.'; //const char d = '.'; const char R = ';'; //const char r = ';'; const char L = 'L'; const char l = 'l'; char CAR1[ROW] = " @ @ @ @ @ "; char CAR2[ROW] = " o-o o-o o-o o-o o-o "; char TRUCK1[ROW] = " _/\\_ _/\\_ _/\\_ _/\\_ _/\\_ _/\\_ "; char TRUCK2[ROW] = " o o O O o o O O o o O O "; char PAD[ROW] = "OOOOO OOOOO OOO OOOOO OOOOO OOO OOOOO "; char LOG[ROW] = "=== ===== === === ===== === "; const int CARPOS = 10; const int TRUCKPOS = 13; const int PADPOS = 6; const int LOG1POS = 4; const int LOG2POS = 8; const int FROGS = 3; //Number of frogs you start with const int KEYBOARD = 1; //used to tell isready() what device to look at const int START = ROW*(MAX-1) + 32; const int MAXTIME = 20; typedef char rows[ROW]; rows screen[MAX]; int High_Score = 0; int Score = 0; int Frogs = FROGS; int HOME[6] = {0}; char str1[ROW]; //These hold the array to be ripped apart and printed char str2[ROW]; int start; //This is where to start printing the car/log/etc. int frogger; //This is the frog's position int timer; //Time left to get home bool DEAD = false; //Is he dead? int offset_log=0; int offset_pad=0; int offset_car=0; int offset_truck=0; void cls() {cout << "\033[;H\033[2J" << flush;} void Inst_Screen(); void gotoxy(int row,int col) {cout< 0) Play(); cls(); cout << "Do you want to play another game? (Y/N) "; cin >> choice; cout << "\n\n"; if (choice == 'n' || choice == 'N') PLAY = false; Frogs=3; Score = 0; } while (PLAY); cout << "Thanks for playing! Email comments to awwatkin@eos.ncsu.edu\n\n"; ofstream fout(HS_FILE); fout<= offset_truck) z = y-offset_truck; else z = ROW-offset_truck + y -1; if (TRUCK2[z] != ' ') DEAD = true; break; case 12: if (y>= offset_truck) z = y-offset_truck; else z = ROW-offset_truck + y -1; if (TRUCK1[z] != ' ') DEAD = true; break; case 10: if (y>= ROW - offset_car) z = y-ROW+offset_car-1; else z = offset_car + y -1; if (CAR2[z] != ' ') DEAD = true; break; case 9: if (y>= ROW - offset_car) z = y-ROW+offset_car; else z = offset_car + y; if (CAR1[z] != ' ') DEAD = true; break; case 3: case 7: if (y>= offset_log) z = y-offset_log; else z = ROW-offset_log + y -1; if (LOG[z] == ' ') DEAD = true; break; case 5: if (y>= ROW-offset_pad) z = y-ROW+offset_pad; else z = offset_pad + y; if (PAD[z] == ' ') DEAD = true; break; default : break; } } void Get_Move() { char move; for (int i=1; i<=5000; i++) { if (isready(KEYBOARD)) { cin.get(move); Check_Move(move); break; } //End of if } //End of for } void Check_Move(char move) { int temp = frogger; switch (move) { case U: case u: frogger-=ROW; if (frogger <= ROW * 2) DEAD = true; //if (temp/ROW == 8) // frogger-=1; if (temp/ROW == 7) frogger-=ROW; if (temp/ROW == 5) frogger-=(ROW-1); break; case D: frogger+=ROW; if (temp/ROW == 5) frogger+=ROW+2; if (temp/ROW == 3) frogger+=ROW-1; if (frogger > ROW*MAX) DEAD = true; break; case R: frogger+=1; if ((frogger % ROW) == 0) DEAD = true; break; case L: case l: frogger-=1; if ((frogger % ROW) == 0) DEAD = true; break; default: break; } if (DEAD) return; //Now update what's happening on the screen if not dead int x=frogger/ROW; int y=frogger%ROW; int x2 = temp/ROW; int y2 = temp%ROW; gotoxy(x2+1, y2+1); if (x2 == 14 || x2 ==8) cout << '*' << flush; else cout << ' ' << flush; if (x==2) { //Check to see if we're home int s=0; if (y <=10 && y >=5) { s=2; if (HOME[0]==0) { HOME[0]=1; s=1; } } else if (y<=20 && y>=15) { s=2; if (HOME[1]==0) { HOME[1]=1; s=1; } } else if (y<=30 && y>=25) { s=2; if (HOME[2]==0) { HOME[2]=1; s=1; } } else if (y<=40 && y>=35) { s=2; if (HOME[3]==0) { HOME[3]=1; s=1; } } else if (y<=50 && y>=45) { s=2; if (HOME[4]==0) { HOME[4]=1; s=1; } } else if (y<=60 && y>=55) { s=2; if (HOME[5]==0) { HOME[5]=1; s=1; } } if (s==0) DEAD=true; else if (s==1) { Score+=10; if (Score > High_Score) High_Score = Score; frogger = START; timer = MAXTIME; Draw_Screen(frogger); Timer(timer); return; } else frogger+=ROW; } } void Update_Screen() { //if (frogger/ROW == 3 || frogger/ROW == 7) frogger+=1; //else if (frogger/ROW == 5) frogger -=2; timer--; Timer(timer); gotoxy(frogger/ROW+1, frogger%ROW+1); cout << 'X' << flush; if (frogger/ROW == 3 || frogger/ROW == 7) frogger++; else if (frogger/ROW == 5) frogger-=2; offset_log++; if (offset_log >= ROW) offset_log = 1; substring (LOG,str1,str2,offset_log); Get_Move(); gotoxy(LOG1POS,offset_log+1); cout << str2; gotoxy(LOG1POS,1); cout << str1; Get_Move(); gotoxy(LOG2POS,offset_log+1); cout << str2; gotoxy(LOG2POS,1); cout << str1; Get_Move(); offset_pad+=2; if (offset_pad >= ROW) offset_pad = 1; Get_Move(); substring2 (PAD,str1,str2,offset_pad); gotoxy(PADPOS,1); cout << str1; gotoxy(PADPOS,ROW - offset_pad); cout << str2; Get_Move(); offset_car+=3; if (offset_car >= ROW) offset_car = 1; substring2 (CAR1,str1,str2,offset_car); gotoxy(CARPOS,1); cout << str1; gotoxy(CARPOS,ROW - offset_car); cout << str2; Get_Move(); substring2 (CAR2,str1,str2,offset_car); gotoxy(CARPOS+1,1); cout << str1; gotoxy(CARPOS+1,ROW - offset_car); cout << str2; Get_Move(); offset_truck+=1; if (offset_truck >= ROW) offset_truck = 1; substring (TRUCK1,str1,str2,offset_truck); Get_Move(); gotoxy(TRUCKPOS,offset_truck+1); cout << str2; gotoxy(TRUCKPOS,1); cout << str1; Get_Move(); substring (TRUCK2,str1,str2,offset_truck); gotoxy(TRUCKPOS+1,offset_truck+1); cout << str2; gotoxy(TRUCKPOS+1,1); cout << str1; Get_Move(); gotoxy(frogger/ROW+1, frogger%ROW+1); cout << 'X' << flush; } void Init_Screen() { screen[0] = "*****************************************************************"; screen[8] = screen[0]; screen[14] = screen[0]; screen[1] = "***** ***** ***** ***** ***** ***** *****"; screen[2] = screen[1]; screen[3] = " "; screen[4] = screen[3]; screen[5] = screen[3]; screen[6] = screen[3]; screen[7] = screen[3]; screen[9] = screen[3]; screen[10] = screen[3]; screen[11] = screen[3]; screen[12] = screen[3]; screen[13] = screen[3]; ifstream fin(HS_FILE); if (fin) {fin>>High_Score;} fin.close(); } void Draw_Screen(int frogger) { int a = 0; for (int i=0; i<6; i++) if (HOME[i]==1) a++; if (a==6) for (int i=0; i<6; i++) HOME[i]=0; cls(); int x=frogger/ROW; int y=frogger%ROW; screen[x][y] = 'X'; for (int i=0; i < MAX; i++) cout << screen[i] << endl; gotoxy (1,ROW+3); cout << "Score"; gotoxy (2,ROW+3); cout << "-----"; gotoxy (3,ROW+3); cout << setiosflags(ios::right) << setw(5) << Score << resetiosflags(ios::right); gotoxy (7,ROW+2); cout << "HScore"; gotoxy (8,ROW+2); cout << "------"; gotoxy (9,ROW+2); cout << setiosflags(ios::right) << setw(6) << High_Score << resetiosflags(ios::right); gotoxy (13,ROW+3); cout << "Frogs"; gotoxy (14,ROW+3); cout << "-----"; for (int i=1; i<= Frogs; i++) { gotoxy (15,ROW+4+i-1); cout << 'X'; } cout << " "; gotoxy(10,0); cout << CAR1 << endl << CAR2 << "\n\n" << TRUCK1 << endl << TRUCK2; gotoxy(4,0); cout << LOG << "\n\n" << PAD << "\n\n" << LOG; gotoxy(19,29); cout << "FROGGER!!" << endl; for (int i=0; i<6; i++) if (HOME[i] !=0) { gotoxy(2,(i+1)*10-4); cout << " X X"; gotoxy(3,(i+1)*10-4); cout << "X X" << flush; } } void Inst_Screen() { cls(); gotoxy(0,0); cout<<"********************************************************************************"; for (int i=1; i<25; i++) { gotoxy(i,0); cout<<'*'; gotoxy(i,80); cout<<'*'; } gotoxy(25,0); cout<<"********************************************************************************"; int x=3; int y=12; gotoxy(x,y); cout<<"****** ***** ****** ****** ****** ****** *****"; gotoxy(++x,y); cout<<"* * * * * * * * * *"; gotoxy(++x,y); cout<<"**** ***** * * * **** * **** **** *****"; gotoxy(++x,y); cout<<"* * * * * * * * * * * *"; gotoxy(++x,y); cout<<"* * * ****** ****** ****** ****** * *"; x=x+3; gotoxy(x,y+12); cout << "The Arcade Classic Goes Text!!!"; x=x+2; gotoxy(x,y+20); cout << "By Alan Watkins"; x=x+3; gotoxy(x,y+26); cout << "UP"; x=x+2; gotoxy(x,y+26); cout<