Advertisement
tei123

snakeo

Mar 16th, 2016
233
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.21 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.  
  9.  
  10.  
  11.  
  12. void gotoxy(int x, int y)
  13. {
  14. COORD c;
  15. c.X = x - 1;
  16. c.Y = y - 1;
  17. SetConsoleCursorPosition (GetStdHandle(STD_OUTPUT_HANDLE), c);
  18. }
  19.  
  20. int main(int argc, char *argv[])
  21. {
  22. int a, b;
  23. gotoxy(25,10);
  24. cout<<"Witamy w Grze o nazwie WONSZ!!!!!";
  25.  
  26. gotoxy(1,15);//trzecia ramka
  27. cout<<char(218);
  28. for(int i=0; i<78; i++)
  29. cout<<char(196);
  30. cout<<char(191);
  31. for(int i=0; i<15; i++)
  32. {
  33. gotoxy(0,i+15);
  34. if(i==14) cout<<char(192);
  35. else cout<<char(179)<<endl;
  36. }
  37. gotoxy(2,30);
  38. for(int i=0; i<78; i++)
  39. cout<<char(196);
  40. gotoxy(79,19);
  41. for(int i=0; i<15; i++)
  42. {
  43. gotoxy(80,i+16);
  44. if(i==14) cout<<char(217);
  45. else cout<<char(179)<<endl;
  46. }
  47. int u,m;
  48. u=rand()%80;
  49. m=rand()%15+15;
  50. gotoxy(u,m);
  51. cout << "X";
  52. int znak;
  53. int x=20,y=20;
  54. gotoxy(x,y);
  55. cout<<"@";
  56. int key;
  57. int pkt=1;
  58.  
  59. do
  60. {
  61.  
  62. key = getch();
  63. if (key == 224 || key ==0 )
  64. {
  65. switch (getch ())
  66. {
  67. case 80 : y++;gotoxy(x,y); cout<<"@"; //dol
  68. gotoxy(x,y-pkt); cout << " ";
  69.  
  70.  
  71. break;
  72. case 72 : y--;gotoxy(x,y); cout<<"@"; //gora
  73. gotoxy(x,y+pkt); cout << " ";
  74. break;
  75. case 77 : x++;gotoxy(x,y); cout<<"@"; //prawo
  76. gotoxy(x-pkt,y); cout << " ";
  77.  
  78. break;
  79. case 75 : x--;gotoxy(x,y); cout<<"@"; //lewo
  80. gotoxy(x+pkt,y); cout << " ";
  81.  
  82.  
  83. break;
  84. }
  85. }
  86. if ((y == 15)||(y==30)||(x==80)||(x==1)){system ("cls");
  87. cout << "PRZEGRANA!"<<endl;
  88. cout << "Liczba uzyskanych punktow: " << pkt-1;};
  89. if ((y==m)&&(x==u))
  90. {
  91. u=rand()%79+1;
  92. m=rand()%15+15;
  93. gotoxy(u,m);
  94. cout << "X";
  95. pkt=pkt+1;
  96. };
  97. if (key==27)break;
  98. /*
  99.  
  100. */
  101.  
  102. ;
  103. }
  104.  
  105. while (true);
  106.  
  107.  
  108. //system ("PAUSE")
  109. return 0;
  110. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement