-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhighroller.c
228 lines (186 loc) · 8.21 KB
/
highroller.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
//SlotMachine Arcade Game NES Style, Noriel Gala, 12/3/24
#include <stdio.h>
#include <stdlib.h>
#include <windows.h> // for system("cls") & Sleep
#include <time.h> //for delay
#include <conio.h> // for _kbhit() and _getch()
#include <mmsystem.h> // for sound functions
#include <stdarg.h> // for variable arguments
//Most of the UI & Quality of Life was done by AI, I made the spinning slots mechanic
void gotoxy(int x, int y) { //handles cursur position for writing text (AI)
COORD coord = {x - 1, y - 1}; // 0-based indexing
SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), coord);
}
void printCentered(const char *format, int y, ...) { //Centers Text (AI)
CONSOLE_SCREEN_BUFFER_INFO csbi;
GetConsoleScreenBufferInfo(GetStdHandle(STD_OUTPUT_HANDLE), &csbi);
int consoleWidth = csbi.srWindow.Right - csbi.srWindow.Left + 1; //width of screen
va_list args;
va_start(args, y);
char buffer[1024]; // Buffer to hold the formatted string
int textLength = vsprintf(buffer, format, args);
va_end(args);
int x = (consoleWidth - textLength) / 2;
COORD coord = {x, y - 1}; // 0-based indexing
SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), coord);
va_start(args, y);
vprintf(format, args);
va_end(args);
}
void setConsoleFullscreen() { //Fullscreens the game upon opening (AI)
HANDLE hOut = GetStdHandle(STD_OUTPUT_HANDLE);
COORD largestSize = GetLargestConsoleWindowSize(hOut);
SMALL_RECT windowSize = {0, 0, largestSize.X - 1, largestSize.Y - 1};
SetConsoleWindowInfo(hOut, TRUE, &windowSize);
SetConsoleScreenBufferSize(hOut, largestSize);
}
void displayMenu(const char *asciiArt[], int lines, int playerMoney) { //Used to display the main game title
system("cls");
// Display High Roller title
for (int i = 0; i < lines; i++) {
printCentered(asciiArt[i], 5 + i);
}
// Display the player's current balance
printCentered("Current balance: $%d", 11, playerMoney);
// Display menu options
printCentered("Press (1) to play normal mode", 14);
printCentered("Press (2) to visit the shop", 15);
printCentered("Press (3) to view stats", 16);
printCentered("Press (q) to quit game (exit)", 17);
}
void displayShop(int playerMoney) { //Displays shop (AI)
system("cls");
printCentered("Welcome to the Shop!", 5);
printCentered("1. Buy Luck Enhancer (+1 winning chance) - $10", 7);
printCentered("Current balance: $%d", 9, playerMoney);
printCentered("Press (b) to buy, (m) to return to the main menu", 11);
}
void playNormalMode(int *playerMoney, int *luckEnhancers, int *totalCashEarned, int *timesWon, int *moneySpent) {
int a, b, c;
char playAgain;
float winChance = 0.01 + (*luckEnhancers * 0.01); // Base 1% chance, each enhancer adds 1% more
// Display instructions to start the game
system("cls");
printCentered("\n\t\t***-: press any key to play the game :-***", 5);
// Wait for a key press once and clear it
while (!_kbhit()); // Wait for a key press
_getch(); // Clear the key press from the buffer
do {
srand((unsigned int)time(NULL));
system("cls");
printCentered("\n\t\t***-: press any key to play the game :-***", 5);
if (_kbhit()) {
_getch(); // Clear any buffered input
}
system("cls");
PlaySound("spinning.wav", NULL, SND_ASYNC | SND_FILENAME); // Play spinning sound effects
DWORD startTime = GetTickCount();
DWORD elapsedTime = 0; //sets timer to 0
while (elapsedTime < 5000) { // Spin for 5 seconds
Sleep(80);
a = rand() % 10;
b = rand() % 10;
c = rand() % 10;
char numbers[20];
sprintf(numbers, "%d %d %d", a, b, c);
printCentered(numbers, 12);
fflush(stdout);
elapsedTime = GetTickCount() - startTime; //stops timer at 5 seconds
}
PlaySound(NULL, 0, SND_PURGE);
//from Float winprobability to printCentered(Won the game) everything except the PlaySound Jackpot is AI
float winProbability = (float)rand() / RAND_MAX;
if (winProbability < winChance) {
*playerMoney += 1000; // Player wins 1,000x the buy-in
*totalCashEarned += 1000;
(*timesWon)++;
PlaySound("jackpot.wav", NULL, SND_ASYNC | SND_FILENAME); //Plays sound effect when you win
printCentered("***-: You Won The Game! :-***", 12);
} else {
*playerMoney -= 1; // Deduct 1 dollar for the roll
*moneySpent += 1;
printCentered("***-: You Lost The Game. :-***", 12);
}
printCentered("\nWould you like to play again? (y/n) or return to main menu (m): ", 14); //Asks if they'd like to play again return to main menu
playAgain = _getch();
if (playAgain == 'n' || playAgain == 'N') {
printf("Exiting the game...\n");
exit(0);
} else if (playAgain == 'm' || playAgain == 'M') {
printf("Returning to the main menu...\n");
PlaySound("themesong.wav", NULL, SND_ASYNC | SND_FILENAME | SND_LOOP); //Plays themesong once returning to main menu is chosen
return;
}
} while (playAgain == 'y' || playAgain == 'Y');
printf("Thank you for playing!\n");
}
void shop(int *playerMoney, int *luckEnhancers) { //Displays shop (AI)
char choice;
do {
displayShop(*playerMoney);
choice = _getch();
if (choice == 'b' || choice == 'B') {
if (*playerMoney >= 10) {
*playerMoney -= 10;
(*luckEnhancers)++;
printf("Luck enhancer purchased! Current enhancers: %d\n", *luckEnhancers);
} else {
printf("Insufficient funds to buy a Luck Enhancer.\n");
}
} else if (choice == 'm' || choice == 'M') {
printf("Returning to the main menu...\n");
return;
}
} while (choice != 'm' && choice != 'M');
}
void displayStats(int totalCashEarned, int timesWon, int moneySpent) { //Displays stats menu (AI)
system("cls");
printCentered("Game Statistics", 5);
printCentered("Total Cash Earned: $%d", 7, totalCashEarned);
printCentered("Total Times Won: %d", 8, timesWon);
printCentered("Total Money Spent: $%d", 9, moneySpent);
printCentered("Press any key to return to the main menu", 11);
_getch(); //devours key used to return back to main menu
}
int main() {
const char *asciiArt[] = {
" _ _ _ _ ______ _ _ ",
"| | | (_) | | | ___ \\ | | | ",
"| |_| |_ __ _| |__ | |_/ /___ | | | ___ _ __ ",
"| _ | |/ _` | '_ \\ | // _ \\| | |/ _ \\ '__|",
"| | | | | (_| | | | | | |\\ \\ (_) | | | __/ | ",
"\\_| |_/_|\\__, |_| |_| \\_| \\\\___/|_|_|\\___|_| ",
" __/ | ",
" |___/ "
};
//beautiful ascii art, I used AI to Format it correctly,
//starting stats, spinning costs 1 dollar
int playerMoney = 100;
int luckEnhancers = 0;
int totalCashEarned = 0;
int timesWon = 0;
int moneySpent = 0;
//Fullscreens the game upon opening .exe (AI)
system("mode con: cols=700 lines=700");
keybd_event(VK_MENU, 0x38, 0, 0); // Press ALT
keybd_event(VK_RETURN, 0x1C, 0, 0); // Press ENTER
keybd_event(VK_RETURN, 0x1C, KEYEVENTF_KEYUP, 0); // Release ENTER
keybd_event(VK_MENU, 0x38, KEYEVENTF_KEYUP, 0); // Release ALT
setConsoleFullscreen();
PlaySound("themesong.wav", NULL, SND_ASYNC | SND_FILENAME | SND_LOOP); //Plays theme song
while (1) { //Gets data for stat menu (AI)
displayMenu(asciiArt, 7, playerMoney);
char choice = _getch();
if (choice == '1') {
playNormalMode(&playerMoney, &luckEnhancers, &totalCashEarned, ×Won, &moneySpent);
} else if (choice == '2') {
shop(&playerMoney, &luckEnhancers);
} else if (choice == '3') {
displayStats(totalCashEarned, timesWon, moneySpent);
} else if (choice == 'q' || choice == 'Q') {
printf("Quitting game...\n");
exit(0);
}
}
return 0;
}