Skip to content

Commit

Permalink
Push latest progress.
Browse files Browse the repository at this point in the history
  • Loading branch information
SuperSaiyajinStackZ committed May 17, 2020
1 parent ac965b9 commit d175235
Show file tree
Hide file tree
Showing 4 changed files with 129 additions and 85 deletions.
7 changes: 6 additions & 1 deletion include/screens/gameScreen.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,17 @@ class GameScreen : public Screen
int rowSelection = 3; // To select the Row.
int dropSelection = 0; // Where to drop.
void Refresh(); // Refresh the dropSelection.
bool isStats = false;

// Player Names etc.
int avatar1, avatar2, winAmount;
std::string p1Name, p2Name;
std::string getName(int Player) const;
int getAvatar(int Player) const;

// Special handle.
int handleAI();
int getValue(int row);

std::vector<ChipIcn> GamePos = {
// First Row -> 0-6.
{115, 205},
Expand Down
3 changes: 2 additions & 1 deletion include/utils/_3DVier_Helper.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,10 @@
#define _3DVIER_HELPER_HPP

#include <3ds.h>
#include <string>

namespace _3DVier_Helper {
int selectAvatar(int oldAvatar);
int selectAvatar(int oldAvatar, const std::string text);
}

#endif
189 changes: 108 additions & 81 deletions source/screens/gameScreen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ extern bool touching(touchPosition touch, Structs::ButtonPos button);
GameScreen::GameScreen() {
// First we select the Avatars.
// Then the names.
this->avatar1 = _3DVier_Helper::selectAvatar(0);
this->avatar2 = _3DVier_Helper::selectAvatar(0);
this->avatar1 = _3DVier_Helper::selectAvatar(0, "Player 1: Select your avatar!");
this->avatar2 = _3DVier_Helper::selectAvatar(0, "Player 2: Select your avatar!");
this->p1Name = Keyboard::getString(10, "Enter Player 1's name.", 0.6f);
this->p2Name = Keyboard::getString(10, "Enter Player 2's name.", 0.6f);
this->winAmount = 3; // For now just 3.
Expand All @@ -51,44 +51,75 @@ std::string GameScreen::getName(int Player) const {

int GameScreen::getAvatar(int Player) const {
if (Player == 1) return this->avatar1;
else return this->avatar2;
else return this->avatar2;
}

void GameScreen::Draw(void) const {
if (!this->isStats) {
GFX::DrawTop(false);
Gui::Draw_Rect(0, 0, 400, 240, C2D_Color32(0, 0, 0, 210)); // Darken the screen.
GFX::DrawRaster(114, 5);
// Draw current Player and the chip color.
GFX::DrawChar(this->getAvatar(this->currentGame->currentPlayer()), -5, 35, 1, 1);
GFX::DrawChip(50, 160, 1, 1, this->currentGame->currentPlayer());
for (int i = 0; i < (int)this->currentGame->getField().size(); i++) {
if (this->currentGame->getField()[i] != 0) {
GFX::DrawChip(GamePos[i].X, GamePos[i].Y, 1, 1, this->currentGame->getField()[i]);
}
}
// Draw the temporary chip.
GFX::DrawSelectedChip(GamePos[this->dropSelection].X, GamePos[this->dropSelection].Y);

GFX::DrawBottom();
Gui::Draw_Rect(0, 0, 320, 240, C2D_Color32(0, 0, 0, 210)); // Darken the screen.
Gui::DrawStringCentered(0, 0, 0.9f, config->textColor(), "Current Player: " + this->getName(this->currentGame->currentPlayer()), 320);
} else {
GFX::DrawTop();
Gui::Draw_Rect(0, 0, 400, 240, C2D_Color32(0, 0, 0, 210)); // Darken the screen.
Gui::DrawStringCentered(0, 0, 0.8f, config->textColor(), "Needed Wins to win: " + std::to_string(this->winAmount), 320);
// Should be basically a helper for the AI in the future.
int GameScreen::getValue(int row) {
if (!this->currentGame->isUsed(row)) {
return row;
}

if (!this->currentGame->isUsed(row + 7)) {
return row + 7;
}

if (!this->currentGame->isUsed(row + 14)) {
return row + 14;
}

if (!this->currentGame->isUsed(row + 21)) {
return row + 21;
}

if (!this->currentGame->isUsed(row + 28)) {
return row + 28;
}

if (!this->currentGame->isUsed(row + 35)) {
return row + 35;
}

GFX::DrawChar(this->getAvatar(1), 70, 35, 1, 1);
Gui::DrawString(75, 160, 0.6f, config->textColor(), this->getName(1), 320);
Gui::DrawString(75, 180, 0.6f, config->textColor(), "Wins: " + std::to_string(this->currentGame->getScore(1)), 320);
if (this->currentGame->isUsed(row + 35)) {
return -1;
}

GFX::DrawChar(this->getAvatar(2), 200, 35, 1, 1);
Gui::DrawString(205, 160, 0.6f, config->textColor(), this->getName(2), 320);
Gui::DrawString(205, 180, 0.6f, config->textColor(), "Wins: " + std::to_string(this->currentGame->getScore(2)), 320);
return -1;
}

GFX::DrawBottom();
Gui::Draw_Rect(0, 0, 320, 240, C2D_Color32(0, 0, 0, 210)); // Darken the screen.
// TODO.
int GameScreen::handleAI() {
return 0;
}


void GameScreen::Draw(void) const {
GFX::DrawTop(false);
Gui::Draw_Rect(0, 0, 400, 240, C2D_Color32(0, 0, 0, 210)); // Darken the screen.
GFX::DrawRaster(114, 5);
// Draw current Player and the chip color.
GFX::DrawChar(this->getAvatar(this->currentGame->currentPlayer()), -5, 35, 1, 1);
GFX::DrawChip(45, 165, 1, 1, this->currentGame->currentPlayer());
for (int i = 0; i < (int)this->currentGame->getField().size(); i++) {
if (this->currentGame->getField()[i] != 0) {
GFX::DrawChip(GamePos[i].X, GamePos[i].Y, 1, 1, this->currentGame->getField()[i]);
}
}
// Draw the temporary chip.
GFX::DrawSelectedChip(GamePos[this->dropSelection].X, GamePos[this->dropSelection].Y);

GFX::DrawBottom();
Gui::Draw_Rect(0, 0, 320, 240, C2D_Color32(0, 0, 0, 210)); // Darken the screen.
Gui::DrawStringCentered(0, 0, 0.8f, config->textColor(), "Needed Wins to win: " + std::to_string(this->winAmount), 320);

GFX::DrawChar(this->getAvatar(1), 30, 35, 1, 1);
Gui::DrawString(40, 160, 0.6f, config->textColor(), this->getName(1), 320);
Gui::DrawString(40, 180, 0.6f, config->textColor(), "Wins: " + std::to_string(this->currentGame->getScore(1)), 320);

GFX::DrawChar(this->getAvatar(2), 170, 35, 1, 1);
Gui::DrawString(175, 160, 0.6f, config->textColor(), this->getName(2), 320);
Gui::DrawString(175, 180, 0.6f, config->textColor(), "Wins: " + std::to_string(this->currentGame->getScore(2)), 320);
}

void GameScreen::Refresh() {
Expand Down Expand Up @@ -131,69 +162,65 @@ void GameScreen::Refresh() {


void GameScreen::Logic(u32 hDown, u32 hHeld, touchPosition touch) {
if (hDown & KEY_B) {
Gui::screenBack();
return;
if (hDown & KEY_START) {
if (Msg::promptMsg("Would you like to exit this game?")) {
Gui::screenBack();
return;
}
}

if (this->isStats) {
if (hDown & KEY_L) this->isStats = false;
}

if (!this->isStats) {
if (hDown & KEY_A) {
if (this->currentGame->setChip(this->dropSelection, this->currentGame->currentPlayer()) == true) {
if (this->currentGame->checkMatches(this->currentGame->currentPlayer()) == true) {
if (this->currentGame->getScore(this->currentGame->currentPlayer()) < this->winAmount) {
Msg::DisplayWaitMsg(this->getName(this->currentGame->currentPlayer()) + " wins this match!\nNeeded Wins to win this game: " + std::to_string(this->winAmount) + ".");
this->currentGame->clearField();
this->rowSelection = 3;
this->Refresh();
this->currentGame->currentPlayer(1);
return;
} else {
Msg::DisplayWaitMsg(this->getName(this->currentGame->currentPlayer()) + " wins this game!\nResult: "
+ this->getName(1) + ": " + std::to_string(this->currentGame->getScore(1)) + " | " + this->getName(2) + ": "
+ std::to_string(this->currentGame->getScore(2)));
Gui::screenBack();
return;
}
} else {
if (this->currentGame->currentPlayer() == 1) {
this->currentGame->currentPlayer(2);
} else {
this->currentGame->currentPlayer(1);
}
}
this->rowSelection = 3;
this->Refresh();
if (this->currentGame->allUsed()) {
Msg::DisplayWaitMsg("Game Over... all slots are used.\nWould you like to rematch?");
if (hDown & KEY_A) {
if (this->currentGame->setChip(this->dropSelection, this->currentGame->currentPlayer()) == true) {
if (this->currentGame->checkMatches(this->currentGame->currentPlayer()) == true) {
if (this->currentGame->getScore(this->currentGame->currentPlayer()) < this->winAmount) {
Msg::DisplayWaitMsg(this->getName(this->currentGame->currentPlayer()) + " wins this match!\nNeeded Wins to win this game: " + std::to_string(this->winAmount) + ".");
this->currentGame->clearField();
this->rowSelection = 3;
this->Refresh();
this->currentGame->currentPlayer(1);
return;
} else {
Msg::DisplayWaitMsg(this->getName(this->currentGame->currentPlayer()) + " wins this game!\nResult: "
+ this->getName(1) + ": " + std::to_string(this->currentGame->getScore(1)) + " | " + this->getName(2) + ": "
+ std::to_string(this->currentGame->getScore(2)));
Gui::screenBack();
return;
}
} else {
if (this->currentGame->currentPlayer() == 1) {
this->currentGame->currentPlayer(2);
} else {
this->currentGame->currentPlayer(1);
}
}
}

if (hDown & KEY_RIGHT) {
if (this->rowSelection < 6) {
this->rowSelection++;
this->rowSelection = 3;
this->Refresh();
if (this->currentGame->allUsed()) {
Msg::DisplayWaitMsg("Game Over... all slots are used.\nWould you like to rematch?");
this->currentGame->clearField();
this->rowSelection = 3;
this->Refresh();
this->currentGame->currentPlayer(1);
return;
}
}
}

if (hDown & KEY_R) {
this->isStats = true;
if (hDown & KEY_RIGHT) {
if (this->rowSelection < 6) {
this->rowSelection++;
this->Refresh();
}
}

if (hDown & KEY_LEFT) {
if (this->rowSelection > 0) {
this->rowSelection--;
this->Refresh();
}
if (hDown & KEY_LEFT) {
if (this->rowSelection > 0) {
this->rowSelection--;
this->Refresh();
}
}

if (hHeld & KEY_SELECT) {
Msg::HelperBox("Press \uE000 to select the position.\nUse the D-Pad to navigate.\nPress START to exit the game.");
}
}
15 changes: 13 additions & 2 deletions source/utils/_3DVier_Helper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ extern std::unique_ptr<Config> config;
extern touchPosition touch;

// Select a Character.
int _3DVier_Helper::selectAvatar(int oldAvatar) {
int _3DVier_Helper::selectAvatar(int oldAvatar, const std::string text) {
int selection = 0;
int page = 1;
while(1) {
Expand All @@ -44,7 +44,7 @@ int _3DVier_Helper::selectAvatar(int oldAvatar) {
C2D_TargetClear(Bottom, C2D_Color32(0, 0, 0, 0));
GFX::DrawTop();
Gui::Draw_Rect(0, 0, 400, 240, C2D_Color32(0, 0, 0, 190));
Gui::DrawStringCentered(0, 0, 0.8f, config->textColor(), "Select a character you want.", 390, 30);
Gui::DrawStringCentered(0, 0, 0.8f, config->textColor(), text, 390, 30);
if (page == 1) {
GFX::DrawPlayer(-5, 35, 1, 1, 0);
GFX::DrawPlayer(95, 35, 1, 1, 1);
Expand All @@ -56,6 +56,17 @@ int _3DVier_Helper::selectAvatar(int oldAvatar) {
GFX::DrawPlayer(195, 35, 1, 1, 6);
GFX::DrawPlayer(295, 35, 1, 1, 7);
}

Gui::Draw_Rect(10, 160, 80, 30, config->buttonColor());
Gui::Draw_Rect(110, 160, 80, 30, config->buttonColor());
Gui::Draw_Rect(210, 160, 80, 30, config->buttonColor());
Gui::Draw_Rect(310, 160, 80, 30, config->buttonColor());
if (page == 1) {
GFX::DrawButtonSelector(10 + (selection * 100), 160, 1, 1, true);
} else {
GFX::DrawButtonSelector(10 + ((selection-4) * 100), 160, 1, 1, true);
}

GFX::DrawBottom();
Gui::Draw_Rect(0, 0, 320, 240, C2D_Color32(0, 0, 0, 190));
C3D_FrameEnd(0);
Expand Down

0 comments on commit d175235

Please sign in to comment.