MCPcopy Create free account
hub / github.com/AlexInLog/ReactivePlusPlus / move_snake

Function move_snake

src/examples/rpp/sfml/snake/snake.cpp:29–49  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

27}
28
29static SnakeBody move_snake(SnakeBody&& body, const std::tuple<Direction, size_t>& direction_and_length)
30{
31 auto head = body.back();
32
33 const auto& [direction, length] = direction_and_length;
34
35 if (length == body.size()) // no any changes
36 std::rotate(body.begin(), body.begin() + 1, body.end());
37 else
38 body.push_back(head);
39
40 head.x += direction.x;
41 head.x = wrap_coordinate(head.x, s_columns_count);
42
43 head.y += direction.y;
44 head.y = wrap_coordinate(head.y, s_rows_count);
45
46 body.back() = head;
47
48 return std::move(body);
49}
50
51static bool is_snake_eat_self(const SnakeBody& body)
52{

Callers

nothing calls this directly

Calls 4

wrap_coordinateFunction · 0.85
beginMethod · 0.45
endMethod · 0.45
push_backMethod · 0.45

Tested by

no test coverage detected