Skip to content

Commit

Permalink
Refactoring Code
Browse files Browse the repository at this point in the history
  • Loading branch information
baguskokow committed Jul 31, 2024
1 parent e0786fd commit 385da0c
Show file tree
Hide file tree
Showing 9 changed files with 45 additions and 49 deletions.
2 changes: 1 addition & 1 deletion src/characters.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ int Game::yHeadRandom() {
return yRandom;
}
}

// Inisialization Start Position
void Game::startPosition() {
xBody.resize(1000);
Expand Down Expand Up @@ -82,7 +83,6 @@ void Game::resetSnake() {

bool checkingCollison;


// ensure there are no more collisions between the head and the body after the game over
do {
startPosition();
Expand Down
8 changes: 0 additions & 8 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,6 @@ int main() {
}

Map->Menu();
//Map->chooseSkin();
// Map->buySkin();
//Map->vSkin();
//Map->showSuccessPopUp();
//Map->showConfirmPopUp();
//Map->render();
// Map->GameOver();
// Map->ShowPopUpGameOver();
}

catch(const char* error) {
Expand Down
2 changes: 1 addition & 1 deletion src/menu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ void Game::Menu() {
} else if(highlight == 1) {
buySkin();
} else if(highlight == 2) {
ShowBestScore();
ShowHighestScore();
} else if(highlight == 3) {
chooseSkin();
} else {
Expand Down
18 changes: 15 additions & 3 deletions src/money.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* #########################################
*
* File: shop.cpp
* File: menu.cpp
*
* Author : Bagus Koko Wibawanto
*
Expand All @@ -18,7 +18,6 @@ void Game::showCoin() {
werase(CoinMap);
box(CoinMap, 0, 0);
noecho();
//moneyString = std::to_string(money);

mvwprintw(CoinMap, 1, 4, "[ $ ");
mvwprintw(CoinMap, 1, 9, moneyString.c_str());
Expand All @@ -39,12 +38,25 @@ int Game::rewardMoney() {
reward = 2;
} else if(point < 40) {
reward = 3;
} else {
} else if(point < 50) {
reward = 4;
} else if(point < 60) {
reward = 5;
} else if(point < 70) {
reward = 6;
} else if(point < 80) {
reward = 7;
} else if(point < 90) {
reward = 8;
} else if(point < 100) {
reward = 9;
} else {
reward = 10;
}
return reward;
}

// Payment Process
bool Game::PayProcess(int moneyCurrent, int cost) {
bool success;
int resultMoney;
Expand Down
1 change: 0 additions & 1 deletion src/popup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ bool Game::ShowPopUpGameOver() {
case 'q':
exit = true;
removeScoreWindow();
//GameOver();
break;
default:
break;
Expand Down
8 changes: 4 additions & 4 deletions src/removewindow.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* #########################################
*
* File: control.cpp
* File: removewindow.cpp
*
* Author : Bagus Koko Wibawanto
*
Expand Down Expand Up @@ -31,9 +31,9 @@ void Game::removeSuccessWindow() {
}

void Game::removeHighScoreWindow() {
werase(BestScoreWindow);
wrefresh(BestScoreWindow);
box(BestScoreWindow, 0, 0);
werase(HighestScoreWindow);
wrefresh(HighestScoreWindow);
box(HighestScoreWindow, 0, 0);
}

void Game::removeShopWindow() {
Expand Down
20 changes: 10 additions & 10 deletions src/score.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,25 +27,25 @@ void Game::UpdateScore(WINDOW* Score, int pointNow) {
}

// Show Best Score
void Game::ShowBestScore() {
void Game::ShowHighestScore() {
removeMenuWindow();
refresh();
curs_set(FALSE);
noecho();
box(BestScoreWindow, 0, 0);
wrefresh(BestScoreWindow);
keypad(BestScoreWindow, TRUE);
box(HighestScoreWindow, 0, 0);
wrefresh(HighestScoreWindow);
keypad(HighestScoreWindow, TRUE);
readData();
bool exit = false;

while(exit != true) {
mvwprintw(BestScoreWindow, 0, 0, "[ q ]");
mvwprintw(BestScoreWindow, 0, 6, "[ r ]");
mvwprintw(BestScoreWindow, 2, 7, "High Score");
mvwprintw(BestScoreWindow, 4, 11, highScoreString.c_str());
mvwprintw(HighestScoreWindow, 0, 0, "[ q ]");
mvwprintw(HighestScoreWindow, 0, 6, "[ r ]");
mvwprintw(HighestScoreWindow, 2, 7, "High Score");
mvwprintw(HighestScoreWindow, 4, 11, highScoreString.c_str());
refresh();

int choice = wgetch(BestScoreWindow);
int choice = wgetch(HighestScoreWindow);

switch(choice) {
case 'q':
Expand All @@ -58,6 +58,6 @@ void Game::ShowBestScore() {
break;
}

box(BestScoreWindow, 0, 0);
box(HighestScoreWindow, 0, 0);
}
}
2 changes: 1 addition & 1 deletion src/shop.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* #########################################
*
* File: skin.cpp
* File: shop.cpp
*
* Author : Bagus Koko Wibawanto
*
Expand Down
33 changes: 13 additions & 20 deletions src/skin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ bool Game::chooseSkin() {
int xMenuWindow[5] = {7, 7, 7, 7, 7};
SkinPreview();
wrefresh(SkinMenuWindow);
//wrefresh(ShadowMap);
readDataCollectionSkin();

while(exit != true) {
Expand All @@ -47,7 +46,7 @@ bool Game::chooseSkin() {
mvwprintw(SkinMenuWindow, 18, 15, "Press Space To Select");

for(int i = 0; i < 4; i++) {
if(i == highlight) {
if(i == highlightSkinMenu) {
wattron(SkinMenuWindow, A_REVERSE);
if(skinCollection[i] == "Qi" || skinCollection[i] == "Ziro" || skinCollection[i] == "Ate" || skinCollection[i] == "The G") {
mvwprintw(SkinMenuWindow, yMenuWindow[i], xMenuWindow[i], skinCollection[i].c_str());
Expand All @@ -62,7 +61,7 @@ bool Game::chooseSkin() {
readDataSkin();

// Show Detail Selected Skin
if(skinSelected == highlight) {
if(skinSelected == highlightSkinMenu) {
for(int i = 0; i < skinCollectionCount; i++) {
if(skinCollection[i] == "Qi" || skinCollection[i] == "Ziro" || skinCollection[i] == "Ate" || skinCollection[i] == "The G") {
ensureSkinCollectionHaveValue.at(i) = "True";
Expand All @@ -87,21 +86,21 @@ bool Game::chooseSkin() {

switch(choice) {
case KEY_UP:
if(highlight == 0) {
highlight = 0;
if(highlightSkinMenu == 0) {
highlightSkinMenu = 0;
break;
}
highlight--;
highlightSkinMenu--;
break;
case KEY_DOWN:
if(highlight == skinCollectionCount - 1) {
highlight = skinCollectionCount - 1;
if(highlightSkinMenu == skinCollectionCount - 1) {
highlightSkinMenu = skinCollectionCount - 1;
break;
}
highlight++;
highlightSkinMenu++;
break;
case ' ':
skinSelected = highlight;
skinSelected = highlightSkinMenu;
saveDataSkin();
break;
case 'q':
Expand All @@ -111,12 +110,6 @@ bool Game::chooseSkin() {
default:
break;
}

//werase(Map);
//box(Map, 0, 0);
//refresh();
//wrefresh(Map);

}

// At below, change head snake that use when playing game
Expand All @@ -136,13 +129,13 @@ bool Game::chooseSkin() {
bool Game::SkinPreview() {
werase(SkinPreviewWindow);
box(SkinPreviewWindow, 0, 0);
if(highlight == 0) {
if(highlightSkinMenu == 0) {
mvwprintw(SkinPreviewWindow, 2, 6, "Q+++");
} else if(highlight == 1) {
} else if(highlightSkinMenu == 1) {
mvwprintw(SkinPreviewWindow, 2, 6, "0+++");
} else if(highlight == 2) {
} else if(highlightSkinMenu == 2) {
mvwprintw(SkinPreviewWindow, 2, 6, "@+++");
} else if(highlight == 3) {
} else if(highlightSkinMenu == 3) {
mvwprintw(SkinPreviewWindow, 2, 6, "G+++");
}

Expand Down

0 comments on commit 385da0c

Please sign in to comment.