#include<iostream>

#include<time.h>

#include<conio.h>

#include<string>

#include<Windows.h>

using namespace std;


void startView(); // 시작화면

void cardSelect(); // 카드선택

void gamePlay(); // 게임화면

void endView(); // 종료화면

string 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 slot1 = 0, slot2 = 0, slot3 = 0; // 슬롯1, 2, 3

int cSlot1 = 0, cSlot2 = 0, cSlot3 = 0; // 슬롯에 위치한 카드 확인

int inputKey = 0;  // 게임진행 키 

int bMoney = 0;  // 배팅 금액


void main()

{

// 과제 월남뽕

// 카드 3장을 출력하되 마지막 3번째 카드는 오픈하지않고

// 3번째 카드의 숫자가 오픈된 1, 2번째 카드 사이의 값인지 

// 여부에 따라 승패가 나뉜다

srand(time(NULL));

startView();

while(money > 0 && inputKey != 27){

cardSelect();

gamePlay();

}

endView();



}

void startView() {

cout << endl;

cout << "          월남뽕          " << endl;

cout << endl;

cout << "   게임을 시작하겠습니다." << endl;

cout << endl;

cout << "     P r e s s  K E Y" << endl;

cout << endl;

}

void cardSelect() {

do 

{

slot1 = rand() % 52;

slot2 = rand() % 52;

slot3 = rand() % 52;

if (slot1 != slot2 && slot1 != slot2 && slot2 != slot3) break;

} while (1);

cSlot1 = slot1 % 13;

cSlot2 = slot2 % 13;

cSlot3 = slot3 % 13;

void gamePlay() {

system("cls");

cout << endl;

cout << "       보유 금액 : " << money << "원 " << endl;

cout << endl;

cout << "            월남뽕          " << endl;

cout << endl;

cout << "     [ " << card[slot1] << " ]" << "\t " << "[ " << card[slot2] << " ]"<< endl;

cout << "            [  ?  ]" << endl;

cout << "  진행을 하시려면 아무키나 눌러주세요" << endl;

cout << " 게임을 종료하시려면 ESC키를 눌러주세요" << endl;

inputKey = getch();

cout << " 배팅 금액을 입력하세요 : ";

if (inputKey != 27) {

cin >> bMoney;

while (money < bMoney) {

cout << " 배팅 금액이 보유 금액보다 높습니다. " << endl;

cout << " 배팅 금액을 입력하세요 : ";

cin >> bMoney;

}

money -= bMoney;

if (cSlot1 < cSlot2) {

if (cSlot1 <= cSlot3 && cSlot3 <= cSlot2) {

money = money + (bMoney * 2);

}

}

else {

if (cSlot2 <= cSlot3 && cSlot3 <= cSlot1) {

money = money + (bMoney * 2);

}

}

}

}


void endView() {

system("cls");

cout << endl;

cout << endl;

cout << endl;

cout << "          월남뽕          " << endl;

cout << endl;

cout << "   게임이 종료되었습니다" << endl;

cout << endl;



if (money == 0) {

cout << "       파산하였습니다" << endl;

}

else {

cout << "    보유 금액 : " << money << "원" << endl;

}

cout << endl;

}

ㅡㅡ 구동화면 ㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡ

기존 룰은 ? 카드가 첫번째와 두번째 나온 카드 사이 숫자인지 여부를 확인해 배팅을 한다

? 카드가 사이값의 카드가 나올 시 배팅금액의 두배를 돌려준다.

아니라고 생각된다면 0원을 배팅할 수 있고 올인나거나 ESC 키를 입력하면 게임이 종료된다.

사정이 생겨 다른 것을 해결하느라 시간이 없어 보이기에는 허접할 수 있으나

요구 조건은 만족했다 생각되어 나름 만족 하지만 허접한건 사실







'SGA 스터디 > C++ 코딩' 카테고리의 다른 글

공 허들넘기 ㅋㅋ  (0) 2015.08.20
카드 뒤집기  (0) 2015.08.14
별찍기  (0) 2015.08.11
하이 로우 세븐 카드게임 ( High & Low 7 )  (0) 2015.08.11
슬롯머신 게임  (0) 2015.08.11

+ Recent posts