미완성
#include <stdio.h>
#include <random>
#include <Windows.h>
int totalMoney = 100000;
int& ttm = totalMoney;
const char* dealerName = "딜러";
const char* playerName = "플레이어";
void PlayerInfo()
{
if (ttm > 10000)
{
printf("소지금액 :%d만 %d원\n\n", ttm / 10000, ttm % 10000);
}
}
void BattingSet(int* battmoney)
{
PlayerInfo();
printf("배팅할 금액을 적으세요.(최소금액: 1000원)\n");
printf("입력:");
scanf_s("%d", battmoney);
while (*battmoney > ttm || *battmoney < 1000)
{
system("cls");
PlayerInfo();
printf("배팅할 금액을 적으세요.(최소금액: 1000원)\n");
if (*battmoney > ttm) { printf("소지금액이 부족합니다.\n"); }
if (*battmoney < 1000) { printf("1000원 이상부터 배팅이 가능합니다.\n"); }
printf("입력:");
scanf_s("%d", battmoney);
}
totalMoney -= *battmoney;
system("cls");
}
void showBattMoney(int* battmoney)
{
printf("배팅 머니: %d\n",*battmoney);
}
int RandomNumber()
{
return rand() % 12 + 2;
};
void reNumber(const char* c, int *p, int r)
{
if (r == 11)
{
printf("%s 카드: A", c);
p[1]++;
}
else if (r == 12 || r == 13 || r == 14)
{
switch (r)
{
case 12:
printf("%s 카드: Q", c);
break;
case 13:
printf("%s 카드: J", c);
break;
case 14:
printf("%s 카드: K", c);
break;
default:
break;
}
p[0] += 10;
}
else
{
printf("%s 카드: %d", c, r);
p[0] += r;
}
printf("\n");
}
void BlindNumber(const char* c, int* p, int r)
{
if (r == 11)
{
p[1]++;
}
else if (r == 12 || r == 13 || r == 14)
{
p[0] += 10;
}
else
{
p[0] += r;
}
printf("%s 카드: ?", c);
printf("\n");
}
void showTotalNumber(const char*c, int *p)
{
if (p[1] > 0)
{
printf("%s 의 총 점수: %d/%d", c, p[0] + p[1], p[0] + p[1] * 11);
}
else { printf("%s 의 총 점수: %d", c, p[0]); }
printf("\n");
}
void firstCardSet(int* player, int* dealer, int*battingAmount)
{
showBattMoney(battingAmount);
PlayerInfo();
reNumber(playerName, player, RandomNumber());
Sleep(1000);
reNumber(dealerName, dealer, RandomNumber());
Sleep(1000);
reNumber(playerName, player, RandomNumber());
Sleep(1000);
BlindNumber(dealerName, dealer, RandomNumber());
Sleep(1000);
printf("_________________________\n");
showTotalNumber(playerName, player);
Sleep(1000);
}
int main()
{
while (true)
{
//배팅 가격세팅
int* battingAmount = (int*)malloc(sizeof(int));
BattingSet(battingAmount);
//카드 세팅
srand(time(0));
int* player = (int*)malloc(sizeof(int) * 2);
int* dealer = (int*)malloc(sizeof(int) * 2);
player[0] = 0;
player[1] = 0;
dealer[0] = 0;
dealer[1] = 0;
firstCardSet(player, dealer, battingAmount);
bool Continue = true;
while (Continue)
{
//둘중 한명이상이 21에 도달했을때
if ((player[0] + player[1] >= 21 && player[0] + player[1] * 11 >= 21) || (dealer[0] + dealer[1] >= 21 && dealer[0] + dealer[1] * 11 >= 21))
{
if (player[0] + player[1] == 21 || player[0] + player[1] * 11 == 21)
{
printf("승리!\n");
printf("+%d원", *battingAmount);
totalMoney += *battingAmount * 2;
}
else if (player[0] + player[1] > 21 && player[0] + player[1] * 11 > 21)
{
printf("패배!\n");
}
else { showTotalNumber(playerName, player); printf("비김\n"); totalMoney += *battingAmount;}
Sleep(1000);
system("cls");
break;
}
int option;
printf("1.Hit 2.Stay 3.DoubleDown\n");
scanf_s("%d", &option);
while (option < 1 || 3 < option)
{
printf("잘못입력하셨습니다.\n");
scanf_s("%d", &option);
}
switch (option)
{
case 1:
reNumber(playerName, player, RandomNumber());
Sleep(1000);
showTotalNumber(playerName, player);
break;
case 2:
showTotalNumber(dealerName, dealer);
while (dealer[0] + dealer[1] < 17)
{
Sleep(1000);
reNumber(dealerName, dealer, RandomNumber());
}
Sleep(1000);
showTotalNumber(dealerName, dealer);
if (dealer[0] + dealer[1] > 21 && dealer[0] + dealer[1] * 11 > 21) { printf("승리!\n"); printf("+%d원", *battingAmount); totalMoney += *battingAmount * 2;}
else if (dealer[0] + dealer[1] > player[0] + player[1] && dealer[0] + dealer[1] * 11 > player[0] + player[1] * 11)
{
printf("패배..\n");
}
else if(player[0] + player[1] > dealer[0] + dealer[1] && player[0] + player[1] * 11 > dealer[0] + dealer[1] * 11)
{
printf("승리!\n");
printf("+%d원", *battingAmount);
totalMoney += *battingAmount * 2;
}
else
{
printf("무승부\n");
totalMoney += *battingAmount;
}
Sleep(4000);
system("cls");
Continue = false;
break;
case 3:
reNumber(playerName, player, RandomNumber());
showTotalNumber(playerName, player);
break;
default:
break;
}
}
free(player);
free(dealer);
free(battingAmount);
}
return 0;
}
'C' 카테고리의 다른 글
C언어게임 현재 진행 상황 (0) | 2023.09.21 |
---|---|
플레이어 입장 프로그램 (0) | 2023.09.04 |
6. malloc (0) | 2023.09.01 |
5.다중포인터 (0) | 2023.09.01 |
4. 구조체 (0) | 2023.08.31 |