#include<iostream>
#include<time.h>
#include<conio.h>
#include<Windows.h>
using namespace std;
void startView(); // 시작화면
void slotInput(); // 슬롯 숫자지정
void Display(); // 그려줄 화면
void gamePlay(); // 게임진행여부 확인
void slotCheck(); // 슬롯 체크
char *card[52] = { "◆A", "◆2", "◆3", "◆4", "◆5", "◆6", "◆7", "◆8", "◆9", "◆10", "◆J", "◆Q", "◆K",
"♣A", "♣2", "♣3", "♣4", "♣5", "♣6", "♣7", "♣8", "♣9", "♣10", "♣J", "♣Q", "♣K",
"♠A", "♠2", "♠3", "♠4", "♠5", "♠6", "♠7", "♠8", "♠9", "♠10", "♠J", "♠Q", "♠K",
"♥A", "♥2", "♥3", "♥4", "♥5", "♥6", "♥7", "♥8", "♥9", "♥10", "♥J", "♥Q", "♥K" };
int money = 1000; // 보유 금액
int bCount = 5; // 배팅 기회
int slot1 = 0, slot2 = 0, slot3 = 0; // 슬롯1, 2, 3
int cSlot1 = 0, cSlot2 = 0, cSlot3 = 0; // 슬롯에 위치한 카드 확인
int inputKey = 49; // 게임진행 및 종료를 입력받을 키 ( Num1키 아스키값 49 / Num2키 아스키값 50)
void main()
{
// 슬롯머신
// 카드 52장 ◆ ♣ ♠ ♥ 1~10 J Q K
// 숫자트리플 777 -> 배팅금액 * 3
// 숫자더블 66 -> 배팅금액 * 2
// 문양트리플♥♥♥ -> 배팅기회 * 3
// 문양더블 ♠♠ -> 배팅기회 + 3
startView();
while(bCount > 0 && inputKey == 49)
{
slotInput();
gamePlay();
slotCheck();
Display();
}
}
void startView() {
cout << " 시작금액" << endl;
cout << " 배팅기회" << endl;
cout << " ┌────슬롯머신────┐" << endl;
cout << " │ │" << endl;
cout << "\t 게임을 시작합니다" << endl;
cout << " │ │" << endl;
cout << " ├────────────┤" << endl;
cout << " │ 게임진행 1 종료 2 │" << endl;
cout << " └────────────┘" << endl;
cout << " 배팅기회는 5회가 주어지며 최대 20까지 증가합니다." << endl;
cout << " 게임진행 Num1 을 누르면 배팅이 진행됩니다. " << endl;
cout << " 게임진행 Num2 를 누르면 배팅이 종료됩니다. " << endl;
}
void slotInput() {
// 중복된 값이 나오지 않을 때까지 반복
srand(time(NULL));
do
{
slot1 = rand() % 52;
slot2 = rand() % 52;
slot3 = rand() % 52;
} while (slot1 == slot2 || slot1 == slot3 || slot2 == slot3);
}
void Display() {
system("cls");
cout << " 시작금액 : 1000원 / 현재금액 : " << money << "원" << endl;
cout << " 배팅기회 : " << bCount << " 회 남았습니다" << endl;
cout << " ┌────슬롯머신────┐" << endl;
cout << " │ │" << endl;
cout << "\t " << card[slot1] << " " << card[slot2] << " " << card[slot3] << endl;
cout << " │ │" << endl;
cout << " ├────────────┤" << endl;
cout << " │ 게임진행 1 종료 2 │" << endl;
cout << " └────────────┘" << endl;
}
void gamePlay() {
while (1) {
inputKey = getch();
if (inputKey == 49 || inputKey == 50) break;
}
if (inputKey == 49) bCount--; // 배팅을 했으므로 기회 1 감소
if (inputKey == 50) exit(1); // Num2 를 누르면 게임이 종료됨
}
void slotCheck() {
int pTriple = 0; // 문양트리플 체크
int pDouble = 0; // 문양더블 체크
cSlot1 = slot1 % 13;
cSlot2 = slot2 % 13;
cSlot3 = slot3 % 13;
// 숫자트리플 배팅금액 * 3
if (cSlot1 == cSlot2 && cSlot1 == cSlot3) { money *= 3; }
// 숫자더블 배팅금액 * 2
else if (cSlot1 == cSlot2) { money *= 2; }
else if (cSlot1 == cSlot2) { money *= 2; }
else if (cSlot2 == cSlot3) { money *= 2; }
cSlot1 = slot1 / 13;
cSlot2 = slot2 / 13;
cSlot3 = slot3 / 13;
// 문양트리플 배팅기회 * 3
if (cSlot1 == cSlot2 && cSlot1 == cSlot3) { bCount *= 3; }
// 문양더블 배팅기회 + 3
else if (cSlot1 == cSlot2) { bCount += 3; }
else if (cSlot1 == cSlot2) { bCount += 3; }
else if (cSlot2 == cSlot3) { bCount += 3; }
// 최대 배팅기회 20으로 제한
if (bCount > 20) { bCount = 20; }
}
//ㅡㅡㅡ 구동화면 ㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡ
기본 룰은 시작금액 1000원으로 고정
배팅기회를 기본 5회로 지정
Num1 키를 누르면 게임이 시작되고
숫자 트리플 시 금액 3배
숫자 더블 시 금액 2배
문양 트리플 시 배팅기회 3배
문양 더블 시 배팅기회 +3
생각외로 문양 트리플이 많이나와 최대 배팅기회를 20으로 지정
Num2 키를 누르면 어느때고 게임이 종료됩니다.
↓↓↓↓ 소스 파일 ↓↓↓↓
↑↑↑↑↑↑↑↑↑↑↑↑↑