ADD BANK + BJ + SLOTS + DICEROLL
This commit is contained in:
parent
4d166209bc
commit
933c9976e3
291
main.cpp
291
main.cpp
@ -1,9 +1,12 @@
|
||||
#include <iostream>
|
||||
#include <cstdlib>
|
||||
#include <ctime>
|
||||
#include <unistd.h>
|
||||
|
||||
using namespace std;
|
||||
char end_choice;
|
||||
int balance = 0;
|
||||
int bank_balance = 10000;
|
||||
|
||||
void coinflip() {
|
||||
srand(time(0)); // Seed the random number generator
|
||||
@ -17,7 +20,7 @@ void coinflip() {
|
||||
// Check if the user has enough balance
|
||||
if (bet_amount > balance) {
|
||||
cout << "You don't have enough NyscoCoins! Please try again with a lower amount." << endl;
|
||||
return;
|
||||
sleep(3);
|
||||
}
|
||||
|
||||
// Deduct the bet amount from the balance
|
||||
@ -30,7 +33,7 @@ void coinflip() {
|
||||
if (user_choice != 'H' && user_choice != 'h' && user_choice != 'T' && user_choice != 't') {
|
||||
cout << "Invalid choice. Please enter either H for Heads or T for Tails." << endl;
|
||||
balance += bet_amount; // Return the bet amount if invalid input
|
||||
return;
|
||||
coinflip();
|
||||
}
|
||||
|
||||
// Generate a random result: 0 for Heads, 1 for Tails
|
||||
@ -40,7 +43,7 @@ void coinflip() {
|
||||
cout << "The coin is flipping..." << endl;
|
||||
|
||||
// Wait a moment to simulate flipping
|
||||
system("pause");
|
||||
sleep(3);
|
||||
|
||||
if (flip_result == 0) {
|
||||
cout << "The result is Heads!" << endl;
|
||||
@ -50,36 +53,257 @@ void coinflip() {
|
||||
|
||||
// Check if the user won or lost
|
||||
if ((user_choice == 'H' || user_choice == 'h') && flip_result == 0) {
|
||||
system("cls");
|
||||
cout << "Congratulations! You won! You get double the bet amount." << endl;
|
||||
balance += 2 * bet_amount;
|
||||
} else if ((user_choice == 'T' || user_choice == 't') && flip_result == 1) {
|
||||
system("cls");
|
||||
cout << "Congratulations! You won! You get double the bet amount." << endl;
|
||||
balance += 2 * bet_amount;
|
||||
} else {
|
||||
system("cls");
|
||||
cout << "Sorry! You lost the bet. Better luck next time!" << endl;
|
||||
}
|
||||
|
||||
cout << "Your new balance is: " << balance << " NyscoCoins" << endl;
|
||||
|
||||
cout << "Play again? (Y/N): ";
|
||||
cin >> end_choice;
|
||||
|
||||
if (end_choice == 'y' || end_choice == 'Y') {
|
||||
system("cls");
|
||||
coinflip();
|
||||
} else {
|
||||
system("cls");
|
||||
}
|
||||
}
|
||||
|
||||
void slots() {
|
||||
// Slots game logic here
|
||||
srand(time(0));
|
||||
int bet_amount;
|
||||
char end_choice;
|
||||
|
||||
cout << "Enter the amount of money you want to bet on slots: ";
|
||||
cin >> bet_amount;
|
||||
|
||||
if (bet_amount > balance) {
|
||||
cout << "You don't have enough NyscoCoins! Please try again with a lower amount." << endl;
|
||||
sleep(3);
|
||||
}
|
||||
|
||||
balance -= bet_amount;
|
||||
|
||||
cout << "Spinning the slots..." << endl;
|
||||
sleep(2);
|
||||
|
||||
int slot1 = rand() % 5 + 1;
|
||||
int slot2 = rand() % 5 + 1;
|
||||
int slot3 = rand() % 5 + 1;
|
||||
|
||||
cout << "| " << slot1 << " | " << slot2 << " | " << slot3 << " |" << endl;
|
||||
|
||||
if (slot1 == slot2 && slot2 == slot3) {
|
||||
cout << "JACKPOT! You won triple your bet amount!" << endl;
|
||||
balance += 3 * bet_amount;
|
||||
} else if (slot1 == slot2 || slot2 == slot3 || slot1 == slot3) {
|
||||
cout << "Nice! You won double your bet amount!" << endl;
|
||||
balance += 2 * bet_amount;
|
||||
} else {
|
||||
cout << "You lost! Better luck next time!" << endl;
|
||||
}
|
||||
|
||||
cout << "Your new balance is: " << balance << " NyscoCoins" << endl;
|
||||
|
||||
cout << "Play again? (Y/N): ";
|
||||
cin >> end_choice;
|
||||
|
||||
if (end_choice == 'y' || end_choice == 'Y') {
|
||||
system("cls");
|
||||
slots();
|
||||
} else {
|
||||
system("cls");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void blackjack() {
|
||||
srand(time(0));
|
||||
int playerCard1 = rand() % 11 + 1;
|
||||
int playerCard2 = rand() % 11 + 1;
|
||||
int dealerCard1 = rand() % 11 + 1;
|
||||
int dealerCard2 = rand() % 11 + 1;
|
||||
int playerTotal = playerCard1 + playerCard2;
|
||||
int dealerTotal = dealerCard1 + dealerCard2;
|
||||
int bet_amount;
|
||||
char end_choice;
|
||||
|
||||
cout << "Your cards: " << playerCard1 << " and " << playerCard2 << " (Total: " << playerTotal << ")" << endl;
|
||||
cout << "Dealer's visible card: " << dealerCard1 << endl;
|
||||
|
||||
cout << "Enter your bet amount: ";
|
||||
cin >> bet_amount;
|
||||
|
||||
if (bet_amount > balance) {
|
||||
cout << "You don't have enough NyscoCoins! Please try again with a lower amount." << endl;
|
||||
sleep(3);
|
||||
}
|
||||
|
||||
balance -= bet_amount;
|
||||
|
||||
char choice;
|
||||
do {
|
||||
cout << "Do you want to hit (H) or stand (S)? ";
|
||||
cin >> choice;
|
||||
|
||||
if (choice == 'H' || choice == 'h') {
|
||||
int newCard = rand() % 11 + 1;
|
||||
playerTotal += newCard;
|
||||
cout << "You drew a " << newCard << ". Your total is now " << playerTotal << "." << endl;
|
||||
|
||||
if (playerTotal > 21) {
|
||||
cout << "You bust! Dealer wins." << endl;
|
||||
}
|
||||
}
|
||||
} while (choice == 'H' || choice == 'h');
|
||||
|
||||
cout << "Dealer's turn. Dealer's total is " << dealerTotal << "." << endl;
|
||||
|
||||
while (dealerTotal < 17) {
|
||||
int newCard = rand() % 11 + 1;
|
||||
dealerTotal += newCard;
|
||||
cout << "Dealer drew a " << newCard << ". Dealer's total is now " << dealerTotal << "." << endl;
|
||||
}
|
||||
|
||||
if (dealerTotal > 21 || playerTotal > dealerTotal) {
|
||||
cout << "You win! You gain " << bet_amount << " NyscoCoins." << endl;
|
||||
balance += 2 * bet_amount; // Win pays 2:1
|
||||
} else if (playerTotal < dealerTotal) {
|
||||
cout << "Dealer wins! You lose your bet." << endl;
|
||||
} else {
|
||||
cout << "It's a tie! Your bet is returned." << endl;
|
||||
balance += bet_amount; // Return bet
|
||||
}
|
||||
|
||||
cout << "Your new balance is: " << balance << " NyscoCoins" << endl;
|
||||
|
||||
cout << "Play again? (Y/N): ";
|
||||
cin >> end_choice;
|
||||
|
||||
if (end_choice == 'y' || end_choice == 'Y') {
|
||||
system("cls");
|
||||
blackjack();
|
||||
} else {
|
||||
system("cls");
|
||||
}
|
||||
}
|
||||
|
||||
void roulette() {
|
||||
cout << "Roulette game logic coming soon!" << endl;
|
||||
}
|
||||
|
||||
void diceRoll() {
|
||||
srand(time(0));
|
||||
int bet_amount, outcome;
|
||||
char end_choice;
|
||||
|
||||
cout << "Enter the amount of money you want to bet on dice roll: ";
|
||||
cin >> bet_amount;
|
||||
|
||||
cout << "Guess the outcome: ";
|
||||
cin >> outcome;
|
||||
|
||||
if (bet_amount > balance) {
|
||||
cout << "You don't have enough NyscoCoins! Please try again with a lower amount." << endl;
|
||||
sleep(3);
|
||||
diceRoll();
|
||||
}
|
||||
|
||||
if (outcome > 12) {
|
||||
cout << "There are only two dices max number is 12" << endl;
|
||||
sleep(3);
|
||||
diceRoll();
|
||||
}
|
||||
|
||||
balance -= bet_amount;
|
||||
|
||||
cout << "Rolling the dice..." << endl;
|
||||
sleep(2);
|
||||
|
||||
int dice1 = rand() % 6 + 1;
|
||||
int dice2 = rand() % 6 + 1;
|
||||
int total = dice1 + dice2;
|
||||
|
||||
cout << "You rolled: " << dice1 << " and " << dice2 << " (Total: " << total << ")" << endl;
|
||||
|
||||
if (total == 7) {
|
||||
cout << "Congratulations! You won double your bet amount!" << endl;
|
||||
balance += 2 * bet_amount;
|
||||
} else {
|
||||
cout << "You lost! Better luck next time!" << endl;
|
||||
}
|
||||
|
||||
cout << "Your new balance is: " << balance << " NyscoCoins" << endl;
|
||||
|
||||
cout << "Play again? (Y/N): ";
|
||||
cin >> end_choice;
|
||||
|
||||
if (end_choice == 'y' || end_choice == 'Y') {
|
||||
system("cls");
|
||||
diceRoll();
|
||||
} else {
|
||||
system("cls");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void higherOrLower() {
|
||||
cout << "Higher or Lower game logic coming soon!" << endl;
|
||||
}
|
||||
|
||||
void deposit() {
|
||||
int deposit_amount;
|
||||
cout << "Enter the amount of money you want to deposit: ";
|
||||
cin >> deposit_amount;
|
||||
if (bank_balance >= deposit_amount) {
|
||||
balance += deposit_amount;
|
||||
bank_balance -= deposit_amount;
|
||||
system("cls");
|
||||
cout << "Deposit successful! Your new balance is: " << balance << " NyscoCoins"<< endl;
|
||||
sleep(3);
|
||||
system("cls");
|
||||
}
|
||||
else {
|
||||
system("cls");
|
||||
cout << "You don't have enough money in your bank account!" << endl;
|
||||
sleep(3);
|
||||
system("cls");
|
||||
}
|
||||
}
|
||||
|
||||
void withdraw() {
|
||||
int withdraw_amount;
|
||||
cout << "Enter the amount of money you want to deposit: ";
|
||||
cin >> withdraw_amount;
|
||||
if (balance >= withdraw_amount) {
|
||||
balance -= withdraw_amount;
|
||||
bank_balance += withdraw_amount;
|
||||
system("cls");
|
||||
cout << "Deposit successful! Your new balance is: " << balance << " NyscoCoins" << endl;
|
||||
sleep(3);
|
||||
system("cls");
|
||||
}
|
||||
else {
|
||||
system("cls");
|
||||
cout << "You don't have enough NyscoCoins to withdraw!" << endl;
|
||||
sleep(3);
|
||||
system("cls");
|
||||
}
|
||||
}
|
||||
|
||||
int main() {
|
||||
char game_choice;
|
||||
|
||||
do {
|
||||
cout << "Your current balance: " << balance << " NyscoCoins" << endl;
|
||||
cout << R"(
|
||||
_ __ ______ _
|
||||
/ | / /_ ________________ / ____/___ ______(_)___ ____
|
||||
@ -88,48 +312,69 @@ int main() {
|
||||
/_/ |_/\__, /____/\___/\____/ \____/\__,_/____/_/_/ /_/\____/
|
||||
/____/
|
||||
--------------------------------------------------------------------------
|
||||
)" << endl;
|
||||
)" << endl;
|
||||
|
||||
cout << "Your current bank balance: " << bank_balance << "$" << endl;
|
||||
cout << "Your current casino balance: " << balance << " NyscoCoins" << endl;
|
||||
cout << "--------------------" << endl;
|
||||
cout << "CHOOSE THE GAME: " << endl;
|
||||
cout << "--------------------" << endl;
|
||||
cout << "(C) - Coinflip" << endl;
|
||||
cout << "(S) - Slots" << endl;
|
||||
cout << "(D) - Deposit money" << endl;
|
||||
cout << endl;
|
||||
cout << "(Q) - I Don't have more money I'm quitting" << endl;
|
||||
cout << endl;
|
||||
|
||||
cout << "(B) - Blackjack" << endl;
|
||||
cout << "(R) - Roulette (coming soon!)" << endl;
|
||||
cout << "(D) - Dice Roll" << endl;
|
||||
cout << "(H) - Higher or Lower (coming soon!)" << endl;
|
||||
cout << "--------------------" << endl;
|
||||
cout << "(M) - Deposit Money" << endl;
|
||||
cout << "(W) - Withdraw NyscoCoins" << endl;
|
||||
cout << "--------------------" << endl;
|
||||
cout << "(Q) - Quit" << endl;
|
||||
cout << "Enter your choice: ";
|
||||
cin >> game_choice;
|
||||
|
||||
switch (game_choice) {
|
||||
case 'C':
|
||||
case 'c':
|
||||
case 'C': case 'c':
|
||||
system("cls");
|
||||
coinflip();
|
||||
break;
|
||||
|
||||
case 'S':
|
||||
case 's':
|
||||
case 'S': case 's':
|
||||
system("cls");
|
||||
slots();
|
||||
break;
|
||||
|
||||
case 'D':
|
||||
case 'd':
|
||||
case 'B': case 'b':
|
||||
system("cls");
|
||||
blackjack();
|
||||
break;
|
||||
case 'R': case 'r':
|
||||
system("cls");
|
||||
roulette();
|
||||
break;
|
||||
case 'D': case 'd':
|
||||
system("cls");
|
||||
diceRoll();
|
||||
break;
|
||||
case 'H': case 'h':
|
||||
system("cls");
|
||||
higherOrLower();
|
||||
break;
|
||||
case 'M': case 'm':
|
||||
system("cls");
|
||||
deposit();
|
||||
break;
|
||||
|
||||
case 'Q':
|
||||
case 'q':
|
||||
case 'W': case 'w':
|
||||
system("cls");
|
||||
withdraw();
|
||||
break;
|
||||
case 'Q': case 'q':
|
||||
cout << "Thanks for playing!" << endl;
|
||||
break;
|
||||
|
||||
default:
|
||||
cout << "Invalid choice. Please try again." << endl;
|
||||
break;
|
||||
}
|
||||
} while (game_choice != 'Q' && game_choice != 'q');
|
||||
|
||||
system("pause");
|
||||
return 0;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user