-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfrut.h
44 lines (37 loc) · 910 Bytes
/
frut.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#pragma once
#include <iostream>
#include "snek.h"
namespace snekGame
{
class Frut
{
public:
std::pair<int, int> pos;
unsigned pts;
unsigned score;
void refresh(std::deque<std::pair<int, int>> body)
{
pos.first = snekGame::distrib(snekGame::gen);
pos.second = snekGame::distrib(snekGame::gen);
for (std::pair<int, int> Spos: body)
{
if (pos == Spos)
refresh(body);
}
}
void ate(snekGame::Snek &S)
{
if (S.posTail.front() == pos)
{
score += pts;
pts++;
S.posTail.push_front(S.posTail.front());
refresh(S.posTail);
}
}
void showScore()
{
std::cout << "score: " << score << "\n";
}
};
}