Created
August 5, 2020 14:14
-
-
Save jsudiaman/c9dca4019559819a415b3aabae44cca5 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
Yugioh Lifepoint Calculator (bit.ly/2ag7YBZ) | |
Programmed by Jonathan Sudiaman | |
Main Features: Inbuilt Calculator, Yu-Jo Friendship | |
Dice and Coin, and Turn Counter | |
2011-10-28: Released v1.0 | |
2016-07-27: Modified the SYSTEM calls for portability | |
*/ | |
// Just a quick note about the turn counter: Its use is for stuff like Final Countdown | |
// or Golden Sarcophagus. It can be incremented or reset. I didnt include decrement, however. | |
#include <iostream> | |
#include <time.h> | |
#include <iomanip> | |
#ifdef _WIN32 | |
#define CLS "CLS" | |
#define PAUSE "PAUSE" | |
#else | |
#define CLS "clear" | |
#define PAUSE "read -rsp $'Press any key to continue...\n' -n 1 key" | |
#endif | |
using namespace std; | |
int playercheck(); | |
int calc(); | |
int main() | |
{ | |
int wins = 0; | |
int losses = 0; | |
begin: // Re-initializes everything for the new round | |
srand(time(NULL)); | |
int p1 = 8000; // Modify if you play with less LP | |
int p2 = 8000; | |
int turn = 0; | |
int damage; | |
int selectedp; | |
int choicex; | |
char choicexyz; // Next Round | |
int average; // Yu-Jo | |
int choiceyy; | |
int dice; | |
int choice; | |
int coin; | |
int constlp = 0; // Constant LP | |
int choicezz; | |
int intro = 0; | |
while((p1>0) && (p2>0)) // Victory Check | |
{ | |
// Begin Main Menu // | |
cout << "Your life: " << p1 << '\n'; | |
cout << "Your opponent's: " << p2 << '\n'; | |
cout << "Turn number: " << turn << '\n'; | |
cout << " " << '\n'; | |
cout << "1 - Deal Damage" << '\n'; | |
cout << "2 - Add Life" << '\n'; | |
cout << "3 - Use Calculator" << '\n'; | |
cout << "4 - Turn Count" << '\n'; | |
cout << "5 - Turn Count Reset" << '\n'; | |
cout << "6 - Six Sided Dice Roll" << '\n'; | |
cout << "7 - Coin Toss" << '\n'; | |
cout << "8 - Custom LP Modification" << '\n'; | |
cout << "9 - Add or Subtract " << constlp << " LP from a player" << '\n'; | |
cout << "10 - Change the above amount of LP" << '\n'; | |
cout << " " << endl; | |
// End Main Menu // | |
cin >> choice; | |
switch(choice) | |
{ | |
case 1: // Damage | |
{ | |
cout << "How much? "; | |
cin >> damage; | |
selectedp = playercheck(); | |
if(selectedp == 1) | |
p1 -= damage; | |
else | |
p2 -= damage; | |
system(CLS); | |
break; | |
} | |
case 2: // Add Life | |
{ | |
cout << "How much? "; | |
cin >> damage; | |
selectedp = playercheck(); | |
if(selectedp == 1) | |
p1 += damage; | |
else | |
p2 += damage; | |
system(CLS); | |
break; | |
} | |
case 3: // Use Calculator | |
{ | |
system(CLS); | |
cout << "Select an option: " << '\n'; | |
cout << "1 - Double LP" << '\n'; | |
cout << "2 - Halve LP" << '\n'; | |
cout << "3 - Average both LP (Yu-Jo Friendship)" << '\n'; | |
cout << "4 - Perform Calculation" << '\n'; | |
cin >> choicex; | |
switch(choicex) | |
{ | |
case 1: // Double LP | |
{ | |
selectedp = playercheck(); // This is to check which player takes damage, you'll see this throught the code | |
if(selectedp == 1) | |
p1 *= 2; | |
else | |
p2 *= 2; | |
system(CLS); | |
break; | |
} | |
case 2: // Halve LP | |
{ | |
selectedp = playercheck(); | |
if(selectedp == 1) | |
p1 /= 2; | |
else | |
p2 /= 2; | |
system(CLS); | |
break; | |
} | |
case 3: // Average LP | |
{ | |
average = (p1 + p2); | |
average /= 2; | |
p1 = average; | |
p2 = average; | |
system(CLS); | |
break; | |
} | |
case 4: // Perform a calculation | |
{ | |
damage = calc(); | |
system(CLS); | |
cout << "The result was " << damage << '\n'; | |
cout << "1 - Deal as damage to a player" << '\n'; | |
cout << "2 - Add to player's LP" << '\n'; | |
cout << "3 - Return to main menu" << '\n'; | |
cin >> choiceyy; | |
switch(choiceyy) | |
{ | |
case 1: | |
{ | |
system(CLS); | |
cout << "Your life: " << p1 << '\n'; | |
cout << "Your opponent's: " << p2 << '\n'; | |
selectedp = playercheck(); | |
if(selectedp == 1) | |
p1 -= damage; | |
else | |
p2 -= damage; | |
break; | |
} | |
case 2: | |
{ | |
system(CLS); | |
cout << "Your life: " << p1 << '\n'; | |
cout << "Your opponent's: " << p2 << '\n'; | |
selectedp = playercheck(); | |
if(selectedp == 1) | |
p1 += damage; | |
else | |
p2 += damage; | |
break; | |
} | |
case 3: | |
{ | |
break; | |
} | |
default: | |
{ | |
break; | |
} | |
} | |
system(CLS); | |
break; | |
} | |
} | |
default: // If invalid, just goes back to main menu. | |
{ | |
system(CLS); | |
break; | |
} | |
break; | |
} // Case 3 Brace | |
case 4: | |
{ | |
turn++; | |
system(CLS); | |
break; | |
} | |
case 5: | |
{ | |
turn = 0; | |
system(CLS); | |
break; | |
} | |
case 6: | |
{ | |
system(CLS); | |
dice = rand()%6+1; | |
cout << "You rolled a: " << dice << '\n'; | |
system(PAUSE); | |
system(CLS); | |
break; | |
} | |
case 7: | |
{ | |
system(CLS); | |
coin = rand()%2+1; | |
if(coin == 1) | |
cout << "Result is Heads." << '\n'; | |
else | |
cout << "Result is Tails." << '\n'; | |
system(PAUSE); | |
system(CLS); | |
break; | |
} | |
case 8: | |
{ | |
cout << "Enter the amount of LP: "; | |
cin >> damage; | |
selectedp = playercheck(); | |
if(selectedp == 1) | |
p1 = damage; | |
else | |
p2 = damage; | |
system(CLS); | |
break; | |
} | |
case 9: | |
{ | |
damage = constlp; | |
system(CLS); | |
cout << "1 - Deal as damage" << '\n'; | |
cout << "2 - Add as life gain" << '\n'; | |
cin >> choicezz; | |
if(choicezz == 1) | |
{ | |
selectedp = playercheck(); | |
if(selectedp == 1) | |
p1 -= damage; | |
else | |
p2 -= damage; | |
} | |
else | |
{ | |
selectedp = playercheck(); | |
if(selectedp == 1) | |
p1 += damage; | |
else | |
p2 += damage; | |
} | |
system(CLS); | |
break; | |
} | |
case 10: | |
{ | |
cout << "Enter amount to change to : "; | |
cin >> constlp; | |
system(CLS); | |
break; | |
} | |
} // Switch Brace | |
}// Victory Check Brace | |
if(p2 <= 0) | |
{ | |
cout << "Congratulations, you are the winner." << '\n'; | |
wins++; | |
} | |
else | |
{ | |
cout << "You have lost." << '\n'; | |
losses++; | |
} | |
if(wins == 2 || losses == 2) // Is the match over? | |
{ | |
if(wins == 2) | |
{ | |
cout << "You have won the match." << '\n'; | |
system(PAUSE); | |
} | |
else | |
{ | |
cout << "You have lost the match." << '\n'; | |
system(PAUSE); | |
} | |
} | |
else | |
{ | |
cout << "Current Wins: " << wins << '\n'; | |
cout << "Current Losses: " << losses << '\n'; | |
cout << "" << endl; | |
cout << "Would you like to begin the next round? [Y/N] "; | |
cin >> choicexyz; | |
if(choicexyz == 'Y' || choicexyz == 'y') | |
{ | |
p1 = 8000; | |
p2 = 8000; | |
turn = 0; | |
system(CLS); | |
goto begin; | |
} | |
} // Match Brace | |
}// Main Brace | |
int playercheck() // Checks which player | |
{ | |
retry: | |
int value; | |
cout << "To which player? [1 = You. 2 = Opponent.] "; | |
cin >> value; | |
if (value != 1 && value !=2) | |
{ | |
cout << "Try again.." << '\n'; | |
goto retry; | |
} | |
return(value); | |
} | |
int calc() | |
{ | |
system(CLS); | |
int sum = 0; | |
char choicechar; | |
int delocaldmg; | |
cout << "Enter a number to intialize as your sum: "; | |
cin >> sum; | |
system(CLS); | |
menu: | |
// How this works is a player enters a letter to do an operation, hits enter. | |
// They then enter the amount, hits enter. | |
// The operation is applied to the sum, which is whatever number it is initialized to by the user. | |
// Then after, the player is allowed to add or subtract it from someone's LP. | |
cout << "Sum: " << sum << '\n'; | |
cout << "A - Add a number to the sum" << '\n'; | |
cout << "S - Subtract a number from the sum" << '\n'; | |
cout << "M - Multiply the sum by a number" << '\n'; | |
cout << "D - Divide the sum by a number" << '\n'; | |
cout << "B - Back to calculator" << '\n'; | |
cin >> choicechar; | |
while(choicechar != 'A' && choicechar != 'S' && choicechar != 'M' && choicechar != 'D' && choicechar != 'B' | |
&& choicechar != 'a' && choicechar != 's' && choicechar != 'm' && choicechar != 'd' && choicechar != 'b') | |
{ | |
cout << "Invalid entry. Try again." << '\n'; | |
cin >> choicechar; | |
} | |
if(choicechar != 'B' && choicechar != 'b') | |
{ | |
cout << "Enter the amount: "; | |
cin >> delocaldmg; | |
} | |
switch(choicechar) | |
{ | |
case 'A': | |
{ | |
sum += delocaldmg; | |
system(CLS); | |
goto menu; | |
break; | |
} | |
case 'a': | |
{ | |
sum += delocaldmg; | |
system(CLS); | |
goto menu; | |
break; | |
} | |
case 'S': | |
{ | |
sum -= delocaldmg; | |
system(CLS); | |
goto menu; | |
break; | |
} | |
case 's': | |
{ | |
sum -= delocaldmg; | |
system(CLS); | |
goto menu; | |
break; | |
} | |
case 'M': | |
{ | |
sum *= delocaldmg; | |
system(CLS); | |
goto menu; | |
break; | |
} | |
case 'm': | |
{ | |
sum *= delocaldmg; | |
system(CLS); | |
goto menu; | |
break; | |
} | |
case 'D': | |
{ | |
sum /= delocaldmg; | |
system(CLS); | |
goto menu; | |
break; | |
} | |
case 'd': | |
{ | |
sum /= delocaldmg; | |
system(CLS); | |
goto menu; | |
break; | |
} | |
case 'B': | |
{ | |
return(sum); | |
break; | |
} | |
case 'b': | |
{ | |
return(sum); | |
break; | |
} | |
} | |
return(sum); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment