Page Menu
Home
Phabricator (Chris)
Search
Configure Global Search
Log In
Files
F132690
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Flag For Later
Award Token
Authored By
Unknown
Size
23 KB
Referenced Files
None
Subscribers
None
View Options
diff --git a/cardsdeck.cpp b/cardsdeck.cpp
index f4cf8b0..baade85 100644
--- a/cardsdeck.cpp
+++ b/cardsdeck.cpp
@@ -1,143 +1,143 @@
#include "cardsdeck.h"
CardsDeck::CardsDeck(TextureHolder *textures, sf::Font *gameFont, Command *command)
{
commandManager=command;
std::array<std::array<int,2>,4> cardsPos = {
{
- {1087,95}, {1225, 95}, {1225, 277}, {1087, 277}
+ {{1087,95}}, {{1225, 95}}, {{1225, 277}}, {{1087, 277}}
}
};
this->textures = textures;
for (int i=0;i<=3;i++)
{
// spriteCardBases[i].setTexture(this->textures->textureCardBases[i]);
spriteCardBases[i].setPosition(cardsPos[i][0],cardsPos[i][1]);
textPileTitle[i].setFont(*gameFont);
textPileTitle[i].setCharacterSize(16);
textPileTitle[i].setPosition(cardsPos[i][0]+10,cardsPos[i][1]+100);
for (unsigned int j=0;j<efc::cardsDistribution.size();j++)
{
int cardTypeInt = efc::cardsDistribution[j];
cardsList[i].cardsPile[j].cardType = efc::cardsTypes[cardTypeInt];
cardsList[i].cardsPile[j].cardTypeInt = cardTypeInt;
spriteCardBases[i].setTexture(this->textures->cardsTextures[i][cardTypeInt]);
}
}
reloadCards();
}
void CardsDeck::reloadCards(){
for (int i=0;i<=3;i++)
{
cardsList[i].shufflePile();
setTitles(i);
}
}
void CardsDeck::draw(sf::RenderTarget& target, sf::RenderStates states) const
{
states.transform *= getTransform();
for (int i=0;i<=3;i++)
{
if ((cardsList[i].invisibleLeft==0.0f) and (cardsList[i].active))
{
target.draw(spriteCardBases[i], states);
target.draw(textPileTitle[i], states);
}
}
}
void CardsDeck::setTitles(int number)
{
int cardTypeInt = getCardTypeInt(number);
textPileTitle[number].setString(efc::cardsTypes[cardTypeInt]);
// int val = getCardTypeInt(number);
spriteCardBases[number].setTexture(textures->cardsTextures[number][cardTypeInt]);
}
void CardsDeck::setFonts(sf::Font *gameFont)
{
for (int i=0;i<=3;i++)
{
textPileTitle[i].setFont(*gameFont);
}
}
void CardsDeck::nextCard(int pileNumber)
{
if (cardsList[pileNumber].active)
{
cardsList[pileNumber].invisibleLeft = 0.75f;
unsigned int currentCard = getCurrentCard(pileNumber);
if (currentCard>=efc::cardsDistribution.size()-1)
{
cardsList[pileNumber].active = false;
commandManager->removeAllCardElement(pileNumber);
} else
{
currentCard += 1;
if (currentCard>3)
currentCard = 0;
cardsList[pileNumber].currentCard = currentCard;
setTitles(pileNumber);
}
}
// setSprites(pileNumber);
}
int CardsDeck::getCurrentCard(int pileNumber)
{
int currentCard = cardsList[pileNumber].currentCard;
return currentCard;
}
std::string CardsDeck::getTitle(int pileNumber)
{
std::string currentText = efc::cardsTypes[getCardTypeInt(pileNumber)];
return currentText;
}
int CardsDeck::getCardTypeInt(int pileNumber)
{
int result = cardsList[pileNumber].cardsPile[getCurrentCard(pileNumber)].cardTypeInt;
return result;
}
void CardsDeck::update(sf::Time deltaTime)
{
for (int i=0;i<=3;i++)
{
if (cardsList[i].invisibleLeft>0.0f)
{
cardsList[i].invisibleLeft -= deltaTime.asSeconds();
}
if (cardsList[i].invisibleLeft<0.0f)
{
cardsList[i].invisibleLeft = 0.0f;
}
}
}
diff --git a/cardslist.h b/cardslist.h
index d2e82eb..ce4ce0d 100644
--- a/cardslist.h
+++ b/cardslist.h
@@ -1,45 +1,45 @@
#ifndef CARDSLIST_H
#define CARDSLIST_H
#include <vector>
#include <iostream> // std::cout
#include <algorithm> // std::shuffle
#include <random> // std::default_random_engine
#include <chrono> // std::chrono::system_clock
#include "card.h"
namespace efc {
- const static std::array<int,32> cardsDistribution = {
+ const static std::array<int,32> cardsDistribution = {{
0,0,0,0,0,0,0,0,
1,1,1,1,1,1,1,1,
2,2,2,2,2,2,2,2,
3,3,3,3,3,3,3,3,
- };
- const static std::array<int,2> cardsDistributionDebug = {
+ }};
+ const static std::array<int,2> cardsDistributionDebug = {{
2,3
- };
+ }};
const static int PILE_SIZE = efc::cardsDistribution.size();
}
class CardsList
{
public:
CardsList(); // To create an array of CardsList
explicit CardsList(int element);
// int amount;
// std::vector<Card*> sd;
/*!
* \brief element Number of the element
*/
std::array<Card, efc::PILE_SIZE> cardsPile;
int currentCard;
int element; /*!< Number of the element */
float invisibleLeft;
bool active;
void shufflePile();
};
#endif // CARDSLIST_H
diff --git a/data.cpp b/data.cpp
index f2fe8a7..b8c27e3 100644
--- a/data.cpp
+++ b/data.cpp
@@ -1,127 +1,127 @@
#include <data.h>
namespace efc {
std::string seasonsNames[4] = {"winter", "spring", "summer", "fall"};
// This array defines fields occupied by the river
int terrainArray[24] = {
8, 24, 40, 56, 72, 88,
113, 114, 115, 116, 117, 118,
138, 139, 140, 141, 142, 143,
167, 183, 199, 215, 231, 247
};
/*
* 0
* 16
* 32
* 48
* 64
* 80
* 96
* 112
* 128
* 144
* 160
* 176
* 192
*/
std::array<std::array<int,2>,256> boards = {
{
- {-1,1}, {0,2}, {1,3}, {2,4}, {3,5}, {4,21}, {-1,-1}, {-1,-1}, {-1,-1}, {-1,-1}, {11,26}, {12,10}, {13,11}, {14,12}, {15,13}, {-1,14},
- {-1,-1}, {18,33}, {19,17}, {20,18}, {21,19}, {5,20}, {-1,-1}, {-1,-1}, {-1,-1}, {-1,-1}, {10, 27,}, {26,28}, {27,29}, {28,30}, {29,46}, {-1,-1},
- {33,48}, {17,32}, {-1,-1}, {51,36}, {35,37}, {36,38}, {37,54}, {-1,-1}, {-1,-1}, {-1,-1}, {43,58}, {44,42}, {60,43}, {-1,-1}, {30,47}, {46,63},
- {32,49}, {48,50}, {49,51}, {50,35}, {-1,-1}, {54,69}, {38,53}, {-1,-1}, {-1,-1}, {58,73}, {42,57}, {-1,-1}, {61,44}, {62,60}, {63,61}, {47,62},
- {65,80}, {66,64}, {67,65}, {68,66}, {69,67}, {53,68}, {-1,-1}, {-1,-1}, {-1,-1}, {57,74}, {73,75}, {74,76}, {75,77}, {76,78}, {77,79}, {78,95},
- {64,81}, {80,97}, {-1,-1}, {99,84}, {83,85}, {84,101}, {-1,-1}, {-1,-1}, {-1,-1}, {90,105}, {91,89}, {92,90}, {108,91}, {-1,-1}, {95,110}, {79,94},
- {-1,-1}, {81,98}, {97,99}, {98,83}, {-1,-1}, {85,102}, {101,118}, {-1,-1}, {105,120}, {89,104}, {-1,-1}, {-1,-1}, {109,92}, {110,108}, {94,109}, {-1,-1},
- {-1,-1}, {-1,-1}, {-1,-1}, {-1,-1}, {-1,-1}, {-1,-1}, {102, 119},{118,-2}, {104,-2}, {-1,-1}, {-1,-1}, {-1,-1}, {-1,-1}, {-1,-1}, {-1,-1}, {-1,-1},
- {-1,-1}, {-1,-1}, {-1,-1}, {-1,-1}, {-1,-1}, {-1,-1}, {-1,-1} , {151,-2}, {137,-2}, {153,136}, {-1,-1}, {-1,-1}, {-1,-1}, {-1,-1}, {-1,-1}, {-1,-1},
- {-1,-1}, {161,146}, {145,147}, {146,163}, {-1,-1}, {-1,-1}, {166,151}, {150,135} ,{-1,-1}, {154,137}, {170,153}, {-1,-1}, {157,172}, {158,156}, {174,157}, {-1,-1},
- {176,161},{160,145}, {-1,-1}, {147,164}, {163,165}, {164,166}, {165,150}, {-1,-1}, {-1,-1}, {-1,-1}, {171,154}, {172,170}, {156,171}, {-1,-1}, {175,158}, {191,174},
- {177,160},{178,176}, {179,177}, {180,178}, {181,179}, {182,180}, {198,181}, {-1,-1}, {-1,-1}, {-1,-1}, {202,187}, {186,188}, {187,189}, {188,190}, {189,191}, {190,175},
- {208,193},{192,194}, {193,195}, {194,211}, {-1,-1}, {213,198}, {197,182}, {-1,-1}, {-1,-1}, {217,202}, {201,186}, {-1,-1}, {205,220}, {206,204}, {207,205}, {223,206},
- {209,192},{225,208}, {-1,-1}, {195,212}, {211,213}, {212,197}, {-1,-1}, {-1,-1}, {-1,-1}, {218,201}, {219,217}, {220,218}, {204,219}, {-1,-1}, {238,223}, {222,207},
- {-1,-1}, {226,209}, {227,225}, {228,226}, {229,227}, {245,228}, {-1,-1}, {-1,-1}, {-1,-1}, {-1,-1}, {250,235}, {234,236}, {235,237}, {236,238}, {237,222}, {-1,-1},
- {-1,241}, {240,242},{241,243}, {242,244}, {243,245}, {244,229}, {-1,-1}, {-1,-1}, {-1,-1}, {-1,-1}, {251,234}, {252,250}, {253,251}, {254,252}, {255,253}, {-1,254},
+ {{-1,1}}, {{0,2}}, {{1,3}}, {{2,4}}, {{3,5}}, {{4,21}}, {{-1,-1}}, {{-1,-1}}, {{-1,-1}}, {{-1,-1}}, {{11,26}}, {{12,10}}, {{13,11}}, {{14,12}}, {{15,13}}, {{-1,14}},
+ {{-1,-1}}, {{18,33}}, {{19,17}}, {{20,18}}, {{21,19}}, {{5,20}}, {{-1,-1}}, {{-1,-1}}, {{-1,-1}}, {{-1,-1}}, {{10, 27,}}, {{26,28}}, {{27,29}}, {{28,30}}, {{29,46}}, {{-1,-1}},
+ {{33,48}}, {{17,32}}, {{-1,-1}}, {{51,36}}, {{35,37}}, {{36,38}}, {{37,54}}, {{-1,-1}}, {{-1,-1}}, {{-1,-1}}, {{43,58}}, {{44,42}}, {{60,43}}, {{-1,-1}}, {{30,47}}, {{46,63}},
+ {{32,49}}, {{48,50}}, {{49,51}}, {{50,35}}, {{-1,-1}}, {{54,69}}, {{38,53}}, {{-1,-1}}, {{-1,-1}}, {{58,73}}, {{42,57}}, {{-1,-1}}, {{61,44}}, {{62,60}}, {{63,61}}, {{47,62}},
+ {{65,80}}, {{66,64}}, {{67,65}}, {{68,66}}, {{69,67}}, {{53,68}}, {{-1,-1}}, {{-1,-1}}, {{-1,-1}}, {{57,74}}, {{73,75}}, {{74,76}}, {{75,77}}, {{76,78}}, {{77,79}}, {{78,95}},
+ {{64,81}}, {{80,97}}, {{-1,-1}}, {{99,84}}, {{83,85}}, {{84,101}}, {{-1,-1}}, {{-1,-1}}, {{-1,-1}}, {{90,105}}, {{91,89}}, {{92,90}}, {{108,91}}, {{-1,-1}}, {{95,110}}, {{79,94}},
+ {{-1,-1}}, {{81,98}}, {{97,99}}, {{98,83}}, {{-1,-1}}, {{85,102}}, {{101,118}}, {{-1,-1}}, {{105,120}}, {{89,104}}, {{-1,-1}}, {{-1,-1}}, {{109,92}}, {{110,108}}, {{94,109}}, {{-1,-1}},
+ {{-1,-1}}, {{-1,-1}}, {{-1,-1}}, {{-1,-1}}, {{-1,-1}}, {{-1,-1}}, {{102, 119}},{{118,-2}}, {{104,-2}}, {{-1,-1}}, {{-1,-1}}, {{-1,-1}}, {{-1,-1}}, {{-1,-1}}, {{-1,-1}}, {{-1,-1}},
+ {{-1,-1}}, {{-1,-1}}, {{-1,-1}}, {{-1,-1}}, {{-1,-1}}, {{-1,-1}}, {{-1,-1}} , {{151,-2}}, {{137,-2}}, {{153,136}}, {{-1,-1}}, {{-1,-1}}, {{-1,-1}}, {{-1,-1}}, {{-1,-1}}, {{-1,-1}},
+ {{-1,-1}}, {{161,146}}, {{145,147}}, {{146,163}}, {{-1,-1}}, {{-1,-1}}, {{166,151}}, {{150,135}} ,{{-1,-1}}, {{154,137}}, {{170,153}}, {{-1,-1}}, {{157,172}}, {{158,156}}, {{174,157}}, {{-1,-1}},
+ {{176,161}},{{160,145}}, {{-1,-1}}, {{147,164}}, {{163,165}}, {{164,166}}, {{165,150}}, {{-1,-1}}, {{-1,-1}}, {{-1,-1}}, {{171,154}}, {{172,170}}, {{156,171}}, {{-1,-1}}, {{175,158}}, {{191,174}},
+ {{177,160}},{{178,176}}, {{179,177}}, {{180,178}}, {{181,179}}, {{182,180}}, {{198,181}}, {{-1,-1}}, {{-1,-1}}, {{-1,-1}}, {{202,187}}, {{186,188}}, {{187,189}}, {{188,190}}, {{189,191}}, {{190,175}},
+ {{208,193}},{{192,194}}, {{193,195}}, {{194,211}}, {{-1,-1}}, {{213,198}}, {{197,182}}, {{-1,-1}}, {{-1,-1}}, {{217,202}}, {{201,186}}, {{-1,-1}}, {{205,220}}, {{206,204}}, {{207,205}}, {{223,206}},
+ {{209,192}},{{225,208}}, {{-1,-1}}, {{195,212}}, {{211,213}}, {{212,197}}, {{-1,-1}}, {{-1,-1}}, {{-1,-1}}, {{218,201}}, {{219,217}}, {{220,218}}, {{204,219}}, {{-1,-1}}, {{238,223}}, {{222,207}},
+ {{-1,-1}}, {{226,209}}, {{227,225}}, {{228,226}}, {{229,227}}, {{245,228}}, {{-1,-1}}, {{-1,-1}}, {{-1,-1}}, {{-1,-1}}, {{250,235}}, {{234,236}}, {{235,237}}, {{236,238}}, {{237,222}}, {{-1,-1}},
+ {{-1,241}}, {{240,242}},{{241,243}}, {{242,244}}, {{243,245}}, {{244,229}}, {{-1,-1}}, {{-1,-1}}, {{-1,-1}}, {{-1,-1}}, {{251,234}}, {{252,250}}, {{253,251}}, {{254,252}}, {{255,253}}, {{-1,254}},
},
};
std::array<std::array<int,numberSteps>,4> occupiedFields =
{
{
- {1,2,3,4,5,17,18,19,20,21,32,33,35,36,37,38,48,49,50,51,53,54,64,65,66,67,68,69,80,81,83,84,85,97,98,99,101,102,118},
- {10,11,12,13,14,26,27,28,29,30,42,43,44,46,47,57,58,60,61,62,63,73,74,75,76,77,78,79,89,90,91,92,94,95,104,105,108,109,110},
- {145,146,147,150,151,160,161,163,164,165,166,176,177,178,179,180,181,182,192,193,194,195,197,198,208,209,211,212,213,225,226,227,228,229,241,242,243,244,245},
- {137,153,154,156,157,158,170,171,172,174,175,186,187,188,189,190,191,201,202,204,205,206,207,217,218,219,220,222,223,234,235,236,237,238,250,251,252,253,254}
+ {{1,2,3,4,5,17,18,19,20,21,32,33,35,36,37,38,48,49,50,51,53,54,64,65,66,67,68,69,80,81,83,84,85,97,98,99,101,102,118}},
+ {{10,11,12,13,14,26,27,28,29,30,42,43,44,46,47,57,58,60,61,62,63,73,74,75,76,77,78,79,89,90,91,92,94,95,104,105,108,109,110}},
+ {{145,146,147,150,151,160,161,163,164,165,166,176,177,178,179,180,181,182,192,193,194,195,197,198,208,209,211,212,213,225,226,227,228,229,241,242,243,244,245}},
+ {{137,153,154,156,157,158,170,171,172,174,175,186,187,188,189,190,191,201,202,204,205,206,207,217,218,219,220,222,223,234,235,236,237,238,250,251,252,253,254}}
}
};
sf::Color playersColors[4] = {
sf::Color(122, 185,246,255),
sf::Color(144, 226,106,255),
sf::Color(255, 163,142,255),
sf::Color(250, 255,117,255),
};
std::array<std::array<int,3>,efc::diamondsNumber> DIAMONDS_SETUP =
{
{
- {0,0,-1},{0,0,-1},
- {1,0,-1},{1,0,-1},
- {2,0,-1},{2,0,-1},
- {3,0,-1},{3,0,-1},
- {4,0,-1},{4,0,-1},{4,0,-1},{4,0,-1},{4,0,-1},{4,0,-1},
- {0,0,-1},{0,0,-1},
- {1,0,-1},{1,0,-1},
- {2,0,-1},{2,0,-1},
- {3,0,-1},{3,0,-1},
- {4,0,-1},{4,0,-1},{4,0,-1},{4,0,-1},{4,0,-1},{4,0,-1},
-
- {0,1,-1},{0,1,-1},
- {1,1,-1},{1,1,-1},
- {2,1,-1},{2,1,-1},
- {3,1,-1},{3,1,-1},
- {4,1,-1},{4,1,-1},{4,1,-1},{4,1,-1},{4,1,-1},{4,1,-1},
- {0,1,-1},{0,1,-1},
- {1,1,-1},{1,1,-1},
- {2,1,-1},{2,1,-1},
- {3,1,-1},{3,1,-1},
- {4,1,-1},{4,1,-1},{4,1,-1},{4,1,-1},{4,1,-1},{4,1,-1},
-
-
-
- {0,3,-1},{0,3,-1},
- {1,3,-1},{1,3,-1},
- {2,3,-1},{2,3,-1},
- {3,3,-1},{3,3,-1},
- {4,3,-1},{4,3,-1},{4,3,-1},{4,3,-1},{4,3,-1},{4,3,-1},
- {0,3,-1},{0,3,-1},
- {1,3,-1},{1,3,-1},
- {2,3,-1},{2,3,-1},
- {3,3,-1},{3,3,-1},
- {4,3,-1},{4,3,-1},{4,3,-1},{4,3,-1},{4,3,-1},{4,3,-1},
-
-
- {0,2,-1},{0,2,-1},
- {1,2,-1},{1,2,-1},
- {2,2,-1},{2,2,-1},
- {3,2,-1},{3,2,-1},
- {4,2,-1},{4,2,-1},{4,2,-1},{4,2,-1},{4,2,-1},{4,2,-1},
- {0,2,-1},{0,2,-1},
- {1,2,-1},{1,2,-1},
- {2,2,-1},{2,2,-1},
- {3,2,-1},{3,2,-1},
- {4,2,-1},{4,2,-1},{4,2,-1},{4,2,-1},{4,2,-1},{4,2,-1},
+ {{0,0,-1}},{{0,0,-1}},
+ {{1,0,-1}},{{1,0,-1}},
+ {{2,0,-1}},{{2,0,-1}},
+ {{3,0,-1}},{{3,0,-1}},
+ {{4,0,-1}},{{4,0,-1}},{{4,0,-1}},{{4,0,-1}},{{4,0,-1}},{{4,0,-1}},
+ {{0,0,-1}},{{0,0,-1}},
+ {{1,0,-1}},{{1,0,-1}},
+ {{2,0,-1}},{{2,0,-1}},
+ {{3,0,-1}},{{3,0,-1}},
+ {{4,0,-1}},{{4,0,-1}},{{4,0,-1}},{{4,0,-1}},{{4,0,-1}},{{4,0,-1}},
+
+ {{0,1,-1}},{{0,1,-1}},
+ {{1,1,-1}},{{1,1,-1}},
+ {{2,1,-1}},{{2,1,-1}},
+ {{3,1,-1}},{{3,1,-1}},
+ {{4,1,-1}},{{4,1,-1}},{{4,1,-1}},{{4,1,-1}},{{4,1,-1}},{{4,1,-1}},
+ {{0,1,-1}},{{0,1,-1}},
+ {{1,1,-1}},{{1,1,-1}},
+ {{2,1,-1}},{{2,1,-1}},
+ {{3,1,-1}},{{3,1,-1}},
+ {{4,1,-1}},{{4,1,-1}},{{4,1,-1}},{{4,1,-1}},{{4,1,-1}},{{4,1,-1}},
+
+
+
+ {{0,3,-1}},{{0,3,-1}},
+ {{1,3,-1}},{{1,3,-1}},
+ {{2,3,-1}},{{2,3,-1}},
+ {{3,3,-1}},{{3,3,-1}},
+ {{4,3,-1}},{{4,3,-1}},{{4,3,-1}},{{4,3,-1}},{{4,3,-1}},{{4,3,-1}},
+ {{0,3,-1}},{{0,3,-1}},
+ {{1,3,-1}},{{1,3,-1}},
+ {{2,3,-1}},{{2,3,-1}},
+ {{3,3,-1}},{{3,3,-1}},
+ {{4,3,-1}},{{4,3,-1}},{{4,3,-1}},{{4,3,-1}},{{4,3,-1}},{{4,3,-1}},
+
+
+ {{0,2,-1}},{{0,2,-1}},
+ {{1,2,-1}},{{1,2,-1}},
+ {{2,2,-1}},{{2,2,-1}},
+ {{3,2,-1}},{{3,2,-1}},
+ {{4,2,-1}},{{4,2,-1}},{{4,2,-1}},{{4,2,-1}},{{4,2,-1}},{{4,2,-1}},
+ {{0,2,-1}},{{0,2,-1}},
+ {{1,2,-1}},{{1,2,-1}},
+ {{2,2,-1}},{{2,2,-1}},
+ {{3,2,-1}},{{3,2,-1}},
+ {{4,2,-1}},{{4,2,-1}},{{4,2,-1}},{{4,2,-1}},{{4,2,-1}},{{4,2,-1}},
}
} ;
}
diff --git a/playerhud.cpp b/playerhud.cpp
index 9c35779..3ae80e0 100644
--- a/playerhud.cpp
+++ b/playerhud.cpp
@@ -1,265 +1,265 @@
#include "playerhud.h"
#include "textureholder.h"
#include "boardelem.h"
std::set<int> Player::getTerrainSet(){
std::set<int> terrain;
for (int i: efc::terrainArray)
{
terrain.insert(i);
}
return terrain;
}
std::set<int> Player::getBusy(){
std::set<int> busyTiles;
for (std::pair<int, efc::BoardElem> i: elems.items_map)
{
busyTiles.insert(i.first);
}
return busyTiles;
}
std::set<int> Player::getNeighbours(){
std::set<int> neighbours;
for (std::pair<int, efc::BoardElem> i: elems.items_map)
{
std::set<int> terrain = getTerrainSet();
std::set<int> neighboursVector(efc::getNeighbours(i.second.pos));
for (int j: neighboursVector)
{
if ((elems.items_map.count(j) == 0) && (terrain.count(j)==0))
{
neighbours.insert(j);
}
}
}
return neighbours;
}
void Player::updateTxt(){
txtCash.setString(std::to_string(cash));
}
void Player::updatePlayer(){
updateTxt();
}
Player::Player():
frozenLeft(0),
reachedPortal(false),
reachedPortalFirst(false),
human(false)
{
pos = 0;
cash = 0;
energy = 0;
food = 0;
faith = 0;
active = false;
done = false;
tileSize = 0;
textures = nullptr;
number = 0;
// setSpriteAI();
}
void Player::setActive(bool newState){
active = newState;
elems.active = newState;
for (auto&& i: characters)
{
i.active = newState;
}
}
Player::Player(TextureHolder *textures, sf::Font *gameFont, int playerNumber):
reachedPortal(false),
reachedPortalFirst(false),
human(false)
{
number = playerNumber;
frozenLeft = 0;
done = false;
active = false;
this->textures = textures;
// Character character(this->textures, pos);
characters.push_back(Character (this->textures, playerNumber));
// efc::BoardElem startElem(textures, efc::startPlayers[pos],444);
// startElem.setColor(efc::playersColors[pos]);
// elems.items.push_back(startElem);
// elems.items_map.insert({efc::startPlayers[pos], startElem});
// this->faceSize = faceSize;
// spriteFace.setTexture(textures->textureFaces);
this->pos = playerNumber;
// symbol.setTexture(this->textures->textureSymbols);
// sf::IntRect symbolsRect[4] = {sf::IntRect(0,0,255,255), sf::IntRect(256,0,512,255), sf::IntRect(0,255, 255, 512), sf::IntRect(255,255,512, 512)};
// symbol.setTextureRect(symbolsRect[pos]);
// symbol.setScale(sf::Vector2f(0.2f, 0.20f));
// symbol.setColor(sf::Color(25, 25, 25, 105));
// symbol.setPosition(60, (pos*100)+40);
food = 0;
cash = 0;
energy = 0;
faith = 0;
txtCash.setFont(*gameFont);
txtCash.setCharacterSize(20);
txtFood.setFont(*gameFont);
txtEnergy.setFont(*gameFont);
txtFaith.setFont(*gameFont);
txtNextRound.setFont(*gameFont);
txtNextRound.setString("End Turn");
txtNextRound.setCharacterSize(12);
txtNextRound.setPosition(40,(playerNumber*100)+10);
int posX1 = 82;
int posX2 = 962;
int posY1 = 22;
int posY2 = 720;
std::array<std::array<int,2>,4> textPos =
{
{
- {{posX1,posY1}}, {posX2,posY1},
- {{posX1,posY2}}, {posX2, posY2}
+ {{posX1,posY1}}, {{posX2,posY1}},
+ {{posX1,posY2}}, {{posX2, posY2}}
}
};
txtCash.setPosition(textPos[playerNumber][0],textPos[playerNumber][1] );
buttons.insert({"end_turn",rectangle});
setSpriteAI();
}
std::string Player::getElem(sf::Vector2f mousePosition) {
std::string result = "";
sf::Vector2f hoverPos = getPosition();
for (std::pair<std::string, sf::RectangleShape> i: buttons)
{
sf::FloatRect spriteBounds = i.second.getLocalBounds();
sf::FloatRect closeRect;
closeRect.left = i.second.getPosition().x;
closeRect.top = i.second.getPosition().y;
closeRect.width = spriteBounds.width;
closeRect.height = spriteBounds.height;
if (closeRect.contains(mousePosition.x - hoverPos.x,mousePosition.y - hoverPos.y))
{
return i.first;
}
}
return result;
}
void Player::draw(sf::RenderTarget& target, sf::RenderStates states) const
{
states.transform *= getTransform();
target.draw(txtCash, states);
}
void Player::play()
{
for (auto&& i: characters)
{
i.play();
}
}
void Player::update(sf::Time deltaTime)
{
updateTxt();
if (frozenLeft==0)
{
for (auto&& i: characters)
{
sf::Vector2f movement(0.f, 0.f);
if (i.currentAnimationIndex==efc::DIR_LEFT)
movement = sf::Vector2f (-10.f, 0.f);
else if (i.currentAnimationIndex==efc::DIR_RIGHT)
movement = sf::Vector2f (10.f, 0.f);
else if (i.currentAnimationIndex==efc::DIR_UP)
movement = sf::Vector2f (0.f, -10.f);
else if (i.currentAnimationIndex==efc::DIR_DOWN)
movement = sf::Vector2f (0.f, 10.f);
i.update(deltaTime);
}
} else{
characters[0].currentAnimationIndex=efc::DIR_DOWN;
}
}
std::array<int,2> Player::getMovements(int diceResult)
{
return characters[0].getMovements(diceResult);
}
void Player::setFigurePos(int pos)
{
characters[0].setBoardPosition(pos);
}
void Player::restartPlayer(){
food = 0;
cash = 0;
energy = 0;
faith = 0;
}
void Player::setHuman(bool newHuman)
{
human = newHuman;
setSpriteAI();
}
void Player::swapHuman()
{
if (human)
{
setHuman(false);
return;
} else {
setHuman(true);
return;
}
}
void Player::setSpriteAI()
{
if (human)
spriteAI.setTexture(textures->textureButtonHuman);
else
spriteAI.setTexture(textures->textureButtonCpu);
std::array<std::array<int,2>,4> spriteHumanPos =
{
{
{{220,450}}, {{1050,450}},
{{140,600}}, {{1110, 600}}
}
};
sf::Vector2f spriteHumanPosNew(spriteHumanPos[number][0],spriteHumanPos[number][1]);
spriteAI.setPosition(spriteHumanPosNew);
}
File Metadata
Details
Attached
Mime Type
text/x-diff
Expires
Tue, Jun 16, 12:58 AM (2 w, 1 d ago)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
69757
Default Alt Text
(23 KB)
Attached To
Mode
R82 deerportal
Attached
Detach File
Event Timeline