123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183 |
- #include <iostream>
- #include <windows.h>
- #include <conio.h>
- #include "Const.h"
- #include "Game.h"
- #include "Snake.h"
- #include "Field.h"
- int main()
- {
- snake_size = 5;// >0 Âêëþ÷àåò ãîëîâó + ðàçìåð õâîñòà (åñëè 1 - òî òîëüêî ãîëîâà)
- //timeout = 200; //> 100 (ms), 1000 - áóäåò çàäåðæèâàòü âûïîëíåíèå ïðîãðàììû íà 1 ñåêóíäó
-
- //Çàïîëíåíèå ìàññèâà êîîðäèíàò èíäåêñàìè îò 1 äî L; snake_x[0] = 1
- // snake_x[L-1] - íà÷àëî õâîñòà
- // snake_x[L-snake_size] - ïîëå, ãäå íàõîäèòñÿ ïóñòîé ñèìâîë
- for (int i = 0; i < L; i++)
- {
- snake_x[i] = i+1;
- }
-
- //Çàäàíèå ðàíäîìíîãî íà÷àëüíîãî ïîëîæåíèÿ ãîëîâû çìåéêè
- srand(time(0));
- int step = rand() % L + 1;
- //step = 13;
- //snake_x[0] = 13;
- for (int i = 0; i < step-1; i++)
- {
- int tmp = snake_x[0];
- for (int j = 0; j< L - 1; j++)
- {
- snake_x[j] = snake_x[j + 1];
- }
- snake_x[L - 1] = tmp;
- }
- field[0]= field[columns -1]= '*';//óñòàíîâêà ãðàíèö
- field[snake_x[0]] = head_symbol;//óñòààíîâêà ãîëîâû
- // óñòàíîâêà õâîñòà, åñëè åñòü
- for (int i = 1; i < snake_size; i++)
- {
- field[snake_x[L - i]] = tail_symbol;
- }
- stop
- 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;
- std::cout << "Press control key" << std::endl;//5) Âûâîä ïðèãëàøåíèÿ ê èãðå.
-
- //char key = _getch();
- //Var1, òîëüêî ãîëîâà çìåéêè
-
- while(false)//
- {
- system("cls");//ïîëíàÿ î÷èñòêà êîíñîëè
- //ñìåùàåì ïîëîæåíèå ãîëîâû çìåéêè
- int tmp = snake_x[0];
-
- for (int j = 0; j < L - 1; j++)
- {
- snake_x[j] = snake_x[j + 1];
- }
-
- snake_x[L - 1] = tmp;
-
- //óñòàíàâëèâàåì ïîëîæåíèå ãîëîâû
- field[snake_x[0]] = head_symbol;
-
- //÷èñòèì "õâîñò"
- field[snake_x[L - 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);
-
- }
-
- //Var2, ãîëîâà+õâîñò çìåéêè
-
- while (true)
- {
- system("cls");//ïîëíàÿ î÷èñòêà êîíñîëè
- //ñìåùàåì ïîëîæåíèå ãîëîâû çìåéêè
- int tmp = snake_x[0];
- for (int j = 0; j < L - 1; j++)
- {
- snake_x[j] = snake_x[j + 1];
- }
- snake_x[L - 1] = tmp;
- //óñòàíàâëèâàåì ïîëîæåíèå ãîëîâû
- field[snake_x[0]] = head_symbol;
- //÷èñòèì "õâîñò"
- field[snake_x[L - snake_size]] = field_symbol;
- if (snake_size > 1)
- {
- //ñèìâîë õâîñòà âìåñòî ãîëîâû
- field[snake_x[L - 1]] = tail_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;//êîä çàâåðøåíèÿ ïðèëîæåíèÿ
- }
|