簡體   English   中英

棋盤游戲功能

[英]Board game functions

我已經編寫了一個棋盤游戲程序。 我的問題是一個功能,因此某些字段會向后或向前傳輸播放器。 顯然我沒做過。

int numbers()
{
int maxscore;
int numbers[10];
maxscore = enter();
srand(time(NULL));
int nonumbers[3] = {0, 1, maxscore};  //to initialize the scores there shouldn't be a badfield
numbers[10] = rand() % maxscore + 1;
if(numbers[10] == nonumbers[3])
{
    numbers[10] = rand() % maxscore + 1;
}
return numbers;


}

int badfields = numbers();
if(score[i] == badfields)
       {
           printf("Player %d. goes 5 fields backwards", playershown);
           score[i] = score[i] - 5;
           printf("This player is now in %d Field", score[i]);
       }

我必須以某種方式重復輸入最高分數的過程。

我不會直接回答“問題”,因為沒有要回答的“問題”。 正如其他人在評論中指出的那樣,您需要更加具體,並提供對問題的正確描述。 但是我仍然可以提供以下反饋:

在我看來,您不太了解數組及其索引。 例如,此行應為您提供細分錯誤,或至少與一個未知值進行比較:

if(numbers[10] == nonumbers[3])

這是因為您的nonumbers數組具有3個元素,因此應將其尋址為nonumbers[0]nonumbers[1]nonumbers[2] (或者通常,如Weather Vane在注釋中所述,從nonumbers[0]nonumbers[array_lenght-1] )。 nonumbers[3]將訪問內存中的未定義位置。 您的問題可能與此有關。

請注意,我和任何人都不會檢查您的整個代碼以找到錯誤。 如上所述,請更具體。

另外,您確定擺脫了所有編譯器錯誤嗎? 因為在您的代碼中,您還有一個未初始化的變量i 為確保您擺脫了所有潛在的討厭的錯誤,請打開終端(假設您使用的是Linux)並使用以下命令來編譯程序:

gcc *.c -Wall -Wextra -o program

然后運行:

./program

暫無
暫無

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

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