简体   繁体   English

棋盘游戏功能

[英]Board game functions

I have made a program to a board game. 我已经编写了一个棋盘游戏程序。 My problem is a function, so that certain fields transport the player back or forward. 我的问题是一个功能,因此某些字段会向后或向前传输播放器。 Apparently the thing I did doesn't work. 显然我没做过。

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]);
       }

Somehow I have to repeat the process of entering the maximum score. 我必须以某种方式重复输入最高分数的过程。

I won't directly answer the "question" because there is no "question" to be answered. 我不会直接回答“问题”,因为没有要回答的“问题”。 As others have pointed out in the comments, you need to be more specific and provide a proper description of your problem. 正如其他人在评论中指出的那样,您需要更加具体,并提供对问题的正确描述。 But I can still provide the following feedback: 但是我仍然可以提供以下反馈:

It seems to me you don't quite understand arrays and their indexing. 在我看来,您不太了解数组及其索引。 For example, this line should give you a segmentation fault error, or at the very least make a comparison with an unknown value: 例如,此行应为您提供细分错误,或至少与一个未知值进行比较:

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

This is because your nonumbers array has 3 elements, and thus they should be addressed as nonumbers[0] , nonumbers[1] or nonumbers[2] (or, in general, as Weather Vane put it in the comments, from nonumbers[0] to nonumbers[array_lenght-1] ). 这是因为您的nonumbers数组具有3个元素,因此应将其寻址为nonumbers[0]nonumbers[1]nonumbers[2] (或者通常,如Weather Vane在注释中所述,从nonumbers[0]nonumbers[array_lenght-1] )。 nonumbers[3] will access an undefined position in memory. nonumbers[3]将访问内存中的未定义位置。 Your problem could be related to this. 您的问题可能与此有关。

Note that neither me nor anybody is going to review your entire code to find the error. 请注意,我和任何人都不会检查您的整个代码以找到错误。 As stated above, please be more specific. 如上所述,请更具体。

Also, are you sure you got rid of all compiler errors? 另外,您确定摆脱了所有编译器错误吗? Because further down your code you have an uninitialized variable i . 因为在您的代码中,您还有一个未初始化的变量i To be sure you got rid of all potentially nasty errors, open the terminal (I'm assuming you are on linux) and use the following command to compile your program: 为确保您摆脱了所有潜在的讨厌的错误,请打开终端(假设您使用的是Linux)并使用以下命令来编译程序:

gcc *.c -Wall -Wextra -o program

Then run it with: 然后运行:

./program

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM