craps赌博游戏

craps赌博游戏

规则:玩家掷两个骰子,每个骰子点数为1-6,如果第一次点数和为7或11,则玩家胜;如果点数和为2、3或12,则玩家输庄家胜。若和为其他点数,则记录第一次的点数和,玩家继续掷骰子,直至点数和等于第一次掷出的点数和则玩家胜;若掷出的点数和为7则庄家胜。

#include <stdio.h>

#include <stdlib.h>

#include <time.h>


// 定义一种新的类型

typedef int BOOL;

// 为新类型设定两个可选值

const int YES = 1;

const int NO = 0;


int main() {

    srand((unsigned)time(0));   //时间作为随机数种子

    int money = 1000;           //玩家游戏筹码

    do {

        printf("玩家拥有%d元筹码!\n", money);

        int debt;   //押注

        do {

            printf("请下注: ");

            scanf("%d", &debt);

        } while (debt <= 0 || debt > money);

        

        int face1 = rand() % 6 + 1;

        int face2 = rand() % 6 + 1;

        int firstPoint;

        firstPoint = face1 + face2;

        printf("玩家摇出了%d\n", firstPoint);

        BOOL gameOver = NO;

        switch (firstPoint) {

            case 7: case 11:

                printf("玩家胜!\n");

                money += debt;

                gameOver = YES;

                break;

            case 2: case 3: case 12:

                printf("庄家胜!\n");

                money -= debt;

                gameOver = YES;

                break;

        }

        while (!gameOver) {

            face1 = rand() % 6 + 1;

            face2 = rand() % 6 + 1;

            int currentPoint = face1 + face2;

            printf("玩家摇出了%d\n", currentPoint);

            if (currentPoint == 7) {

                printf("庄家胜!\n");

                money -= debt;

                gameOver = YES;

            }

            else if (currentPoint == firstPoint) {

                printf("玩家胜!\n");

                money += debt;

                gameOver = YES;

            }

        }

    } while (money > 0);

    printf("你破产了!游戏结束!\n");

    return 0;

}



你可能感兴趣的:(C语言,craps赌博游戏)