123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899 |
- #include <iostream>
- #include <windows.h>
- #include "Const.h"
- int main()
- {
- snake_size = 3;// >0 Âêëþ÷àåò ãîëîâó + ðàçìåð õâîñòà (åñëè 1 - òî òîëüêî ãîëîâà)
- timeout = 200; //> 100 (ms), 1000 - áóäåò çàäåðæèâàòü âûïîëíåíèå ïðîãðàììû íà 1 ñåêóíäó
-
- //Var1, òîëüêî ãîëîâà çìåéêè
- char field[columns]{};
- for (int i = 0; i < columns; i++)
- {
- system("cls");//ïîëíàÿ î÷èñòêà êîíñîëè
- //ïåðåäâèãàåì çíà÷åíèå ãîëîâû
- field[i] = head_symbol;
-
- //åñëè íå âíà÷àëå, òî ÷èñòèì ïðåäûäóùèé ñèìâîë
- if (i >= 1)
- {
- field[i - 1] = field_symbol;
- }
-
- //ïå÷àòü
- for (int i = 0; i < columns; i++)
- {
- std::cout << border_symbol;
- }
- std::cout << std::endl;
- for (int i = 0; i < columns; i++)
- {
- std::cout << field[i];
- }
- std::cout << std::endl;
- for (int i = 0; i < columns; i++)
- {
- std::cout << border_symbol;
- }
- std::cout << std::endl;
- Sleep(timeout);
- }
-
- field[columns - 1] = field_symbol; //óáðàëè ãîëîâó
-
- //Var2, ãîëîâà+õâîñò çìåéêè
-
- for (int i = 0; i < columns; i++)
- {
- system("cls");//ïîëíàÿ î÷èñòêà êîíñîëè
-
- //ñòàâèì ãîëîâó
- field[i] = head_symbol;
- //åñëè íå âíà÷àëå, òî ñòàâèì õâîñò
- if (i > 0)
- {
- field[i - 1] = tail_symbol;
- }
- //âûâåëè õâîñò, ïîøëè ÷èñòèòü
- if (i >= snake_size)
- {
- field[i - snake_size] = field_symbol;
- }
- //ïå÷àòü
- for (int i = 0; i < columns; i++)
- {
- std::cout << border_symbol;
- }
- std::cout << std::endl;
- for (int i = 0; i < columns; i++)
- {
- std::cout << field[i];
- }
- std::cout << std::endl;
- for (int i = 0; i < columns; i++)
- {
- std::cout << border_symbol;
- }
- std::cout << std::endl;
- Sleep(timeout);
- }
-
- return 0;//êîä çàâåðøåíèÿ ïðèëîæåíèÿ
- }
|