Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <cstdlib>
- #include <iostream>
- #include <conio.h>
- #include "windows.h"
- #include <time.h>
- using namespace std;
- int h, j;
- void gotoxy(int x, int y)
- {
- COORD c;
- c.X = x - 1;
- c.Y = y - 1;
- SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), c);
- }
- int main(int argc, char *argv[])
- {
- char men;
- system("CLS");
- cout << " Witaj w grze Wonsz \276eczny" << endl;
- cout << "1. Zagraj w gr\251" << endl;
- cout << "2. Wy\210\245cz gr\251" << endl;
- cout << endl;
- cout << endl;
- cout << "Instrukcja: " << endl;
- cout << "Jedz zielone" << endl;
- cout << "Nie jedz czerwonych" << endl;
- cout << "Nie jedz pude\210ka" << endl;
- men = getch();
- if (men == '1')
- cout << " ";
- else if (men == '2')
- return 0;
- else getch();
- system("cls");
- HANDLE hConsole;
- hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
- int a, b;
- gotoxy(25, 10);
- cout << "Witamy w Grze o nazwie WONSZ!!!!!";
- gotoxy(1, 15);//trzecia ramka
- cout << char(218);
- for (int i = 0; i<78; i++)
- cout << char(196);
- cout << char(191);
- for (int i = 0; i<15; i++)
- {
- gotoxy(0, i + 15);
- if (i == 14) cout << char(192);
- else cout << char(179) << endl;
- }
- gotoxy(2, 30);
- for (int i = 0; i<78; i++)
- cout << char(196);
- gotoxy(79, 19);
- for (int i = 0; i<15; i++)
- {
- gotoxy(80, i + 16);
- if (i == 14) cout << char(217);
- else cout << char(179) << endl;
- }
- int u, m;
- u = rand() % 80;
- m = rand() % 15 + 15;
- gotoxy(u, m);
- SetConsoleTextAttribute(hConsole, 2);
- cout << "X";
- SetConsoleTextAttribute(hConsole, 7);
- int u1, m1;
- u1 = rand() % 80;
- m1 = rand() % 15 + 15;
- gotoxy(u1, m1);
- SetConsoleTextAttribute(hConsole, 4);
- cout << "X";
- SetConsoleTextAttribute(hConsole, 7);
- int znak;
- int x = 20, y = 20;
- gotoxy(x, y);
- cout << "@";
- int key;
- int pkt = 1;
- do
- {
- key = getch();
- if (key == 224 || key == 0)
- {
- switch (getch())
- {
- case 80: y++; gotoxy(x, y); cout << "@"; //dol
- gotoxy(x, y - pkt); cout << " ";
- break;
- case 72: y--; gotoxy(x, y); cout << "@"; //gora
- gotoxy(x, y + pkt); cout << " ";
- break;
- case 77: x++; gotoxy(x, y); cout << "@"; //prawo
- gotoxy(x - pkt, y); cout << " ";
- break;
- case 75: x--; gotoxy(x, y); cout << "@"; //lewo
- gotoxy(x + pkt, y); cout << " ";
- break;
- }
- }
- if ((y == 15) || (y == 30) || (x == 80) || (x == 1)) {
- system("cls");
- cout << "PRZEGRANA!" << endl;
- cout << "Liczba uzyskanych punktow: " << pkt - 1;
- };
- if ((y == m) && (x == u))
- {
- u = rand() % 79 + 1;
- m = rand() % 15 + 15;
- gotoxy(u, m);
- SetConsoleTextAttribute(hConsole, 2);
- cout << "X";
- SetConsoleTextAttribute(hConsole, 7);
- pkt = pkt + 1;
- gotoxy(u1, m1);
- cout << " ";
- u1 = rand() % 80;
- m1 = rand() % 15 + 15;
- gotoxy(u1, m1);
- SetConsoleTextAttribute(hConsole, 4);
- cout << "X";
- SetConsoleTextAttribute(hConsole, 7);
- gotoxy(25, 12);
- cout << "Liczba uzyskanych punktow: " << pkt - 1;
- };
- if ((y == m1) && (x == u1))
- {
- system("cls");
- cout << "PRZEGRANA! Wonsz \276eczny by\210 zbyt niebezpieczny!" << endl;
- cout << "Liczba uzyskanych punktow: " << pkt - 1 << endl;
- };
- if (key == 27)
- break;
- /*
- */
- ;
- }
- while (true);
- //system ("PAUSE")
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement