Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <conio.h>
- #include <Windows.h>
- #include <iostream>
- using namespace std;
- const int rechts = 'd';
- const int links = 'a';
- const int hoch = 'w';
- const int runter = 's';
- const int prechts = 0x4d; //Hexadezimale codes der Pfeiltasten
- const int plinks = 0x4b;
- const int phoch = 0x48;
- const int prunter = 0x50;
- void Bewegung(int, int);
- int main()
- {
- bool ende = false;
- int x = 12; //x Koordniate (erste Definition = Startpunkt)
- int y = 10; //y Koordniate (erste Definition = Startpunkt)
- int richtung = 1;
- int punkt = 0;
- cout << "Punkte " << punkte << endl;
- cout <<"XXXXXXXXXXXXXXXXXXXXXXXXX"<<endl;
- for(int i = 1; i < 24; i++)
- {
- cout << "X X"<<endl;
- }
- cout <<"XXXXXXXXXXXXXXXXXXXXXXXXX"<<endl;
- do
- {
- Bewegung(x, y);
- cout << "o";
- if(kbhit())
- {
- int taste = getch();
- if(!taste || taste == 0xe0))
- taste = getch();
- if(taste == hoch && richtung != 2 || taste == phoch && richtung != 2)
- {
- richtung = 1;
- --y;
- }
- else if(taste == runter && richtung != 1 || taste == prunter && richtung != 1)
- {
- richtung = 2;
- ++y;
- }
- else if(taste == rechts && richtung != 4 || taste == prechts && richtung != 4)
- {
- richtung = 3;
- ++x;
- }
- else if(taste == links && richtung != 3 || taste == plinks && richtung != 3)
- else
- {
- continue;
- }
- Sleep(150);
- }
- else if(!kbhit())
- {
- if(richtung == 1)
- {
- --y;
- }
- if(richtung == 2)
- {
- ++y;
- }
- if(richtung == 3)
- {
- ++x;
- }
- if(richtung == 4)
- {
- --x;
- }
- Sleep(150);
- }
- system("cls");
- if( x <= 0 || x >= 24 || x <= 1 || y >= 25)
- {
- cout << "Game Over!" << endl << endl;
- cout << "Du hast " << punkte << " Punkte erreicht" << endl << endl;
- system("pause");
- return 0;
- }
- cout << "Punkte " << punkte << endl;
- cout <<"XXXXXXXXXXXXXXXXXXXXXXXXX"<<endl;
- for(int i = 1; i < 24; i++)
- {
- cout << "X X"<<endl;
- }
- cout <<"XXXXXXXXXXXXXXXXXXXXXXXXX"<<endl;
- }while(true);
- return 0;
- }
- void Bewegung(int b, int h)
- {
- COORD punkt;
- punkt.X = b;
- punkt.Y = h;
- SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), punkt);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement