-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCandy.cpp
168 lines (141 loc) · 3.06 KB
/
Candy.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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
#ifndef BASIC_LIB
#define BASIC_LIB
#include <SDL.h>
#include <SDL_image.h>
#include <string>
#include <stdlib.h>
#include <stdio.h>
#include <iostream>
#include <algorithm>
#endif // BASIC_LIB
#include "Candy.h"
#include "Headers.h"
int Candy::CandyWidth = 69;
int Candy::CandyHeight = 69;
Candy::Candy()
{
type = EMPTY;
// just to get the default width and height, doesn't matter if it's blue candy or not
mTexture = &mCandyTexture[type];
mWidth = mTexture->getWidth();
mHeight = mTexture->getWidth();
mX = 0;
mY = 0;
mIndex = 0;
is2ndWrapped = false;
}
Candy::~Candy()
{
empty();
}
void Candy::empty()
{
setBreed(EMPTY);
}
bool Candy::equal(Candy* other)
{
// 4 is the number of type of candy of 1 color
// -1 because the first one is EMPTY
if(this->getBreed() == COLOUR_BOMB || this->getBreed() == EMPTY || other->getBreed() == COLOUR_BOMB || other->getBreed() == EMPTY)
return false;
int cur_type = this->getBreed() / 4;
int other_type = other->getBreed() / 4;
//printf("%d %d- %d %d cur_type : %d other_type : %d\n", mX, mY, other->getX(), other->getY(), cur_type, other_type);
return (other_type == cur_type);
}
void Candy::render(SDL_Renderer* lRenderer)
{
mTexture->render(lRenderer, mX, mY);
}
void Candy::render(SDL_Renderer* lRenderer, int lX, int lY)
{
mTexture->render(lRenderer, lX, lY);
}
Texture* Candy::getTexture()
{
return mTexture;
}
CandyBreed Candy::getBreed()
{
return type;
}
CandyType Candy::getType()
{
if(type == EMPTY || type == COLOUR_BOMB)
return NORMAL;
int ret = (int) type;
ret = ret - (ret / 4) * 4;
return (CandyType) ret;
}
void Candy::swap(Candy* other)
{
CandyBreed tmp_breed = this->getBreed();
this->setBreed(other->getBreed());
other->setBreed(tmp_breed);
bool tmp_is2ndWrapped = this->isUnwrapped();
this->is2ndWrapped = other->isUnwrapped();
if(tmp_is2ndWrapped == true)
other->makeUnwrapped();
else
other->makeNotUnwrapped();
}
void Candy::turnIntoNormal()
{
if(type == EMPTY || type == COLOUR_BOMB)
return;
// turn into normal
CandyBreed tmp_breed = (CandyBreed) ((int) type - (int) getType());
setBreed(tmp_breed);
}
void Candy::setInfo(CandyBreed lType, int lX, int lY)
{
setBreed(lType);
mX = lX;
mY = lY;
}
void Candy::setBreed(CandyBreed lCandyBreed)
{
type = lCandyBreed;
mTexture = &mCandyTexture[type];
return;
}
int Candy::getWidth()
{
return mWidth;
}
int Candy::getHeight()
{
return mHeight;
}
int Candy::getX()
{
return mX;
}
int Candy::getY()
{
return mY;
}
void Candy::setX(int x)
{
mX = x;
}
void Candy::setY(int y)
{
mY = y;
}
int Candy::getIndex()
{
return mIndex;
}
bool Candy::isUnwrapped()
{
return is2ndWrapped;
}
void Candy::makeUnwrapped()
{
is2ndWrapped = true;
}
void Candy::makeNotUnwrapped()
{
is2ndWrapped = false;
}