-
Notifications
You must be signed in to change notification settings - Fork 0
/
ShapeManager.cpp
120 lines (99 loc) · 2.03 KB
/
ShapeManager.cpp
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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
#include "ShapeManager.h"
#include "Rectangle.h"
#include "ShapeGun.h"
#include "ShapeRGun.h"
#include "ShapeLine.h"
#include "ShapeT.h"
#include "ShapeS.h"
#include "ShapeZ.h"
#include "Shape.h"
#include "StageManager.h"
#include "Stage.h"
CShapeManager* CShapeManager::m_pInst = nullptr;
CShapeManager::CShapeManager() :
m_pCurShape(nullptr),
m_pNextShape(nullptr)
{
m_pCurShape = CreateRandomShape();
m_pNextShape = CreateRandomShape();
m_iSpeed = 0;
}
CShapeManager::~CShapeManager()
{
SAFE_DELETE(m_pCurShape);
SAFE_DELETE(m_pNextShape);
}
void CShapeManager::Update()
{
CStage* pStage = CStageManager::GetInst()->GetCurrentStage();
++m_iSpeed;
if (pStage->GetSpeed() == m_iSpeed)
{
if (m_pCurShape->MoveDown())
{
pStage->AddBlock(m_pCurShape, m_pCurShape->GetPosition());
SAFE_DELETE(m_pCurShape);
m_pCurShape = m_pNextShape;
m_pCurShape->SetPosition(4, 0);
m_pNextShape = CreateRandomShape();
}
m_iSpeed = 0;
}
if (GetAsyncKeyState('A') & 0x8000)
{
m_pCurShape->MoveLeft();
}
if (GetAsyncKeyState('D') & 0x8000)
{
m_pCurShape->MoveRight();
}
if (GetAsyncKeyState('W') & 0x8000)
{
m_pCurShape->Rotation();
}
}
void CShapeManager::Render()
{
m_pCurShape->Render();
m_pNextShape->SetPosition(13, 3);
m_pNextShape->RenderNext();
}
CShape * CShapeManager::CreateRandomShape()
{
int iType = rand() % ST_END;
return CreateShape((SHAPE_TYPE)iType);
}
CShape * CShapeManager::CreateShape(SHAPE_TYPE eType)
{
CShape* pShape = nullptr;
switch (eType)
{
case ST_RECT:
pShape = new CRectangle;
break;
case ST_GUN:
pShape = new CShapeGun;
break;
case ST_RGUN:
pShape = new CShapeRGun;
break;
case ST_LINE:
pShape = new CShapeLine;
break;
case ST_T:
pShape = new CShapeT;
break;
case ST_S:
pShape = new CShapeS;
break;
case ST_Z:
pShape = new CShapeZ;
break;
}
if (!pShape->Init())
{
SAFE_DELETE(pShape);
return nullptr;
}
return pShape;
}