#include<iostream>

#include<time.h>

#include<conio.h>

#include<Windows.h>


using namespace std;


void startView(); // 시작화면

void cardShuffle(); // 카드를 섞어줄 함수

void gamePlay(); // 진행화면

void endPage(); // 종료화면



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 cardResult[52];                  // 실질적인 하이 로우 세븐을 처리할 값을 저장할 배열

int money = 1000;          // 보유 금액

int remainCard = 0;  // 진행하며 남은 카드를 확인할 변수

int inputKey;  // 첫화면에서 Enter 키를 입력을 받아야 다음을 진행하기 위해 사용된 변수로 사용되고 이후 하이로우세븐을 지정할 변수 ( Num1키 49 , Num2키 50 , Num3키 51 , ESC키 27)

int stage = 0;  // 스테이지 진행 및 보여줄 카드 확인을 위한 변수

int bMoney = 0;  // 배팅 금액



void main() 

{

// 과제3 하이로우세븐

//   카드 52장  

//       하이 금액 * 2

//       로우 금액 * 2

//       세븐 금액 * 7

srand(time(NULL));


startView();

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

cardShuffle();

gamePlay();

}

endPage();

}


void startView() {

cout << endl;

cout << " ┌──── HIGH & LOW 7 ────┐" << endl;

cout << " │                              │" << endl;

cout << " │                              │" << endl;

cout << " │                              │" << endl;

cout << " │                              │" << endl;

cout << " │      G A M E  S T A R T      │" << endl;

cout << " │                              │" << endl;

cout << " │  P r e s s  S p a c e B a r  │" << endl;

cout << " │                              │" << endl;

cout << " │                              │" << endl;

cout << " └───────────────┘" << endl;


while(1){

inputKey = getch();

if (inputKey == 32) break;

}

}

void cardShuffle() {

int nNum1, nNum2; // 랜덤 숫자를 받을 변수

if(remainCard == 0)

{

// 섞을 카드를 새로운 배열에 일단 초기화

// 아래 if문은 해당 하이로우세븐을 구분할 값을 배열에 초기화

for (int i = 0; i < 52; i++) {

if( i % 13 < 7)

{

cardResult[i] = 2;

}

else if (i % 13 == 7) {

cardResult[i] = 3;

}

else {

cardResult[i] = 1;

}

}

// 카드 섞기

for (int i = 0; i < 1000; i++){

nNum1 = rand() % 52;

nNum2 = rand() % 52;

swap(card[nNum1], card[nNum2]);

swap(cardResult[nNum1], cardResult[nNum2]);

}

remainCard = 51;

stage = 0;

}

}


void gamePlay() {

system("cls");

cout << endl;

cout << " ┌──── HIGH & LOW 7 ────┐" << endl;

if(remainCard > 9){

cout << " │  [  ?  ]       남은카드 : " << remainCard << " │" << endl;

}

else {

cout << " │  [  ?  ]       남은카드 :  " << remainCard << " │" << endl;

}

cout << " │                              │" << endl;


if (stage - 1 >= 0) {

cout << "     [ " << card[stage - 1] << " ]";

} else {

cout << "     [     ]";

}

if (stage - 2 >= 0) {

cout << "   [ " << card[stage - 2] << " ]";

} else {

cout << "   [     ]";

}

if (stage - 3 >= 0) {

cout << "   [ " << card[stage - 3] << " ]" << endl;

} else {

cout << "   [     ]" << endl;

}


cout << " │                              │" << endl;

if (stage - 4 >= 0) {

cout << "     [ " << card[stage - 4] << " ]";

}

else {

cout << "     [     ]";

}

if (stage - 5 >= 0) {

cout << "   [ " << card[stage - 5] << " ]";

}

else {

cout << "   [     ]";

}

if (stage - 6 >= 0) {

cout << "   [ " << card[stage - 6] << " ]" << endl;

}

else {

cout << "   [     ]" << endl;

}


cout << " │                              │" << endl;


if (stage - 7 >= 0) {

cout << "     [ " << card[stage - 7] << " ]";

}

else {

cout << "     [     ]";

}

if (stage - 8 >= 0) {

cout << "   [ " << card[stage - 8] << " ]";

}

else {

cout << "   [     ]";

}

if (stage - 9 >= 0) {

cout << "   [ " << card[stage - 9] << " ]" << endl;

}

else {

cout << "   [     ]" << endl;

}

cout << " │                              │" << endl;

cout << " │ 1. HIGH    2. LOW   3. SEVEN │" << endl;

cout << " └───────────────┘" << endl;

cout << " 배팅을 종료하시려면 ESC 키를 입력하세요" << endl;

cout << " HIGH, LOW, SEVEN 을 선택하세요 ( 1, 2, 3 )" << endl;

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

while (1)

{

inputKey = getch();

if (inputKey == 49 || inputKey == 50 || inputKey == 51 || inputKey == 27) break;

}

if (inputKey == 49 || inputKey == 50 || inputKey == 51)

{

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

cin >> bMoney;

while (money < bMoney && bMoney > 0) {

cout << " 배팅금액이 보유금액을 넘을 수 없습니다 " << endl;

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

cin >> bMoney;

}

int select = 0;  // 하이 로우 세븐 계산 변수


// 하이 로우 세븐 중 선택한 값을 선택

if (inputKey == 49) {

select = 1;

}

else if (inputKey == 50) {

select = 2;

}

else {

select = 3;

}


// 보유금액에서 배팅한 금액만큼 빼준다

money -= bMoney;


// 배팅에 성공 여부에 따른 계산 처리

if (cardResult[stage] == select) {

if (select == 1 || select == 2) {

money = money + (bMoney * 2);

}

else {

money = money + (bMoney * 7);

}

}

stage++;

remainCard--;

}

}

void endPage() {

if (money == 0) {

cout << " =========== 게임 종료 ===========" << endl;

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

}

else {

cout << " =========== 게임 종료 ===========" << endl;

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

}

}

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

스페이스바를 누르면 게임이 시작됩니다.

룰은 ? 된 카드의 값이 7보다 높은지 낮은지 아니면 7인지를 선택해 

( Num1키 -> HIGH  /  Num2키 -> LOW  /  Num3키 -> SEVEN )

만약 맞추었다면 배팅한 금액에 따라 

HIGH & LOW 는 배팅 금액 2배

SEVEN 은 배팅 금액 7배

에 해당하는 금액을 받게 됩니다.

카드가 다 소모되면 카드를 초기화 시켜 계속 이어서 게임을 진행할 수 있고

금액을 다 소모하게되면

아래 그림과 같이 파산하게 되어 게임이 종료됩니다.

아니면 게임 진행 중에 종료하고 싶다면 ESC 키를 누르면 게임이 종료됩니다.


↓ 소스 파일 

HighLowSeven.cpp


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

월남뽕  (0) 2015.08.13
별찍기  (0) 2015.08.11
슬롯머신 게임  (0) 2015.08.11
타일맵 그리기  (0) 2015.08.05
채팅 대전액션  (0) 2015.08.04

+ Recent posts