簡體   English   中英

機會游戲,一款非常簡單的骰子游戲模擬器

[英]A Game of Chance,a simulator for a very simple dice game

誰能告訴我代碼有什么問題嗎?

玩家將擲出兩個骰子。 在第一個擲骰中,如果兩個骰子的總和等於7或11,則玩家獲勝。 如果總和等於2、3或12,則玩家輸。 任何其他金額,游戲將繼續,該金額將成為玩家的“積分”。 玩家將一次又一次擲出兩個骰子,以達到玩家的“積分”。 如果玩家達到此目標,則玩家獲勝。 如果玩家在達到“點數”之前擲出7,則玩家將輸。

和平!

#include <stdio.h>
#include <stdlib.h>
#include <time.h>

int rand_num()
{
    return ( 1 + (rand()%6) );
}

int main( void )
{
    int D1, D2, score, point;
    int D3, D4, score_n = 0;

    srand ( time( NULL ) );

    D1 = rand_num();
    D2 = rand_num();

    score = D1 + D2;
    printf( "You rolled %d + %d = %d", D1, D2, score );

    if ( score == 7 || score == 11 )
        printf( "\n\nYou win!");

    else if ( score == 2 || score == 3 || score == 12 )
        printf( "\n\nYou lose!");

    else
        {
            point = score;
            printf( "\n\nYou must get %d to win", point);

            do
            {
                D3 = rand_num();
                D4 = rand_num();

                score_n = D3 + D4;

                printf( "\n\nYou rolled %d + %d = %d", D3, D4, score_n );   

                if ( score_n == 7 ) 
                    printf( "\n\nYou lose!" );


                if ( score_n == point )
                    printf( "\n\nYou win!" );

            }while ( score_n == point || score_n == 7 );            


        }



    return 0;
}
 }while ( score_n == point || score_n == 7 ); 

僅當分數==點或7時,循環才會繼續

 }while ( score_n != point && score_n != 7 ); 

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM