Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "pch.h"
- #include <iostream>
- #include <conio.h>
- #include <stdlib.h>
- #include <time.h>
- #include <string>
- using namespace std;
- bool gameOver;
- int x, y, FruitX, FruitY, score;
- enum Prebirovka{STOP = 0, LEFT, RIGHT, UP, DOWN};
- Prebirovka zip;
- const int wight = 30;
- const int hight = 30;
- void Parametr()
- {
- gameOver = false;
- zip = STOP;
- x = wight / 2;
- y = hight / 2;
- FruitX = rand() % wight;
- FruitY = rand() % hight;
- score = 0;
- }
- void mapPrint()
- {
- system("cls");
- for (int i = 0; i < wight + 1; i++)
- cout << "*";
- cout << endl;
- for (int i = 0; i < wight; i++)
- {
- for (int j = 0; j < hight; j++)
- {
- if (j == 0 || j == wight - 1)
- cout << "*";
- if (i == x && j == y)
- cout << "0";
- else if (i == FruitX && j == FruitY)
- cout << "F";
- else
- cout << " ";
- }
- cout << endl;
- }
- for (int i = 0; i < wight + 1; i++)
- cout << "*";
- cout << endl;
- cout << "Score : " << score << endl;
- }
- void Ypravl()
- {
- if (_kbhit())
- {
- switch (_getch())
- {
- case 'a':
- zip = LEFT;
- break;
- case 'd':
- zip = RIGHT;
- break;
- case 'w':
- zip = UP;
- break;
- case 's':
- zip = DOWN;
- break;
- case 'x':
- gameOver = true;
- break;
- }
- }
- }
- void Logik()
- {
- switch (zip)
- {
- case LEFT:
- x--;
- break;
- case RIGHT:
- x++;
- break;
- case UP:
- y--;
- break;
- case DOWN:
- y++;
- break;
- }
- if (x = rand() % wight || y = rand() % hight)
- {
- gameOver = false;
- }
- else if (x > wight || x < wight || y > hight || y < hight)
- {
- gameOver = true;
- }
- if (x == FruitX && y == FruitY)
- {
- score += 5;
- FruitX = rand() % wight;
- FruitY = rand() % hight;
- }
- }
- int main()
- {
- while (!gameOver)
- {
- Parametr();
- mapPrint();
- Ypravl();
- Logik();
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement