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 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135
|
#include<iostream>
#include<cstdlib>
#include<ctime>
#include<conio.h>
using namespace std;
void timers(clock_t &t1, clock_t &t2, clock_t &t3, int wait)
{
t1=t2=clock();//ready clocks 1 and 2 for this cycle comparison.
while((t1-t2)+(t2-t3)<wait)//Wait for a 1000 milliseconds
{
t1=clock();
}//update clock one, and retest!
t3=t1;//ready clock 3 for next cycle comparison.
}
int main()
{
srand(time(0));
const int pillar_length = 10;
const int gap = 13;
const int space = 10;
const int jump = 10;
char maze[45][90];
for (int i = 0; i < 45; i++)
{
for (int j = 0; j < 89; j++)
{
maze[i][j] = ' ';
}
maze[i][89] = '\0';
}
int height[30][2];
int n = 0;
int up = 22;
int increase = -1;
int previous;
maze[up][0] = 'o';
bool game_over = false;
int score = 0;
clock_t t1,//The game clock - main timer.
t2,//Temporary timer - holds the time prior to attempting wait.
t3;//Temporary timer - holds the time prior to before attempting procedures.
t1=t2=t3=clock();//Starting clocks!
for (int i = 0; i > -1 && game_over == false; i++)
{
timers(t1,t2,t3,500);//Call with argument: t1,t2,t3, and wait timer - in milliseconds.
system("cls");
cout << "Score:\t" << score << endl;
for (int j = 0; j < 45; j++)
{
cout << maze[j] << endl;
}
for (int j = 0; j < n; j++)
{
height[j][1]--;
}
if (height[0][1] == -1 - pillar_length)
{
for (int j = 0; j < n - 1; j++)
{
height[j][0] = height[j + 1][0];
height[j][1] = height[j + 1][1];
}
n--;
score++;
}
if (height[n - 1][1] + pillar_length + space == 88 || n == 0)
{
height[n][0] = rand() % 20 + 5;
height[n][1] = 88;
n++;
}
for (int j = 0; j < n; j++)
{
//create colum
if (height[j][1] >= 0)
{
for (int k = 44; k>44 - height[j][0]; k--)
{
maze[k][height[j][1]] = '*';
}
//
for (int k = 0; k<45 - height[j][0] - gap; k++)
{
maze[k][height[j][1]] = '*';
}
}
//destroy colum
if (height[j][1] <= 88 - pillar_length)
{
for (int k = 44; k>44 - height[j][0]; k--)
{
maze[k][height[j][1] + pillar_length] = ' ';
}
//
for (int k = 0; k<45 - height[j][0] - gap; k++)
{
maze[k][height[j][1] + pillar_length] = ' ';
}
}
}
if (_kbhit())
{
if (_getch() == ' ')
{
increase = i + jump;
}
}
previous = up;
if (i < increase)
{
up--;
}
else
{
up++;
}
if (up == 45 || up == -1 || maze[up][0] == '*')
{
game_over = true;
}
else
{
if (maze[previous][0] != '*')
{
maze[previous][0] = ' ';
}
maze[up][0] = 'o';
}
}
cout << endl << "Game Over" << endl;
system("pause");
return 0;
}
|