1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071 |
- #include <iostream>
- #include <windows.h>
- #include <conio.h>
- #include "Const.h"
- #include "Game.h"
- #include "Snake.h"
- #include "Field.h"
- #include "winconsole.h"
- int main()
- {
- char field[rows][columns]{}; //Ìàññèâ èãðîâîãî ïîëÿ
- int snake_x_main[L]{ 0 };//Ìàññèâ êîîðäèíàò çìåéêè ïî ãîðèçîíòàëè(X)
- int snake_y_main[Y]{ 0 };//Ìàññèâ êîîðäèíàò çìåéêè ïî âåðòèêàëè(Y)
- int snake_size = 1; //Òåêóùèé ðàçìåð çìåéêè; >0 Âêëþ÷àåò ãîëîâó + ðàçìåð õâîñòà (åñëè 1 - òî òîëüêî ãîëîâà)
- int timeout = 200; //Òàéìàóò çàäåðæêè ìåæäó øàãàìè èãðû; > 100 (ms), 1000 - áóäåò çàäåðæèâàòü âûïîëíåíèå ïðîãðàììû íà 1 ñåêóíäó
- int game_on = 1;//Ïðèçíàê ïðîäîëæåíèÿ èãðû
- DIRECTION direction = turn_right;//íàïðàâëåíèå äâèæåíèÿ
- int score = 0;
- init_game(field, snake_x_main, snake_y_main, direction, snake_size, timeout, game_on, score);
-
- _getch(); // îæèäàíèå îòêëèêà èãðîêà
- system("cls");//ïîëíàÿ î÷èñòêà êîíñîëè
-
- bool food_flag = false;//Ïðèçíàê, ÷òî åäà óñòàíîâëåíà
- int food_x;//Êîîðäèíàòà åäû ïî ãîðèçîíòàëè (X)
- int food_y;//Êîîðäèíàòà åäû ïî âåðòèêàëè (Y)
-
- #define Auto
- //#define Hand
-
- while (game_on)
- {
- setCursorPosition(0, 0);
- //system("cls");//ïîëíàÿ î÷èñòêà êîíñîëè
- #if defined Auto
- if (_kbhit())
- {
- handle_cmd(direction, game_on);
- }
- //else { continue; }
- #elif defined Hand
- handle_cmd(direction, game_on);
- #else
- std::cout << "Select mode!" << std::endl;
- #endif
- clear_snake(field, snake_x_main, snake_y_main, snake_size);//÷èñòèì "õâîñò"
- set_food(field, snake_size, food_flag, food_x, food_y);//óñòàíàâëèâàåòñÿ åäà
-
- move_snake(snake_x_main, snake_y_main, snake_size, direction);//ñìåùàåì ïîëîæåíèå ãîëîâû çìåéêè
- check_eating(field, snake_x_main, snake_y_main, snake_size, food_flag, score);//Âûïîëíÿåòñÿ ïðîâåðêà òîãî, ÷òî çìåéêà ñúåëà åäó.
-
- set_snake(field, snake_x_main, snake_y_main, snake_size);//Çìåéêà óñòàíàâëèâàåòñÿ â èãðîâîì ïîëå
- print_field(field, score);//ïå÷àòü
-
- game_on = check_game(field, snake_x_main, snake_y_main, snake_size, food_flag, game_on);//ïðîâåðêà íà êîíåö èãðû
-
- Sleep(timeout);//îæèäàíèå
- }
- game_over(field, snake_x_main, snake_y_main, score);
-
- return 0;//êîä çàâåðøåíèÿ ïðèëîæåíèÿ
- }
|