Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- #include <ctime>
- #include <conio.h>
- #include <windows.h>
- using namespace std;
- struct player{
- int x,y;
- double rx,ry;
- double dx,dy;
- };
- struct ananas{
- int x,h,w;
- };
- int a_count = 10; // Кол-во ананасов
- ananas a[100]; // Кол-во ананасов
- player p;
- int bestscore=0,nowscore=0;
- int rr;
- int A1;
- char g;
- bool isAnanasHere(int x, int y){
- for(int i = 0;i < a_count;i++){
- int ax_screen = a[i].x - p.x + 20;
- if(x >= ax_screen && y >= 20 - a[i].h && x < ax_screen + a[i].w){
- //A1 = x >= ax_screen-30 && y>=20 + 20 - a[i].h && x < ax_screen + a[i].w - 40;
- return true;
- }
- }
- return false;
- }
- void print(){
- resett:
- rr++;
- COORD c = {0, 0};
- HANDLE output=GetStdHandle(STD_OUTPUT_HANDLE);
- SetConsoleCursorPosition(output,c);
- int max_h = 20; // Размер экрана по высоте
- int max_w = 50; // Размер экрана по длине
- for(int i = 0;i < max_h;i++){
- for(int j = 0;j < max_w;j++){
- if(i == 5 && j == 3){ // Солнце
- cout << " \\ | / " << endl;
- cout << " _____" << endl;
- cout << " / \\ " << endl;
- cout << " _ | | _" << endl;
- cout << " | | " << endl;
- cout << " \\_____/" << endl << endl;
- cout << " / | \\ " << endl;
- }
- int max_h = 20; // Размер экрана по высоте
- int max_w = 50; // Размер экрана по длине
- if(isAnanasHere(20, p.y) == true){
- cout<<"\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\t\tG A M E O V E R";
- cout << "\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t";
- system("pause");
- if(nowscore > bestscore){
- bestscore = nowscore;
- }
- nowscore = 0;
- p.y = -1;
- goto resett;
- }
- if(i == 2 && j == 40){
- cout << "HI " << bestscore << " " << nowscore;
- }
- if(i == p.y-1 && j == 20){ // Игрок
- cout << "&";
- }
- if(i == p.y && j == 20){ // Игрок
- cout << "&";
- }else{
- if(isAnanasHere(j, i) == true){
- cout << "x";
- }else{
- cout << " ";
- }
- }
- }
- cout << endl;
- }
- for(int i = 49;i < 50;i++){ // Создание песка
- int r = rand()%6;
- switch(r){
- case 0:
- cout << ".";
- break;
- case 1:
- cout << "_";
- break;
- case 2:
- cout << "_";
- break;
- case 3:
- cout << "_";
- break;
- case 4:
- cout << "-";
- break;
- case 5:
- cout << "-";
- break;
- }
- }
- }
- int main(){
- reset:
- srand(time(NULL));
- p.rx = 0;
- p.ry = 19;
- p.x = (int)p.rx;
- p.y = (int)p.ry;
- for(int q = 0;q < 10;q++){
- a[q].x = 50 + rand()%400; // расстояние до ананасов
- a[q].h = 1 + rand()%3;// высота ананасов
- a[q].w = 1 + rand()%3;// ширина ананасов
- }
- for(;;){
- p.x = (int)p.rx;
- p.y = (int)p.ry;
- p.ry = p.ry - p.dy;
- p.dy -= 0.3;
- if(p.ry > 19){
- p.ry = 19;
- }
- print();
- Sleep(1);
- p.rx++;
- nowscore++;
- if(isAnanasHere(20, p.y) != true){
- if(_kbhit()){
- g = getch();
- switch(g){
- case 13:
- if(nowscore > bestscore){
- bestscore = nowscore;
- }
- nowscore = 0;
- goto reset;
- break;
- case 32:
- if(p.y == 19){
- p.dy = 1.6;
- }
- break;
- }
- }
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement