//Demonstrates basic animation and displays a selected symbol //Created by Gilad "Speaker For The Dead" Barlev //Final Edit on 25/2/02 (D/M/Y) #include #include #include #include using namespace std; int randInt(int lower, int upper) {//randInt - converts the rand() function into one that is easier to use srand(time(NULL)); return lower + rand() % (upper - lower + 1); }//end randInt function void main() {//main - main function //declare variables int x; int y; int posx = 4; int posy = 8; int obj1x = 0; int obj1y = 0; int obj2x = 0; int obj2y = 0; const int startx = 2; //starting x position of animation field const int starty = 2; //starting y position of animation field int getKey = 0; while ((obj1x == obj2x) && (obj1y == obj2y)) {//randomize location of two objects obj1x = randInt(1,8); obj1y = randInt(1,16); obj2x = randInt(1,8); obj2y = randInt(1,16); }//end randomize while (getKey != 13) {//animation loop system("cls"); //clear screen x = 0; while (x < 8 + startx) {//while in animation field (x) x++; y = 0; if (x == startx + 1) {//get to top of box while (y < starty - 1) {//indent y++; cout << " "; }//end of indent cout << "*******************" << endl; // display top border y = 0; }//end get to animation field while (y < 16 + starty) {//while in animation field (y) y++; if (x == posx + startx && y == posy + starty) cout << "*"; //display cursor else {//display other items if (y == starty && x > startx) cout << "*"; //display left border if (x == obj1x + startx && y == obj1y + starty) cout << "+"; //display object 1 if (x == obj2x + startx && y == obj2y + starty) cout << "/"; //display object 2 if ((x != obj1x + startx || y != obj1y + starty) && (x != obj2x + startx || y != obj2y + starty)) cout << " "; }//end of display }//end of while in animation field (y) if (x > startx) cout << "*"; //display right border cout << endl; }//end of while in animation field (x) y = 0; while (y < starty - 1) {//indent last line y++; cout << " "; }//end indent cout << "*******************" << endl; //display bottom border getKey = getch(); //get keystroke if (getKey == 72 && posx > 1) posx = posx - 1; //move cursor up if (getKey == 80 && posx < 8) posx = posx + 1; //move cursor down if (getKey == 75 && posy > 1) posy = posy - 1; //move cursor left if (getKey == 77 && posy < 16) posy = posy + 1; //move cursor right }//end of animation loop system("cls"); //clear screen //display which icon was selected (if any) cout << "You selected: "; if (posx == obj1x && posy == obj1y) cout << "+"; if (posx == obj2x && posy == obj2y) cout << "/"; if ((posx != obj1x || posy != obj1y) && (posx != obj2x || posy !=obj2y)) cout << "Neither object :("; cout << endl; getch(); //credits system("cls"); //clear screen cout << "This program was made by Speaker For The Dead for entertainment purposes only." << endl << "For problems with this program or more information on Speaker For The Dead," << endl << "Please send an email to the_sftd@yahoo.com" << endl; }//end of main function //This program was made by Speaker For The Dead for entertainment purposes only. //For problems with this program or more information on Speaker For The Dead, //Please send an email to the_sftd@yahoo.com