Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <windows.h>
- #include <conio.h>
- using namespace std;
- bool gameOver = false;
- bool pojeo = true;
- char smijer;
- int x = 15;
- int y = 10;
- int hranaX = 1;
- int hranaY = 1;
- int prevX = 1;
- int prevY = 1;
- int d = 1;
- int rep[150];
- int repX = 1;
- int repY = 1;
- ///////////////////////
- void gotoxy(int x, int y);
- void run();
- void odredismijer(char c);
- void kretanje();
- void lik();
- void kreiranjehrane();
- void prikazhrane();
- //////////////////////
- int main()
- {
- while(!gameOver)
- {
- system("CLS");
- run();
- Sleep(5);
- }
- return 0;
- }
- void run()
- {
- if(kbhit())
- {
- odredismijer(getch());
- }
- kretanje();
- lik();
- if(x == hranaX && y == hranaY)
- {
- d++;
- pojeo = true;
- }
- if(pojeo)
- {
- kreiranjehrane();
- pojeo = false;
- }
- if(!pojeo)
- {
- prikazhrane();
- }
- }
- void odredismijer(char c)
- {
- switch(c)
- {
- case 'a':
- smijer = 'a';
- break;
- case 's':
- smijer = 's';
- break;
- case 'd':
- smijer = 'd';
- break;
- case 'w':
- smijer = 'w';
- break;
- }
- }
- void kretanje()
- {
- switch(smijer)
- {
- case 'w':
- y--;
- break;
- case 'a':
- x--;
- break;
- case 's':
- y++;
- break;
- case 'd':
- x++;
- break;
- }
- }
- void lik()
- {
- gotoxy(x,y);
- cout<<"O";
- }
- void kreiranjehrane()
- {
- hranaX = rand() % 30 + 5;
- hranaY = rand() % 20 + 5;
- gotoxy(hranaX,hranaY);
- cout<<"Q";
- }
- void prikazhrane()
- {
- gotoxy(hranaX,hranaY);
- cout<<"Q";
- }
- void gotoxy(int x, int y)
- {
- COORD c;
- c.X = x;
- c.Y = y;
- SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE),c);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement