Skip to content

Commit

Permalink
UMM added defense a little
Browse files Browse the repository at this point in the history
  • Loading branch information
101itsGabe committed Sep 26, 2023
1 parent 22b9451 commit 8ee8db7
Show file tree
Hide file tree
Showing 11 changed files with 201 additions and 92 deletions.
57 changes: 56 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,61 @@
"iostream": "cpp",
"*.tcc": "cpp",
"random": "cpp",
"vector": "cpp"
"vector": "cpp",
"array": "cpp",
"atomic": "cpp",
"cctype": "cpp",
"clocale": "cpp",
"cmath": "cpp",
"cstdarg": "cpp",
"cstddef": "cpp",
"cstdint": "cpp",
"cstdio": "cpp",
"cstdlib": "cpp",
"cstring": "cpp",
"ctime": "cpp",
"cwchar": "cpp",
"cwctype": "cpp",
"deque": "cpp",
"unordered_map": "cpp",
"exception": "cpp",
"algorithm": "cpp",
"functional": "cpp",
"iterator": "cpp",
"memory": "cpp",
"memory_resource": "cpp",
"numeric": "cpp",
"optional": "cpp",
"string": "cpp",
"system_error": "cpp",
"tuple": "cpp",
"type_traits": "cpp",
"utility": "cpp",
"fstream": "cpp",
"initializer_list": "cpp",
"iosfwd": "cpp",
"istream": "cpp",
"limits": "cpp",
"new": "cpp",
"ostream": "cpp",
"sstream": "cpp",
"stdexcept": "cpp",
"streambuf": "cpp",
"cinttypes": "cpp",
"typeinfo": "cpp",
"bit": "cpp",
"compare": "cpp",
"concepts": "cpp",
"ios": "cpp",
"xfacet": "cpp",
"xiosbase": "cpp",
"xlocale": "cpp",
"xlocinfo": "cpp",
"xlocnum": "cpp",
"xmemory": "cpp",
"xstddef": "cpp",
"xstring": "cpp",
"xtr1common": "cpp",
"xutility": "cpp"
}
}
Binary file removed main
Binary file not shown.
31 changes: 11 additions & 20 deletions main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ void renderText(SDL_Renderer *renderer, Tile *tile, TTF_Font *font, int check)
else if (check == 1)
tileId = "H";
else

tileId = to_string(tile->getTileId());
SDL_Color textColor = {85, 85, 85};
if (font != NULL)
Expand Down Expand Up @@ -155,12 +156,12 @@ bool InitSDL()
SDL_Surface *image = NULL;

PlayerManager PM(6);
GameManager GM(PM.getPlayerList());
GameManager GM(*PM.getPlayerList());

// Window
// Window
int windowWidth, windowHeight;

vector<Tile>* tiles;
vector<Tile> *tiles;

TileManager TM;
tiles = TM.getTileList();
Expand Down Expand Up @@ -227,20 +228,9 @@ bool InitSDL()
printf("Failed to load image. Error: %s\n", IMG_GetError());
}



random_device rd;
mt19937 eng(rd());
int min = 1;
int max = 69;

for (Player &p : PM.getPlayerList())
{
uniform_int_distribution<> distr1(min, max);
int curN = distr1(eng);
// cout << "First Player Tile: " << curN << endl;
p.SetTile(curN);
}
int check = 0;

// Show the updated Frame
SDL_RenderPresent(renderer);
Expand Down Expand Up @@ -291,12 +281,13 @@ bool InitSDL()
{
if (clicked == false)
{
for (Player &p : PM.getPlayerList())
for (Player &p : *PM.getPlayerList())
{
if (p.GetTile() == curTile->getTileId() && p.getClicked() == false)
{
clickedPlayer = &p;
clickedPlayer->setClicked(true);
GM.SetCurPlayer(p);
menu = true;
break;
}
Expand All @@ -305,7 +296,7 @@ bool InitSDL()
}
}

PM.RenderPlayers(renderer,tiles);
PM.RenderPlayers(renderer, tiles);
if (menu)
{
highlight = false;
Expand All @@ -318,12 +309,12 @@ bool InitSDL()
if (clickedPlayer->getTeam() == "Team1")
{
cout << "Clicked Team 1" << endl;
GM.AddTeamScore1(GM.madeShot(curTile, clickedPlayer));
GM.AddTeamScore1(GM.madeShot(curTile, clickedPlayer, *PM.getPlayerList()));
}
else if (clickedPlayer->getTeam() == "Team2")
{
cout << "Clicked Team 2" << endl;
GM.AddTeamScore2(GM.madeShot(curTile, clickedPlayer));
GM.AddTeamScore2(GM.madeShot(curTile, clickedPlayer, *PM.getPlayerList()));
}

clicked = false;
Expand Down Expand Up @@ -358,7 +349,7 @@ bool InitSDL()
}

GM.RenderShotPercent(renderer, font, windowWidth, windowHeight, clickedPlayer);

SDL_RenderPresent(renderer);
}
}
Expand Down
Binary file modified main.exe
Binary file not shown.
81 changes: 63 additions & 18 deletions src/gameManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ GameManager::GameManager(vector<Player> &pl)
{
TeamScore1 = 0;
TeamScore2 = 0;
int count1 = 0;
int count2 = 0;
bool team = true;
SetUpPointVecs();
for (Player &p : pl)
Expand All @@ -28,13 +30,17 @@ GameManager::GameManager(vector<Player> &pl)
{
Team1.emplace_back(p);
p.setTeam("Team1");
p.SetTile(T1StartingPoints[count1]);
team = false;
count1++;
}
else
{
Team2.emplace_back(p);
p.setTeam("Team2");
p.SetTile(T2StartingPoints[count2]);
team = true;
count2++;
}
}
}
Expand All @@ -60,6 +66,18 @@ string GameManager::WhichTeam(Player *player)

void GameManager::SetUpPointVecs()
{
T1StartingPoints = {
54,
68,
84,
};
T2StartingPoints = {66, 50, 80};
HoopTile1 = 60;
HoopTile2 = 74;

TwoPointerSpots = {15, 16, 17, 18, 30, 31, 32, 33, 34, 45,
46, 47, 48, 49, 61, 62, 63, 64, 75, 76, 77, 78, 79, 9, 91,
92, 94, 94, 105, 106, 107, 108};
}

void GameManager::NewGame()
Expand All @@ -80,21 +98,19 @@ void GameManager::AddTeamScore2(int s)

int GameManager::check3(int t)
{
auto it = std::find(ThreePointerSpots.begin(), ThreePointerSpots.end(), t);
auto it2 = std::find(TwoPointerSpots.begin(), TwoPointerSpots.end(), t);

if (it != ThreePointerSpots.end())
if (it2 != TwoPointerSpots.end())
{
// std::cout << t << " is found in the vector." << std::endl;
return 3;
return 2;
}
else if (it2 != TwoPointerSpots.end())
else if (t == HoopTile1 || t == HoopTile2)
{
// cout << t << "is found in 2PointVector" << endl;
return 2;
return 1;
}

return 0;
else
return 3;
}

void GameManager::RenderScore(SDL_Renderer *renderer, TTF_Font *font, int windowWidth, int windowHeight)
Expand Down Expand Up @@ -128,35 +144,43 @@ void GameManager::RenderScore(SDL_Renderer *renderer, TTF_Font *font, int window
}

// returns the number of points
int GameManager::madeShot(Tile *tile, Player *player)
int GameManager::madeShot(Tile *tile, Player *player, vector<Player> pList)
{
// if true then 3 point shot, false 2 point

bool or32 = false;
if (player != NULL)
{
auto it = std::find(ThreePointerSpots.begin(), ThreePointerSpots.end(), player->GetTile());
// auto it = std::find(ThreePointerSpots.begin(), ThreePointerSpots.end(), player->GetTile());
auto it2 = std::find(TwoPointerSpots.begin(), TwoPointerSpots.end(), player->GetTile());

if (it != ThreePointerSpots.end())
{
cout << "3P: " << *it << endl;
or32 = true;
}
if (it2 != TwoPointerSpots.end())
{
cout << "2P: " << *it << endl;
cout << "2P: " << *it2 << endl;
or32 = false;
}
else
{
or32 = true;
}
}

Player *dPlayer = ifDefense(*player, pList);
int defense = 0;
if (dPlayer != NULL)
{
defense = dPlayer->getStats().Defense;
}
std::mt19937 gen(std::time(0)); // Initialize with current time as seed
std::uniform_int_distribution<int> dist(1, 100); // Define a distribution

int r = dist(gen); // Generate a random number
cout << r << endl;
if (or32)
{
if (r < player->getStats().ThreePointer)
cout << "Player 3: " << player->getStats().ThreePointer << endl;
cout << "Defense: " << defense << endl;
if (r < (player->getStats().ThreePointer - defense))
{
cout << "GIMMI THREEEEEEE" << endl;
return 3;
Expand All @@ -165,7 +189,8 @@ int GameManager::madeShot(Tile *tile, Player *player)
}
else if (!or32)
{
if (r < player->getStats().ThreePointer)
cout << "hello?" << endl;
if (r < (player->getStats().TwoPointer - defense))
{
cout << "AND MPS GOOD for another 2" << endl;
return 2;
Expand Down Expand Up @@ -196,3 +221,23 @@ void GameManager::RenderShotPercent(SDL_Renderer *renderer, TTF_Font *font, int
SDL_FreeSurface(surface);
}
}

void GameManager::SetCurPlayer(Player &p)
{
curPlayer = &p;
}

Player *GameManager::ifDefense(Player &player, vector<Player> pList)
{
// Need to implement hoop logic for which team is on which side
int pTile = player.GetTile();
for (Player &p : pList)
{
if (p.GetTile() + 1 == pTile || p.GetTile() + 15 == pTile || p.GetTile() - 1 == pTile || p.GetTile() - 15 == pTile)
{
cout << "DEFENSE" << endl;
return &p;
}
}
return NULL;
}
9 changes: 7 additions & 2 deletions src/gameManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,15 @@ using namespace std;
class GameManager
{
private:
int TeamScore1, TeamScore2;
int TeamScore1, TeamScore2, HoopTile1, HoopTile2;
vector<Player> Team1;
vector<Player> Team2;
vector<int> ThreePointerSpots;
vector<int> TwoPointerSpots;
vector<int> T1StartingPoints;
vector<int> T2StartingPoints;
Player *curPlayer;
Player *ifDefense(Player &, vector<Player>);

public:
GameManager();
Expand All @@ -30,8 +34,9 @@ class GameManager
void SetUpPointVecs();
void RenderScore(SDL_Renderer *, TTF_Font *, int, int);
void RenderShotPercent(SDL_Renderer *, TTF_Font *, int, int, Player *);
void SetCurPlayer(Player &);

int madeShot(Tile *, Player *);
int madeShot(Tile *, Player *, vector<Player>);
int check3(int);
string WhichTeam(Player *p);
};
Expand Down
6 changes: 4 additions & 2 deletions src/player.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,17 @@ Player::Player()
curTile = 0;
curClicked = false;
stats.ThreePointer = 33;
stats.TwoPointer = 33;
stats.TwoPointer = 66;
stats.Defense = 10;
}

Player::Player(int t)
{
curTile = t;
curClicked = false;
stats.ThreePointer = 33;
stats.TwoPointer = 33;
stats.TwoPointer = 66;
stats.Defense = 10;
}

void Player::setImgPath(string p)
Expand Down
2 changes: 1 addition & 1 deletion src/player.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

struct Stats
{
int ThreePointer, TwoPointer;
int ThreePointer, TwoPointer, Defense;
};

struct ImgRect
Expand Down
Loading

0 comments on commit 8ee8db7

Please sign in to comment.