|
|
@ -1,5 +1,7 @@ |
|
|
|
#define OLC_PGE_APPLICATION |
|
|
|
#define OLC_PGE_APPLICATION |
|
|
|
#include "olcPixelGameEngine.h" |
|
|
|
#include "olcPixelGameEngine.h" |
|
|
|
|
|
|
|
#define OLC_PGEX_QUICKGUI |
|
|
|
|
|
|
|
#include "olcPGEX_QuickGUI.h" |
|
|
|
|
|
|
|
|
|
|
|
using namespace olc; |
|
|
|
using namespace olc; |
|
|
|
|
|
|
|
|
|
|
@ -33,14 +35,40 @@ class CardGameRef : public olc::PixelGameEngine |
|
|
|
DRAWFOUR, |
|
|
|
DRAWFOUR, |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
enum GameState{ |
|
|
|
|
|
|
|
AIPICK, |
|
|
|
|
|
|
|
DRAW, |
|
|
|
|
|
|
|
PICK, |
|
|
|
|
|
|
|
RESULT, |
|
|
|
|
|
|
|
VICTORY |
|
|
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
struct Rect{ |
|
|
|
struct Rect{ |
|
|
|
vf2d pos; |
|
|
|
vf2d pos; |
|
|
|
vf2d size; |
|
|
|
vf2d size; |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
struct Card{ |
|
|
|
|
|
|
|
Color col; |
|
|
|
|
|
|
|
CardValue val; |
|
|
|
|
|
|
|
bool faceDown=false; |
|
|
|
|
|
|
|
Card(Color col,CardValue val,bool faceDown=false) |
|
|
|
|
|
|
|
:col(col),val(val),faceDown(faceDown){} |
|
|
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
typedef std::vector<Card> Hand; |
|
|
|
|
|
|
|
typedef std::vector<Card> CardPile; |
|
|
|
|
|
|
|
|
|
|
|
std::vector<Decal*>IMAGES; |
|
|
|
std::vector<Decal*>IMAGES; |
|
|
|
Rect cardBorder,cardBack,skip,reverse,wild,drawTwo,drawFour; |
|
|
|
Rect cardBorder,cardBack,skip,reverse,wild,drawTwo,drawFour; |
|
|
|
Decal*cardTilesheet; |
|
|
|
Decal*cardTilesheet; |
|
|
|
|
|
|
|
Hand playerHand; |
|
|
|
|
|
|
|
std::vector<Hand>opponentHands; |
|
|
|
|
|
|
|
CardPile startingPile,drawPile,discardPile; |
|
|
|
|
|
|
|
QuickGUI::Manager playerPickMenu; |
|
|
|
|
|
|
|
QuickGUI::Button *TwoPlayerButton,*ThreePlayerButton,*FourPlayerButton; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
GameState state=AIPICK; |
|
|
|
|
|
|
|
|
|
|
|
public: |
|
|
|
public: |
|
|
|
CardGameRef() |
|
|
|
CardGameRef() |
|
|
@ -49,23 +77,25 @@ public: |
|
|
|
sAppName = "Uno!"; |
|
|
|
sAppName = "Uno!"; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public: |
|
|
|
void ReshuffleDrawPile(){ |
|
|
|
bool OnUserCreate() override |
|
|
|
while(discardPile.size()>1){ |
|
|
|
{ |
|
|
|
int randomCardIndex=rand()%(discardPile.size()-1); |
|
|
|
// Called once at the start, so create things here
|
|
|
|
drawPile.push_back(discardPile[randomCardIndex]); |
|
|
|
|
|
|
|
discardPile.erase(discardPile.begin()+randomCardIndex); |
|
|
|
cardBorder={{0,0},{48,64}}; |
|
|
|
} |
|
|
|
cardBack={{48,0},{48,64}}; |
|
|
|
} |
|
|
|
skip={{0,64},{32,32}}; |
|
|
|
|
|
|
|
reverse={{32,64},{32,32}}; |
|
|
|
|
|
|
|
wild={{64,64},{32,32}}; |
|
|
|
|
|
|
|
drawTwo={{96,32},{32,32}}; |
|
|
|
|
|
|
|
drawFour={{96,64},{32,32}}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
cardTilesheet = new Decal(new Sprite("CardGame.png")); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
SetPixelMode(Pixel::MASK); |
|
|
|
void DrawCard(Hand&hand){ |
|
|
|
|
|
|
|
if(drawPile.size()==0){ |
|
|
|
|
|
|
|
ReshuffleDrawPile(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
if(drawPile.size()>0){//It's possible all the cards in the game may have been drawn,
|
|
|
|
|
|
|
|
hand.push_back(drawPile.back()); |
|
|
|
|
|
|
|
drawPile.erase(drawPile.end()-1); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void GenerateCards(){ |
|
|
|
for(int color=0;color<4;color++){ |
|
|
|
for(int color=0;color<4;color++){ |
|
|
|
for(int numb=0;numb<13;numb++){ |
|
|
|
for(int numb=0;numb<13;numb++){ |
|
|
|
Decal*card=new Decal(new Sprite(48,64)); |
|
|
|
Decal*card=new Decal(new Sprite(48,64)); |
|
|
@ -159,6 +189,58 @@ public: |
|
|
|
IMAGES.push_back(card); |
|
|
|
IMAGES.push_back(card); |
|
|
|
} |
|
|
|
} |
|
|
|
SetDrawTarget(nullptr); |
|
|
|
SetDrawTarget(nullptr); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public: |
|
|
|
|
|
|
|
bool OnUserCreate() override |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
// Called once at the start, so create things here
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
cardBorder={{0,0},{48,64}}; |
|
|
|
|
|
|
|
cardBack={{48,0},{48,64}}; |
|
|
|
|
|
|
|
skip={{0,64},{32,32}}; |
|
|
|
|
|
|
|
reverse={{32,64},{32,32}}; |
|
|
|
|
|
|
|
wild={{64,64},{32,32}}; |
|
|
|
|
|
|
|
drawTwo={{96,32},{32,32}}; |
|
|
|
|
|
|
|
drawFour={{96,64},{32,32}}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
cardTilesheet = new Decal(new Sprite("CardGame.png")); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
SetPixelMode(Pixel::MASK); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
GenerateCards(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//2 of each basic card. (80)
|
|
|
|
|
|
|
|
//2 of each special card. (24)
|
|
|
|
|
|
|
|
//8 Wild Cards (8)
|
|
|
|
|
|
|
|
//4 Draw Four Cards (4)
|
|
|
|
|
|
|
|
for(int color=0;color<4;color++){ |
|
|
|
|
|
|
|
for(int value=0;value<13;value++){ |
|
|
|
|
|
|
|
startingPile.emplace_back(Color(color),CardValue(value),true); |
|
|
|
|
|
|
|
startingPile.emplace_back(Color(color),CardValue(value),true); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
for(int i=0;i<8;i++){ |
|
|
|
|
|
|
|
startingPile.emplace_back(Color::RED,WILD,true); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
for(int i=0;i<4;i++){ |
|
|
|
|
|
|
|
startingPile.emplace_back(Color::RED,DRAWFOUR,true); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
while(startingPile.size()>0){ |
|
|
|
|
|
|
|
int randomCardIndex=rand()%startingPile.size(); |
|
|
|
|
|
|
|
drawPile.push_back(startingPile[randomCardIndex]); |
|
|
|
|
|
|
|
startingPile.erase(startingPile.begin()+randomCardIndex); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
TwoPlayerButton=new QuickGUI::Button(playerPickMenu,"1 Opponent",{128-42,20},{84,40}); |
|
|
|
|
|
|
|
ThreePlayerButton=new QuickGUI::Button(playerPickMenu,"2 Opponents",{128-42,94},{84,40}); |
|
|
|
|
|
|
|
FourPlayerButton=new QuickGUI::Button(playerPickMenu,"3 Opponents",{128-42,168},{84,40}); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for(int i=0;i<7;i++){ |
|
|
|
|
|
|
|
DrawCard(playerHand); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return true; |
|
|
|
return true; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -175,15 +257,36 @@ public: |
|
|
|
|
|
|
|
|
|
|
|
bool OnUserUpdate(float fElapsedTime) override |
|
|
|
bool OnUserUpdate(float fElapsedTime) override |
|
|
|
{ |
|
|
|
{ |
|
|
|
// Called once per frame, draws random coloured pixels
|
|
|
|
switch(state){ |
|
|
|
float scale=256.f/(13*48); |
|
|
|
case AIPICK:{ //Player Pick Menu
|
|
|
|
for(int color=0;color<4;color++){ |
|
|
|
playerPickMenu.Update(this); |
|
|
|
for(int value=0;value<13;value++){ |
|
|
|
|
|
|
|
DrawRotatedDecal(vf2d{value*scale*48,color*scale*64}+scale*vf2d{24,32}/2,GetCardImage(Color(color),CardValue(value)),0,scale*vf2d{24,32},{scale,scale});
|
|
|
|
bool buttonClicked=false; |
|
|
|
|
|
|
|
int AICount=0; |
|
|
|
|
|
|
|
if(TwoPlayerButton->bPressed){ |
|
|
|
|
|
|
|
buttonClicked=true; |
|
|
|
|
|
|
|
AICount=1; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
if(ThreePlayerButton->bPressed){ |
|
|
|
|
|
|
|
buttonClicked=true; |
|
|
|
|
|
|
|
AICount=2; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
if(FourPlayerButton->bPressed){ |
|
|
|
|
|
|
|
buttonClicked=true; |
|
|
|
|
|
|
|
AICount=3; |
|
|
|
} |
|
|
|
} |
|
|
|
for (int value=0;value<3;value++){ |
|
|
|
if(buttonClicked){ |
|
|
|
DrawRotatedDecal(vf2d{value*scale*48,5*scale*64}+scale*vf2d{24,32}/2,GetCardImage(Color::RED,CardValue(value+13),value==2?true:false),0,scale*vf2d{24,32},{scale,scale});
|
|
|
|
for(int ai=0;ai<AICount;ai++){ |
|
|
|
|
|
|
|
Hand opponent; |
|
|
|
|
|
|
|
for (int i=0;i<7;i++){ |
|
|
|
|
|
|
|
DrawCard(opponent); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
opponentHands.push_back(opponent); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
state=GameState::DRAW; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
playerPickMenu.DrawDecal(this); |
|
|
|
|
|
|
|
}break; |
|
|
|
} |
|
|
|
} |
|
|
|
return true; |
|
|
|
return true; |
|
|
|
} |
|
|
|
} |
|
|
|