Ex_2.cpp 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. #include <iostream>
  2. #include <windows.h>
  3. #include "Const.h"
  4. int main()
  5. {
  6. snake_size = 3;// >0 Âêëþ÷àåò ãîëîâó + ðàçìåð õâîñòà (åñëè 1 - òî òîëüêî ãîëîâà)
  7. timeout = 200; //> 100 (ms), 1000 - áóäåò çàäåðæèâàòü âûïîëíåíèå ïðîãðàììû íà 1 ñåêóíäó
  8. //Var1, òîëüêî ãîëîâà çìåéêè
  9. char field[columns]{};
  10. for (int i = 0; i < columns; i++)
  11. {
  12. system("cls");//ïîëíàÿ î÷èñòêà êîíñîëè
  13. //ïåðåäâèãàåì çíà÷åíèå ãîëîâû
  14. field[i] = head_symbol;
  15. //åñëè íå âíà÷àëå, òî ÷èñòèì ïðåäûäóùèé ñèìâîë
  16. if (i >= 1)
  17. {
  18. field[i - 1] = field_symbol;
  19. }
  20. //ïå÷àòü
  21. for (int i = 0; i < columns; i++)
  22. {
  23. std::cout << border_symbol;
  24. }
  25. std::cout << std::endl;
  26. for (int i = 0; i < columns; i++)
  27. {
  28. std::cout << field[i];
  29. }
  30. std::cout << std::endl;
  31. for (int i = 0; i < columns; i++)
  32. {
  33. std::cout << border_symbol;
  34. }
  35. std::cout << std::endl;
  36. Sleep(timeout);
  37. }
  38. field[columns - 1] = field_symbol; //óáðàëè ãîëîâó
  39. //Var2, ãîëîâà+õâîñò çìåéêè
  40. for (int i = 0; i < columns; i++)
  41. {
  42. system("cls");//ïîëíàÿ î÷èñòêà êîíñîëè
  43. //ñòàâèì ãîëîâó
  44. field[i] = head_symbol;
  45. //åñëè íå âíà÷àëå, òî ñòàâèì õâîñò
  46. if (i > 0)
  47. {
  48. field[i - 1] = tail_symbol;
  49. }
  50. //âûâåëè õâîñò, ïîøëè ÷èñòèòü
  51. if (i >= snake_size)
  52. {
  53. field[i - snake_size] = field_symbol;
  54. }
  55. //ïå÷àòü
  56. for (int i = 0; i < columns; i++)
  57. {
  58. std::cout << border_symbol;
  59. }
  60. std::cout << std::endl;
  61. for (int i = 0; i < columns; i++)
  62. {
  63. std::cout << field[i];
  64. }
  65. std::cout << std::endl;
  66. for (int i = 0; i < columns; i++)
  67. {
  68. std::cout << border_symbol;
  69. }
  70. std::cout << std::endl;
  71. Sleep(timeout);
  72. }
  73. return 0;//êîä çàâåðøåíèÿ ïðèëîæåíèÿ
  74. }