-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathItemBox.h
More file actions
99 lines (83 loc) · 2.34 KB
/
ItemBox.h
File metadata and controls
99 lines (83 loc) · 2.34 KB
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
#ifndef ITEMBOX_H
#define ITEMBOX_H
#include "FallingObject.h"
#include <cmath>
#include <string>
// ItemBox: 아이템 박스
class ItemBox : public FallingObject
{
public:
enum class ItemType
{
TIME_BONUS, // 시간 +10초
TIME_MINUS, // 시간 -10초
SCORE_BOOST // 점수 2배
};
private:
ItemType itemType;
double fallAccumulator;
public:
ItemBox(int areaWidth, int areaHeight, double speed = 0.8)
: FallingObject(areaWidth, areaHeight, speed), fallAccumulator(0.0)
{
// 랜덤 아이템 타입 결정
itemType = static_cast<ItemType>(rand() % 3);
// 랜덤 x 위치 (아이템 박스는 3칸 폭: [?])
x = rand() % (gameAreaWidth - 4) + 1;
initialX = x;
}
// 낙하 (바닥 도달 시 페널티 없음)
void fall() override
{
if (!isActive)
return;
// 낙하 속도가 1보다 작을 때도 움직이도록 누적 이동량을 반영
fallAccumulator += fallSpeed;
int step = static_cast<int>(std::floor(fallAccumulator));
if (step <= 0)
{
return;
}
y += step;
fallAccumulator -= step;
// 바닥에 도달하면 그냥 사라짐 (페널티 없음)
if (y >= gameAreaHeight - 3)
{
isActive = false; // 비활성화
y = gameAreaHeight - 3;
// hasReachedBottom은 설정하지 않음 → 페널티 적용 안됨
}
}
// 화면에 그리기
void draw() const override
{
if (!isActive)
return;
// ncurses로 그리기 (PlayScreen에서 호출)
// mvprintw(y, x, "[%c]", displayChar);
}
// 랜덤 효과 적용 (GameManager와 연동)
ItemType applyRandomEffect()
{
isActive = false; // 획득 시 비활성화
return itemType;
}
// Getter
ItemType getItemType() const { return itemType; }
// 아이템 효과 설명 문자열
std::string getEffectDescription() const
{
switch (itemType)
{
case ItemType::TIME_BONUS:
return "Time +10 sec";
case ItemType::TIME_MINUS:
return "Time -10 sec";
case ItemType::SCORE_BOOST:
return "Score x2";
default:
return "Unknown";
}
}
};
#endif // ITEMBOX_H