Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <WINDOWS.H>
- #include <ctime>
- int main()
- {
- unsigned seed = time(nullptr);
- srand(seed);
- const int WID = 20;
- const int HIG = 10;
- char width[WID];
- int posx = WID / 2;
- int posy = HIG - 1;
- int obx = rand() % WID;
- int oby = 2;
- int score = 0;
- bool done = false;
- while (!done)
- {
- system("cls");
- std::cout << "SCORE: " << score << std::endl;
- //MAP BOUNDRIES
- if (posx > WID - 1)
- {
- posx = 0; //leftmost position
- }
- else if (posx < 0)
- {
- posx = WID - 1; //rightmost position
- }
- if (oby > HIG)
- {
- oby = 0;
- obx = rand() % WID;
- }
- //DRAW
- for (int k = 0; k < HIG; k++)
- {
- for (int i = 0; i < WID; i++)
- {
- if (k == posy && i == posx)
- {
- width[i] = 'O'; //player
- }
- else if (k == oby && i == obx)
- {
- width[i] = 'X'; //object
- }
- else
- {
- width[i] = '_'; //background
- }
- std::cout << width[i];
- }
- std::cout <<std:: endl;
- }
- //CONTROLS
- if (GetKeyState('A') < 0)
- {
- posx -= 1;
- Sleep(5);
- }
- else if (GetKeyState('D') < 0)
- {
- posx += 1;
- Sleep(5);
- }
- else if (GetKeyState('Q') < 0)
- {
- done = true;
- }
- //OBJECT MOVE
- oby++;
- //SCORE
- if (obx == posx && oby == posy)
- {
- score++;
- }
- Sleep(50);
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement