Advertisement
tei123

tail

Mar 23rd, 2016
274
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.33 KB | None | 0 0
  1. #include <cstdlib>
  2. #include <iostream>
  3. #include <conio.h>
  4. #include "windows.h"
  5. #include <time.h>
  6.  
  7. using namespace std;
  8. int h, j;
  9.  
  10.  
  11. void gotoxy(int x, int y)
  12. {
  13. COORD c;
  14. c.X = x - 1;
  15. c.Y = y - 1;
  16. SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), c);
  17. }
  18.  
  19.  
  20.  
  21. int main(int argc, char *argv[])
  22. {
  23.  
  24. char men;
  25. system("CLS");
  26. cout << " Witaj w grze Wonsz \276eczny" << endl;
  27. cout << "1. Zagraj w gr\251" << endl;
  28. cout << "2. Wy\210\245cz gr\251" << endl;
  29. cout << endl;
  30. cout << endl;
  31. cout << "Instrukcja: " << endl;
  32. cout << "Jedz zielone" << endl;
  33. cout << "Nie jedz czerwonych" << endl;
  34. cout << "Nie jedz pude\210ka" << endl;
  35. men = getch();
  36. if (men == '1')
  37. cout << " ";
  38. else if (men == '2')
  39. return 0;
  40. else getch();
  41. system("cls");
  42.  
  43. HANDLE hConsole;
  44. hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
  45. int a, b;
  46. gotoxy(25, 10);
  47. cout << "Witamy w Grze o nazwie WONSZ!!!!!";
  48.  
  49. gotoxy(1, 15);//trzecia ramka
  50. cout << char(218);
  51. for (int i = 0; i<78; i++)
  52. cout << char(196);
  53. cout << char(191);
  54. for (int i = 0; i<15; i++)
  55. {
  56. gotoxy(0, i + 15);
  57. if (i == 14) cout << char(192);
  58. else cout << char(179) << endl;
  59. }
  60. gotoxy(2, 30);
  61. for (int i = 0; i<78; i++)
  62. cout << char(196);
  63. gotoxy(79, 19);
  64. for (int i = 0; i<15; i++)
  65. {
  66. gotoxy(80, i + 16);
  67. if (i == 14) cout << char(217);
  68. else cout << char(179) << endl;
  69. }
  70. int u, m;
  71. u = rand() % 80;
  72. m = rand() % 15 + 15;
  73. gotoxy(u, m);
  74. SetConsoleTextAttribute(hConsole, 2);
  75. cout << "X";
  76. SetConsoleTextAttribute(hConsole, 7);
  77.  
  78. int u1, m1;
  79. u1 = rand() % 80;
  80. m1 = rand() % 15 + 15;
  81. gotoxy(u1, m1);
  82. SetConsoleTextAttribute(hConsole, 4);
  83. cout << "X";
  84. SetConsoleTextAttribute(hConsole, 7);
  85.  
  86. int znak;
  87. int x = 20, y = 20;
  88. gotoxy(x, y);
  89. cout << "@";
  90. int key;
  91. int pkt = 1;
  92.  
  93. do
  94. {
  95.  
  96. key = getch();
  97. if (key == 224 || key == 0)
  98. {
  99. switch (getch())
  100. {
  101. case 80: y++; gotoxy(x, y); cout << "@"; //dol
  102. gotoxy(x, y - pkt); cout << " ";
  103.  
  104.  
  105. break;
  106. case 72: y--; gotoxy(x, y); cout << "@"; //gora
  107. gotoxy(x, y + pkt); cout << " ";
  108.  
  109. break;
  110. case 77: x++; gotoxy(x, y); cout << "@"; //prawo
  111. gotoxy(x - pkt, y); cout << " ";
  112.  
  113. break;
  114. case 75: x--; gotoxy(x, y); cout << "@"; //lewo
  115. gotoxy(x + pkt, y); cout << " ";
  116.  
  117.  
  118. break;
  119. }
  120. }
  121. if ((y == 15) || (y == 30) || (x == 80) || (x == 1)) {
  122. system("cls");
  123. cout << "PRZEGRANA!" << endl;
  124. cout << "Liczba uzyskanych punktow: " << pkt - 1;
  125. };
  126. if ((y == m) && (x == u))
  127. {
  128. u = rand() % 79 + 1;
  129. m = rand() % 15 + 15;
  130. gotoxy(u, m);
  131. SetConsoleTextAttribute(hConsole, 2);
  132. cout << "X";
  133. SetConsoleTextAttribute(hConsole, 7);
  134. pkt = pkt + 1;
  135.  
  136. gotoxy(u1, m1);
  137. cout << " ";
  138. u1 = rand() % 80;
  139. m1 = rand() % 15 + 15;
  140. gotoxy(u1, m1);
  141. SetConsoleTextAttribute(hConsole, 4);
  142. cout << "X";
  143. SetConsoleTextAttribute(hConsole, 7);
  144.  
  145. gotoxy(25, 12);
  146. cout << "Liczba uzyskanych punktow: " << pkt - 1;
  147. };
  148. if ((y == m1) && (x == u1))
  149. {
  150. system("cls");
  151. cout << "PRZEGRANA! Wonsz \276eczny by\210 zbyt niebezpieczny!" << endl;
  152. cout << "Liczba uzyskanych punktow: " << pkt - 1 << endl;
  153. };
  154. if (key == 27)
  155. break;
  156. /*
  157.  
  158. */
  159.  
  160. ;
  161. }
  162.  
  163. while (true);
  164.  
  165.  
  166. //system ("PAUSE")
  167. return 0;
  168. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement