-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
994 lines (756 loc) · 24.6 KB
/
Copy pathmain.cpp
File metadata and controls
994 lines (756 loc) · 24.6 KB
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
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
/*
*************************************** FRUIT MACHINE *****************************************************
**** Features:
* There are three subjects of games which the user can choose
* Each subject cost a different price
* The user starts with a balance of 0 credits, can top up multiples of 10 or liquidate his balance
* If the user do not have enought credits to pay, that subject will shown in red else green.
* Each subject has a specific theme (music)
* Display 7 columns and 5 rows
* The user can stop column by column from left to right
* There are differents prizes depends on the subject:
* - Special prize (If the user mach the full middle row with the special character)
* - First prize (If the user get a full same characters on row)
* - Second prize (If the user get six same characters on row)
* - Third prize (If the user get five same characters on row)
* The Abertay subject its precial price is match set "A-B-E-R-T-A-Y" in the middle row
**** Creator: FMGD
**** Class: 1st year Computer Games Technology
**** Module: Programming C++ (CMP 104)
**** Year: 2019
**** Contact: 1902654@uad.ac.uk
*/
//1. INCLUDES ///////////////////////////////////////////////
#include <iostream>
#include <vector>
#include <string>
#include <windows.h>
#include <time.h> //For rand()
#include <conio.h> //For _kbhit() -> detect press key
#pragma comment(lib, "Winmm.lib") //For music
using namespace std;
//2. DEFINES ////////////////////////////////////////////////
//3. PROTOTYPES /////////////////////////////////////////////
/*3.1*/
void setSubject();
void setSpecialPrize();
void setSpecialDetails();
void setValues();
void setSlots();
/*3.2*/
void rotateColumn(const int&);
void rotateSlots();
void stopColumn();
void resetSlotsRotation();
/*3.3*/
int getResults();
void displayEndGame();
/*3.4*/
bool paidPlay(const int&);
void addPrizeToBalance(const int&);
/*3.5*/
void checkKeyPress(const int&);
/*3.6*/
void setOutputColor(const int&, const int& = 0);
void predefinedColorsByChar(const char&, const int&);
void printByCharacter(const string&, const int& = 0);
int getColorDependOnBalance(const int&);
/*3.7*/
void printSlots();
void printIntro();
void printLogo();
void printLoading(const int& = 3000);
void printMainMenu();
void printStartRollingMenu();
void printPrizesInfo();
void printInGameMenu();
void printResults(const int&);
void printEndMenu();
void printCredits();
void clearScreen();
/*3.8*/
void playMusic(string, string = "");
//4. GLOBALS ////////////////////////////////////////////////
////4.1 - System/Console
HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
////4.2 - Slots Data
const int NUM_ROWS = 7; //Always has to be a odd number
const int NUM_COLUMNS = 7; //If we modify this value we have to modify the number of column_rolling[]
int middleRow = round(NUM_ROWS / 2.0) - 1; //Main row. It has been susbtracted 1 due to the array start 0
int subject_code = 0; //Subject = 0 = Not subject chosen
//Merely illustrative (Default data)
vector<string> values{ "$", "%", "&", "*", "/", "+", "-" }; //All the characters availables to show in slots
string slots[NUM_ROWS][NUM_COLUMNS]{ //Slots. If any new character is added it is neccesary modify values[] and/or ocurrences[] and/or column_rolling[]
{"$", "$", "$", "$", "$", "$", "$"}, //Row 0
{"%", "%", "%", "%", "%", "%", "%"}, //Row 1
{"&", "&", "&", "&", "&", "&", "&"}, //Row 2
{"*", "*", "*", "*", "*", "*", "*"}, //Row 3
{"/", "/", "/", "/", "/", "/", "/"}, //Row 4
{"+", "+", "+", "+", "+", "+", "+"}, //Row 5
{"-", "-", "-", "-", "-", "-", "-"} //Row 6
};
////4.3 - Balance and Prizes Data
int credit = 0; //Money of the user
int prizes[4]{ 5000,1000,100,10 }; //Amount to earn in each prize prize[0] = Special price, prize[1]=first prize, prize[2] = second price...
string special_details; //Info of what character have to mach
////4.4 - State Game and Columns
bool game_running = true; // state of game
bool slots_rolling = false; // state of slots (all)
bool column_rolling[NUM_COLUMNS]{ false, false, false, false, false, false, false }; //Each element represent the state of each column (its state) column_rolling[0] = column 0
bool is_showing_results = false;
//5. FUNCTIONS //////////////////////////////////////////////
////5.1. FUNCTIONS - SET PLAY//////////////////////////////////////////////
void setSubject()
{
//Change Values (characters)
setValues();
//Insert that values in slots
setSlots();
//Reset slots rotation
resetSlotsRotation();
//Set Special prize
setSpecialPrize();
//Set the info message for the special prize of each subject
setSpecialDetails();
}
///////////////////////////////////////////////////////////
void setSpecialPrize()
{
if (subject_code == 3)
prizes[0] = 9000;
else
prizes[0] = 5000;
}
///////////////////////////////////////////////////////////
void setSpecialDetails()
{
special_details = "";
if (subject_code == 3)
{
for (int i = 0; i < NUM_ROWS - 1; i++) //We copy in the same order the characters of values[]
special_details += values[i] + "-";
special_details += values[NUM_ROWS -1];
}
else
{
for (int i = 0; i < NUM_COLUMNS - 1; i++) //We copy one specific character of values[]
special_details += values[middleRow] + "-";
special_details += values[middleRow];
}
}
///////////////////////////////////////////////////////////
void setValues()
{
//Set Values
values.clear();
switch (subject_code)
{
case 1:
values = { "\x8C", "\xA3", "\x80", "7", "?", "!", "\x24" };
break;
case 2:
values = { "\xD8", "\xDF", "\xBD", "\xD7", "=", "\xF7", "%" };
break;
case 3:
values = { "A", "B", "E", "R", "T", "A", "Y" }; //It is neccessary that the letters are in order (word)
break;
}
}
///////////////////////////////////////////////////////////
void setSlots()
{
//Set Slots
for (int i = 0; i < NUM_ROWS; i++)
{
for (int column = 0; column < NUM_COLUMNS; column++)
{
slots[i][column] = values[i]; //Change slotsArray
}
}
}
////5.2. FUNCTIONS - LOGIC (MECHANISMS SLOTS) //////////////////////////////////////////////
void rotateColumn(const int& column)
{
string temp;
temp = slots[NUM_ROWS - 1][column]; //We get the last element in the array
for (int i = NUM_ROWS - 1; i > 0; i--) //This 'for' go over the array from the last element (from the bottom to top)
{
slots[i][column] = slots[i - 1][column]; //Set the current element whith the value of the above element
}
slots[0][column] = temp; //Set the saved element to the first position
}
///////////////////////////////////////////////////////////
void rotateSlots()
{
for (int i = 0; i < NUM_COLUMNS; i++) //Check what columns have to be rotated
{
if (column_rolling[i]) rotateColumn(i); //Only rotate columns which are activated
}
}
///////////////////////////////////////////////////////////
void stopColumn() //Change the status of the column rotation
{
for (int i = 0; i < NUM_COLUMNS; i++) //Check what column has to be stopped
{
if (column_rolling[i]) //Get the first column that is rotating (from left to right)
{
column_rolling[i] = false; //We set that column rotation to false
if (i == NUM_COLUMNS - 1) slots_rolling = false; //The player has stopped the last column is neccessary to check if it has won
break;
}
}
}
/////////////////////////////////////////////////////////
void resetSlotsRotation()
{
for (int i = 0; i < NUM_COLUMNS; i++)
{
column_rolling[i] = true;
}
}
////5.3. FUNCTIONS - LOGIC WIN //////////////////////////////////////////////
int getResults()
{
//Get the middle row
int match_found;
int occurrences[NUM_ROWS] = { 0, 0, 0, 0, 0, 0, 0 }; //Each element correspond to its value in values[]
for (int i = 0; i < NUM_ROWS; i++) //This for go over values[]
{
match_found = 0;
for (int j = 0; j < NUM_COLUMNS; j++) //This array go over the middle row comparing with the character selected in values[i]
{
if (values[i] == slots[middleRow][j])
{
match_found++;
}
}
occurrences[i] = match_found; //here it is saved the number of ocurrences found for one character of values[]
}
if (subject_code == 3 && NUM_ROWS == NUM_COLUMNS) //For special Subjects
{
bool same_order = true; //Check if the middle row is in the same order as values[]
for (int i = 0; i < NUM_ROWS; i++) //This for go over values[]
{
if (values[i] != slots[middleRow][i]) //Compare if the character X on both arrays are in the same position
{
same_order = false;
}
}
if (same_order) return 10; //Special prize for subject 3 'word'
}
//Read array - //Here is the type of prize (Depending on how may matched found)
for (int i = 0; i < NUM_ROWS; i++) {
if (occurrences[i] == NUM_COLUMNS) // First Prize
{
if (i == 4 && subject_code != 3) //If it is a full matched row of the "special character" (values[4])
{
return 10; //Special prize for subject 1, and 2
}
else
return 1; //Normal characters
}
else if (occurrences[i] == NUM_COLUMNS - 1 && (NUM_COLUMNS - 1 > 0)) // Second Price
{
return 2;
}
else if (occurrences[i] == NUM_COLUMNS - 2 && (NUM_COLUMNS - 2 > 0)) // Third Price
{
return 3;
}
}
return -1; //The rest of results, the player has not won.
}
///////////////////////////////////////////////////////////
void displayEndGame()
{
int results = getResults(); //Check the middle Row
clearScreen(); //Clean
//Printing depend on results
printSlots();
printResults(results);
if (results != -1)
{
playMusic("theme" + to_string(subject_code), "prize");
addPrizeToBalance(results);
}
printEndMenu();
do
{
checkKeyPress(3);
} while (subject_code != 0);
}
////5.4. FUNCTIONS - BALANCE OPERATIONS //////////////////////////////////////////////
bool paidPlay(const int& subject_to_pay)
{
if ((subject_to_pay == 1 || subject_to_pay == 2) && credit >= 10) //For the first two games
{
credit -= 10; //1st and 2nd Game Price
return true;
}
else if (subject_to_pay == 3 && credit >= 30) //For the last game
{
credit -= 30; //1st and 2nd Game Price
return true;
}
else //If the user don't have enought money
{
return false;
}
}
///////////////////////////////////////////////////////////
void addPrizeToBalance(const int& result_code)
{
credit += prizes[result_code];
}
////5.5. FUNCTIONS - INPUTS CONTROL //////////////////////////////////////////////
void checkKeyPress(const int& menu_type) //Menu
{
char key;// player input data
if (_kbhit()) //If any key is push it
{
key = toupper(_getch());// get keyboard data, and filter it
if (menu_type == 0) //Menu for chose subject
{
switch (key)
{
case 'V': //Player want to play the Las Vegas subject
if (paidPlay(1))
{
subject_code = 1;
setSubject();
printLoading(1500);
playMusic("theme" + to_string(subject_code));
}
break;
case 'M': //Player want to play the Maths subject
if (paidPlay(2))
{
subject_code = 2;
setSubject();
printLoading(1500);
playMusic("theme" + to_string(subject_code));
}
break;
case 'A': //Player want to play the Abertay Subject
if (paidPlay(3))
{
subject_code = 3;
setSubject();
printLoading(1500);
playMusic("theme" + to_string(subject_code));
}
break;
case 'T': //Player want to top up his credit
credit += 10;
//playMusic("lounge","insert_credit");
printMainMenu(); //We update the screen
break;
case 'L': //Player want to top up his credit
if (credit > 0) {
credit = 0;
//playMusic("lounge", "get_credit");
printMainMenu(); //We update the screen
}
break;
case 'E': // player trying to exit
game_running = false;
break;
}
}
else if (menu_type == 1) //Menu for start rolling
{
switch (key)
{
case 'R': //Player want to roll the slots
slots_rolling = true;
break;
}
}
else if (menu_type == 2) { //Menu for slots
switch (key)
{
case 'S': //Player want to stop a column
if (slots_rolling) stopColumn();
break;
}
}
else if (menu_type == 3) { //Menu for slots
switch (key)
{
case 'B': //Player want to go back exit to Main Menu
is_showing_results = false;
subject_code = 0;
printLoading(2000);
break;
}
}
} // end if
}
//5.6. FUNCTIONS - Outputs Logic/Customizations //////////////////////////////////////////////
void setOutputColor(const int& f_color, const int& bg_color) { //Default black
/*
COLOR INT VALUES
------------------------------ -
BLACK 0
BLUE 1
GREEN 2
CYAN 3
RED 4
MAGENTA 5
BROWN 6
LIGHTGRAY 7
DARKGRAY 8
LIGHTBLUE 9
LIGHTGREEN 10
LIGHTCYAN 11
LIGHTRED 12
LIGHTMAGENTA 13
YELLOW 14
WHITE 15
*/
SetConsoleTextAttribute(hConsole, (WORD)((bg_color << 4) | f_color));
}
///////////////////////////////////////////////////////////
void predefinedColorsByChar(const char& ch, const int& bg_color)
{
switch (ch)
{
case 'A':
case '\x8C':
case'\xBD':
setOutputColor(1, bg_color);
break;
case 'C':
case '\xA3':
case'\xF7':
setOutputColor(2, bg_color);
break;
case 'E':
case'\x80':
case 'G':
case'=':
setOutputColor(3, bg_color);
break;
case 'F':
case '\x24':
case '\xDF':
setOutputColor(4, bg_color);
break;
case 'H':
case '?':
case'\xD7':
setOutputColor(5, bg_color);
break;
case 'I':
case '!':
case'%':
case 'Y':
setOutputColor(6, bg_color);
break;
case 'M':
setOutputColor(7, bg_color);
break;
case 'N':
case '\xD8':
case '7':
setOutputColor(8, bg_color);
break;
case 'R':
setOutputColor(9, bg_color);
break;
case 'T':
setOutputColor(10, bg_color);
break;
case 'U':
setOutputColor(11, bg_color);
break;
case 'B':
setOutputColor(12, bg_color);
break;
case 'D':
setOutputColor(13, bg_color);
break;
case 'P':
setOutputColor(14, bg_color);
break;
case '#':
setOutputColor((rand() % 14) + 1, 0);
break;
default:
setOutputColor(15, bg_color);
break;
}
}
///////////////////////////////////////////////////////////
void printByCharacter(const string& str, const int& special_bg_color) {
for (size_t i = 0; i < str.length(); i++)
{
predefinedColorsByChar(str[i], special_bg_color);
cout << str[i];
}
}
///////////////////////////////////////////////////////////
int getColorDependOnBalance(const int& cost)
{
if (credit >= cost)
{
return 2; //GREEN
}
else
{
return 4; //RED
}
}
///////////////////////////////////////////////////////////
//5.7. FUNCTIONS - Messages (Outputs) //////////////////////////////////////////////
void printSlots()
{
//Clean Screen before
clearScreen();
string border = " #########################################################\n";
string line;
const int bg_color_mid = 15;//(rand() % 14) + 1;
//Print decoration top
cout << endl << endl << endl;
printByCharacter(border);
//Print the slots (and lateral decoration)
for (int row = 0; row < NUM_ROWS; row++)
{
for (int column = 0; column < NUM_COLUMNS; column++)
{
if (column == 0)
{
line = " # " + slots[row][column] + " "; //First column
}
else if (column == NUM_COLUMNS - 1)
{
line = " " + slots[row][column] + " " + " # "; //Last column
}
else
{
line = " " + slots[row][column] + " "; //Rest column
}
if (row == middleRow) printByCharacter(line, bg_color_mid); //Print the middle row with different bg
else printByCharacter(line);
}
cout << endl;
}
//Print bottom decoration
printByCharacter(border);
}
///////////////////////////////////////////////////////////
void printIntro() {
//Print Logo
cout << "\n\n\n\n\n\n\n\n\n\n";
printLogo();
Sleep(3000);
//Print Loading info
printLoading();
}
///////////////////////////////////////////////////////////
void printLogo()
{
string title = "\n" +
string( " FFFF RRRR U U III TTTTTT M M AA CCC H H III N N EEEE \n") +
" F R R U U I TT MM MM A A C H H I NN N E \n" +
" FFF RRRR U U I TT M M M AAAA C HHHH I N N N EEE \n" +
" F R R U U I TT M M A A C H H I N NN E \n" +
" F R RR UUU III TT M M A A CCC H H III N N EEEE BY FMGD \n";
printByCharacter(title);
}
///////////////////////////////////////////////////////////
void printLoading(const int& milliseconds)
{
clearScreen();
string loading =
string( " _ _ _\n") +
" | | ___ __ _ __| | (_) _ __ __ _\n" +
" | | / _ \x5C / _` | / _` | | | | '_ \x5C / _` |\n" +
" | |___ | (_) | | (_| | | (_| | | | | | | | | (_| | _ _ _\n" +
" |_____| \x5C___ / \x5C__,_| \x5C__,_| |_| |_| |_| \x5C__, | (_)(_)(_)\n" +
" |___/\n";
cout << "\n\n\n\n\n\n\n\n\n\n";
cout << loading;
Sleep(milliseconds);//Time showing loading
}
///////////////////////////////////////////////////////////
void printMainMenu()
{
clearScreen();
printLogo();
cout << "\n\n\n\n" +
string(" Select one of the following modes of games: \n\n") +
" Subjects Press the key Cost (credits)\n" +
" --------- ------------- -------------\n";
setOutputColor(getColorDependOnBalance(10));
cout << " Las Vegas V 10 \n" +
string(" Maths M 10 \n");
setOutputColor(getColorDependOnBalance(30));
cout <<
string(" Abertay A 30 \n\n\n");
setOutputColor(15);
cout <<
string(" My account:\n\n") +
" Options Press the key My Balance (credits)\n" +
" ---------------- ------------- ------------------\n" +
" Top up 10 credits T " + to_string(credit) + " \n" +
" Liquidate account L \n\n\n" +
" For Exit press 'E'.\n";
//Wait for key press
do
{
checkKeyPress(0);
} while (subject_code == 0 && game_running);
}
///////////////////////////////////////////////////////////
void printStartRollingMenu()
{
cout << "\n" +
string(" Commands Availables: \n") +
" Action Press the key \n" +
" --------- ------------- \n" +
" Rolling R \n" +
"\n";
}
///////////////////////////////////////////////////////////
void printPrizesInfo()
{
cout << "\n" +
string(" Prizes: \n") +
" Name Details Amount(Credits)\n" +
" --------- ------------- ---------------\n" +
" Special Event " + special_details + " " + to_string(prizes[0]) + "\n" +
" Jackpot Seven characters matched " + to_string(prizes[1]) + " \n" +
" MiniJackpot Six characters matched " + to_string(prizes[2]) + " \n" +
" Third Prize Five characters matched " + to_string(prizes[3]) + " \n" +
"\n";
}
///////////////////////////////////////////////////////////
void printInGameMenu()
{
cout << "\n" +
string(" Commands Availables: \n") +
" Action Press the key \n" +
" --------- ------------- \n" +
" Stop Column S \n" +
" (left to right) \n" +
"\n";
}
///////////////////////////////////////////////////////////
void printResults(const int& results_code)
{
cout << "\n\n _______________________________________________________\n";
cout << " | |" << endl;
switch (results_code)
{
case 1:
cout << " | FIRST PRIZE: " + to_string(prizes[1]) + " credits |" << endl;
break;
case 2:
cout << " | SECOND PRIZE: " + to_string(prizes[2]) + " credits |" << endl;
break;
case 3:
cout << " | THIRD PRIZE: " + to_string(prizes[3]) + " credits |" << endl;
break;
case 10:
cout << " | SPECIAL PRIZE: " + to_string(prizes[0]) + " credits |" << endl;
break;
default:
cout << " | Try again, you can do it! |" << endl;
break;
}
cout << " |_______________________________________________________|\n\n";
}
///////////////////////////////////////////////////////////
void printEndMenu()
{
cout << "\n" +
string(" Commands Availables: \n") +
" Action Press the key \n" +
" --------- ------------- \n" +
" Go Back to Main Menu B \n" +
"\n";
}
///////////////////////////////////////////////////////////
void printCredits()
{
clearScreen();
string credits = "\n\n\n\n\n\n\n" +
string(" #################################################################################\n") +
" # #\n" +
" # Credits: #\n" +
" # --------- ------------- #\n" +
" # Creater Francisco Diaz #\n" +
" # Class Computer Games Technology - 1st Year #\n" +
" # Module Programming with C++ (CMP104) #\n" +
" # Year 2019 #\n" +
" # Contact 1902654@uad.ac.uk #\n" +
" # #\n" +
" #################################################################################\n" +
"\n\n\n\n\n\n";
printByCharacter(credits);
}
///////////////////////////////////////////////////////////
void clearScreen() {
system("cls");
}
//5.8. FUNCTIONS - Music //////////////////////////////////////////////
void playMusic(string theme_file_name, string event_sound_file_name) { //Only for .WAV files, just play the music directly without opening the file
theme_file_name = "music/" + theme_file_name + ".wav"; //Set route
DWORD fdwSound = SND_FILENAME | SND_NODEFAULT ; //Flags for playing the sound
//SND_NODEFAULT = Don't play the default sound if filename cannot be found
if (!event_sound_file_name.empty()) //For sounds (events)
{
event_sound_file_name = "music/" + event_sound_file_name + ".wav";
fdwSound += SND_SYNC; //The sound is played synchronously, and PlaySound returns after the sound event completes.
PlaySound(event_sound_file_name.c_str(), GetModuleHandle(NULL), fdwSound);//just play the music directly without opening the file
}
fdwSound += SND_ASYNC | SND_LOOP;
PlaySound(theme_file_name.c_str(), GetModuleHandle(NULL), fdwSound);//just play the music directly without opening the file
//SND_ASYNC: The sound is played asynchronously and PlaySound returns immediately after beginning the sound
//SND_LOOP: The sound plays repeatedly until PlaySound is called again with the pszSound parameter set to NULL
}
// MAIN GAME LOOP /////////////////////////////////////////
int main()
{
//SECTION: CONFIGURE
SetConsoleOutputCP(1252); //Set to Windows Codepage 1252
srand((unsigned)time(NULL));// seed the random number generator with time for use rand()
//SECTION: GAME
printIntro();
while (game_running)
{
//SECTION: MAIN MENU
playMusic("lounge");
printMainMenu();
//SECTION: PLAY
if (subject_code != 0)
{
//SECTION: SHOW INFO BEFORE START PLAY
do //Show the slots stoped
{
printSlots();
printStartRollingMenu();
printPrizesInfo();
checkKeyPress(1);
Sleep(60);
} while (!slots_rolling); //While the user doesn't start to play
//SECTION: ROLLING SLOTS (PLAYING)
while (slots_rolling) //Here the user is playing
{
//- Get player input
checkKeyPress(2);
//- Rotation action
rotateSlots();
printSlots();
printInGameMenu();
Sleep(70);
}
//SECTION: END OF PLAY
displayEndGame(); //Show results and wait for action
}
}
//SECTION: GAME CLOSED
printCredits();
return 0;
} // end main