这是我的代码到目前为止,我使用的是目标c。这是小的,但我想作出默认的答案,例如,如果有人输入“我喜欢馅饼”,它会说“我不明白”。当用户键入错误的输入时,如何在文本游戏中创建默认答案?
printf("This is a text game! You will be shown what is going on");
printf("\nand it is up to you to decide what to do.");
printf("\n\nThere is a gem on the ground.");
printf("\nWhat do you want to do");
printf("\n>");
char string[256];
fgets(string, 255, stdin);
if (strcmp(string, "pick up gem\n") == 0)
{
printf("Got Gem");
}
else if (strcmp(string, "kick gem\n") == 0){
printf("Gem flew off the road.");
}
请注意,您发布的代码中的所有内容都是普通的C,而不是Objective-C。这没什么错,因为所有有效的C也是有效的Objective-C,但它不是通常编写Objective-C程序的方式。 – 2013-02-28 00:39:24
@AndrewMadsen你可以标记我的帖子 – codegeek511 2013-02-28 03:58:19