1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950 |
- #include <iostream>
- #include "Const.h"
- //Óñòàíàâëèâàåòñÿ ïîëüçîâàòåëüñêèé ðàçìåð çìåéêè, ìàññèâ çìåéêè çàïîëíÿåòñÿ ñòàðòîâûìè çíà÷åíèÿìè
- void init_snake(Snake& snake)
- {
- std::cout << "Enter snake_size > 0. Snake_size must be <" << L << std::endl;
- std::cin >> snake.snake_size;
- if (snake.snake_size <= 0 || snake.snake_size > L)//Ïðîâåðêà íà äîïóñòèìûé ðàçìåð çíà÷åíèÿ.
- {
- std::cout << "Err! Wrong size " << std::endl;
- exit(1);
- }
-
- for (int i = 1; i < snake.snake_size; i++)
- {
- snake.snake_x[i] = snake.snake_x[0] - i;
- if (snake.snake_x[i] <= 0)
- {
- snake.snake_x[i] = 1;
- }
- snake.snake_y[i] = snake.snake_y[0];
- }
- }
- // Ïåðåäâèãàþòñÿ ýëåìåíòû çìåéêè.
- void move_snake(Snake& snake)
- {
-
- for (int i = snake.snake_size - 1; i > 0; i--)// ñäâèã õâîñòà
- {
- snake.snake_x[i] = snake.snake_x[i - 1];
- snake.snake_y[i] = snake.snake_y[i - 1];
- }
- switch (snake.direction)//óñòàíîâêà çíà÷åíèÿ ãîëîâû
- {
- case turn_left: {snake.snake_x[0]--;}break;
- case turn_right: {snake.snake_x[0]++;}break;
- case turn_up: {snake.snake_y[0]--;}break;
- case turn_down: {snake.snake_y[0]++;}break;
- default: break;
- }
- }
|