Added AI Player menu setup.
This commit is contained in:
parent
3688ff574c
commit
591eaf788a
@ -1,5 +1,7 @@
|
||||
#define OLC_PGE_APPLICATION
|
||||
#include "olcPixelGameEngine.h"
|
||||
#define OLC_PGEX_QUICKGUI
|
||||
#include "olcPGEX_QuickGUI.h"
|
||||
|
||||
using namespace olc;
|
||||
|
||||
@ -33,14 +35,40 @@ class CardGameRef : public olc::PixelGameEngine
|
||||
DRAWFOUR,
|
||||
};
|
||||
|
||||
enum GameState{
|
||||
AIPICK,
|
||||
DRAW,
|
||||
PICK,
|
||||
RESULT,
|
||||
VICTORY
|
||||
};
|
||||
|
||||
struct Rect{
|
||||
vf2d pos;
|
||||
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;
|
||||
Rect cardBorder,cardBack,skip,reverse,wild,drawTwo,drawFour;
|
||||
Decal*cardTilesheet;
|
||||
Hand playerHand;
|
||||
std::vector<Hand>opponentHands;
|
||||
CardPile startingPile,drawPile,discardPile;
|
||||
QuickGUI::Manager playerPickMenu;
|
||||
QuickGUI::Button *TwoPlayerButton,*ThreePlayerButton,*FourPlayerButton;
|
||||
|
||||
GameState state=AIPICK;
|
||||
|
||||
public:
|
||||
CardGameRef()
|
||||
@ -49,23 +77,25 @@ public:
|
||||
sAppName = "Uno!";
|
||||
}
|
||||
|
||||
public:
|
||||
bool OnUserCreate() override
|
||||
{
|
||||
// Called once at the start, so create things here
|
||||
void ReshuffleDrawPile(){
|
||||
while(discardPile.size()>1){
|
||||
int randomCardIndex=rand()%(discardPile.size()-1);
|
||||
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 numb=0;numb<13;numb++){
|
||||
Decal*card=new Decal(new Sprite(48,64));
|
||||
@ -159,6 +189,58 @@ public:
|
||||
IMAGES.push_back(card);
|
||||
}
|
||||
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;
|
||||
}
|
||||
|
||||
@ -175,15 +257,36 @@ public:
|
||||
|
||||
bool OnUserUpdate(float fElapsedTime) override
|
||||
{
|
||||
// Called once per frame, draws random coloured pixels
|
||||
float scale=256.f/(13*48);
|
||||
for(int color=0;color<4;color++){
|
||||
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});
|
||||
switch(state){
|
||||
case AIPICK:{ //Player Pick Menu
|
||||
playerPickMenu.Update(this);
|
||||
|
||||
bool buttonClicked=false;
|
||||
int AICount=0;
|
||||
if(TwoPlayerButton->bPressed){
|
||||
buttonClicked=true;
|
||||
AICount=1;
|
||||
}
|
||||
if(ThreePlayerButton->bPressed){
|
||||
buttonClicked=true;
|
||||
AICount=2;
|
||||
}
|
||||
for (int value=0;value<3;value++){
|
||||
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});
|
||||
if(FourPlayerButton->bPressed){
|
||||
buttonClicked=true;
|
||||
AICount=3;
|
||||
}
|
||||
if(buttonClicked){
|
||||
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;
|
||||
}
|
||||
|
@ -76,6 +76,7 @@
|
||||
<SDLCheck>true</SDLCheck>
|
||||
<PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<ConformanceMode>true</ConformanceMode>
|
||||
<LanguageStandard>stdcpp17</LanguageStandard>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<SubSystem>Console</SubSystem>
|
||||
@ -104,6 +105,7 @@
|
||||
<SDLCheck>true</SDLCheck>
|
||||
<PreprocessorDefinitions>_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<ConformanceMode>true</ConformanceMode>
|
||||
<LanguageStandard>stdcpp17</LanguageStandard>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<SubSystem>Console</SubSystem>
|
||||
@ -127,6 +129,7 @@
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="olcPGEX_QuickGUI.h" />
|
||||
<ClInclude Include="olcPixelGameEngine.h" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
|
@ -18,6 +18,9 @@
|
||||
<ClInclude Include="olcPixelGameEngine.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="olcPGEX_QuickGUI.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="CardGame.cpp">
|
||||
|
1170
CardGameRef/olcPGEX_QuickGUI.h
Normal file
1170
CardGameRef/olcPGEX_QuickGUI.h
Normal file
File diff suppressed because it is too large
Load Diff
Loading…
x
Reference in New Issue
Block a user