posted by REDFORCE 2017. 6. 14. 14:06

간단한 하이로우세븐 콘솔 게임입니다.


하이로우세븐 게임 룰 자체는 설명안하겠습니다.



코드도 그렇게 어려운건 없어서...


단순하게 랜덤하게 나온 값을 토대로 조건문으로 검사하는 것뿐...


(어딘가에 좋은 짤방이 없나...)


#include "Choco.h"
Choco::Choco()
{
int num;
int _money = 10000;
for (int i = 0; i < 52; i++) {
num = i / 13;
switch (num)
{
case 0:
_card[i].shape = "◆";
break;
case 1:
_card[i].shape = "♠";
break;
case 2:
_card[i].shape = "♥";
break;
case 3:
_card[i].shape = "♣";
break;
}
num = i % 13 + 1;
_card[i].number = num;
}
//초기화 시키고 난 뒤 섞기
for (int i = 0; i < 150; i++) {
int dest = rand() % 52;
int sour = rand() % 52;
stCard temp = _card[dest];
_card[dest] = _card[sour];
_card[sour] = temp;
}
int betting;
int select;
int gameCount = 1;
int startCard = 0;
int endCard = 5;
while (true) {
cout << gameCount << " 번째 게임 Start!!" << endl << endl;
for (startCard = gameCount-1; startCard < endCard+1; startCard++) {
if (startCard == endCard) {
cout << "XX" << endl;
}
else {
cout << _card[startCard].shape << _card[startCard].number << "\t";
}
}
cout << "Select : High (1) " << "Low (2) " << "Seven (3)" << endl;
while (true) {
cin >> select;
if (select > 3 || select < 1) continue;
if (cin.fail())
{
cin.clear();
cin.ignore(INT_MAX, '\n');
continue;
}
break;
}
while (true) {
cout << "베팅하세요. (최소 100원) : " << endl;
cin >> betting;
if (betting < 100) continue;
if (betting > _money) continue;
if (cin.fail())
{
cin.clear();
cin.ignore(INT_MAX, '\n');
continue;
}
break;
}
switch (select)
{
case 1: // Select High
if (_card[endCard].number > 7) {
cout << "당신이 이겼습니다." << endl;
_money += betting;
}
else {
cout << "당신이 졌습니다." << endl;
_money -= betting;
}
break;
case 2: // Select Low
if (_card[endCard].number < 7) {
cout << "당신이 이겼습니다." << endl;
_money += betting;
}
else {
cout << "당신이 졌습니다." << endl;
_money -= betting;
}
break;
case 3: // Select Seven
if (_card[endCard].number == 7) {
cout << "당신이 이겼습니다." << endl;
_money += 13 * betting;
}
else {
cout << "당신이 졌습니다." << endl;
_money -= betting;
}
break;
default:
break;
}
system("cls");
cout << "결과 후 소지금 : " << _money << " 원" << endl << endl;
gameCount++;
startCard++;
endCard++;
if (gameCount == 47) {
break;
}
}
}
Choco::~Choco()
{
}
view raw main.cpp hosted with ❤ by GitHub


'Programming > C++' 카테고리의 다른 글

[C++]나눗셈을 피해서 연산하자  (0) 2017.09.04
[C++]상점/인벤토리 만들기(콘솔)  (0) 2017.06.14
[C++]간단한 배팅 도박게임  (0) 2017.06.14
[C++]간단한 숫자 퍼즐 게임  (0) 2017.06.14
[C++]간단한 별찍기  (0) 2017.06.14