Advertisement
Guest User

Untitled

a guest
Jul 3rd, 2014
393
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.08 KB | None | 0 0
  1.  
  2. #include <conio.h>
  3. #include <Windows.h>
  4. #include <iostream>
  5.  
  6. using namespace std;
  7.  
  8. const int rechts = 'd';
  9. const int links = 'a';
  10. const int hoch = 'w';
  11. const int runter = 's';
  12. const int prechts = 0x4d;         //Hexadezimale codes der Pfeiltasten
  13. const int plinks = 0x4b;
  14. const int phoch = 0x48;
  15. const int prunter = 0x50;
  16.  
  17. void Bewegung(int, int);
  18.  
  19. int main()
  20. {
  21. bool ende = false;
  22. int x = 12;                      //x Koordniate (erste Definition = Startpunkt)
  23. int y = 10;                      //y Koordniate (erste Definition = Startpunkt)
  24. int richtung = 1;
  25. int punkt = 0;
  26.  
  27. cout << "Punkte " << punkte << endl;
  28. cout <<"XXXXXXXXXXXXXXXXXXXXXXXXX"<<endl;
  29. for(int i = 1; i < 24; i++)
  30. {
  31. cout << "X                      X"<<endl;
  32. }
  33. cout <<"XXXXXXXXXXXXXXXXXXXXXXXXX"<<endl;
  34.  
  35. do
  36. {
  37. Bewegung(x, y);
  38. cout << "o";
  39.  
  40. if(kbhit())
  41. {
  42. int taste = getch();
  43. if(!taste || taste == 0xe0))
  44. taste = getch();
  45.  
  46. if(taste == hoch && richtung != 2 || taste == phoch && richtung != 2)
  47. {
  48. richtung = 1;
  49. --y;
  50. }
  51.  
  52. else if(taste == runter && richtung != 1 || taste == prunter && richtung != 1)
  53. {
  54. richtung = 2;
  55. ++y;
  56. }
  57.  
  58. else if(taste == rechts && richtung != 4 || taste == prechts && richtung != 4)
  59. {
  60. richtung = 3;
  61. ++x;
  62. }
  63.  
  64. else if(taste == links && richtung != 3 || taste == plinks && richtung != 3)
  65.  
  66. else
  67. {
  68. continue;
  69. }
  70.  
  71. Sleep(150);
  72. }
  73.  
  74. else if(!kbhit())
  75. {
  76. if(richtung == 1)
  77. {
  78. --y;
  79. }
  80. if(richtung == 2)
  81. {
  82. ++y;
  83. }
  84. if(richtung == 3)
  85. {
  86. ++x;
  87. }
  88. if(richtung == 4)
  89. {
  90. --x;
  91. }
  92. Sleep(150);
  93. }
  94.  
  95. system("cls");
  96.  
  97. if( x <= 0 || x >= 24 || x <= 1 || y >= 25)
  98. {
  99. cout << "Game Over!" << endl << endl;
  100. cout << "Du hast " << punkte << " Punkte erreicht" << endl << endl;
  101. system("pause");
  102. return 0;
  103. }
  104.  
  105. cout << "Punkte " << punkte << endl;
  106. cout <<"XXXXXXXXXXXXXXXXXXXXXXXXX"<<endl;
  107. for(int i = 1; i < 24; i++)
  108. {
  109. cout << "X                      X"<<endl;
  110. }
  111. cout <<"XXXXXXXXXXXXXXXXXXXXXXXXX"<<endl;
  112.  
  113. }while(true);
  114.  
  115.  
  116. return 0;
  117. }
  118.  
  119. void Bewegung(int b, int h)
  120. {
  121. COORD punkt;
  122. punkt.X = b;
  123. punkt.Y = h;
  124. SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), punkt);
  125. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement