1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110
|
#include <iostream>
#include <windows.h>
using namespace std;
void printarray(char);
void gotoxy (int x, int y);
int main()
{
int num = 10;
int q,w,e,r;
cout<<"This exercise contains a 10 by 10 grid and four fixation targets.\n";
cout<<"Please enter the target flashing periods(in ms, preferably, multiples of 25).\n";
cout<<"Target 1: "; cin>>q; cout<<"Target 2: "; cin>>w;
cout<<"Target 3: "; cin>>e; cout<<"Target 4: "; cin>>r;
cout<<"When you are ready, \n";
system("pause");
printarray(num);
int qt=0, wt=0, et=0, rt=0;
while (true)
{
if (qt<q)
{
gotoxy(2,8); // move to where we want to output
cout << "q"; // overwrite the current output
}
else
{
gotoxy(2,8); // move back to the start of output
cout << " "; // this will reset the output to blank
}
if (wt<w)
{
gotoxy(56,8); // move to where we want to output
cout << "w"; // overwrite the current output
}
else
{
gotoxy(56,8); // move back to the start of output
cout << " "; // this will reset the output to blank
}
if (et<e)
{
gotoxy(2,35); // move to where we want to output
cout << "e"; // overwrite the current output
}
else
{
gotoxy(2,35); // move back to the start of output
cout << " "; // this will reset the output to blank
}
if (rt<r)
{
gotoxy(56,35); // move to where we want to output
cout << "r"; // overwrite the current output
}
else
{
gotoxy(56,35); // move back to the start of output
cout << " "; // this will reset the output to blank
}
qt+=25; if (qt>2*q) qt=0;
wt+=25; if (wt>2*w) wt=0;
et+=25; if (et>2*e) et=0;
rt+=25; if (rt>2*r) rt=0;
Sleep(25);
}cin.get();
system("pause");
return 0;
}
void printarray(char n)
{
char array[n][n];
for(int x=0, i=1; x<n; x++, i++)
{
for(int y=0; y<n; y++)
{
array[x][y]=' '; //assigning space ' ' to all elements of matrix
}
}
for(int y=0; y<n; y++)
{
for(int x=0; x<n; x++)
{
cout<<"|_"<<array[x][y]<<"_| ";
}
cout<<endl<<endl<<endl;
}
}
void gotoxy (int x, int y)
{
COORD coord; // coordinates
coord.X = x; coord.Y = y; // X and Y coordinates
SetConsoleCursorPosition(
GetStdHandle(STD_OUTPUT_HANDLE), coord); // moves to the coordinates
}
| |