还是新手,所以我有点麻烦。谁能指引我朝着正确的方向前进,那就太好了。这是我到目前为止的代码:
int Rock = 0;
int Paper = 1;
int Scissors = 2;
int PlayerChoice (int PlayerC){
NSLog(@"Player chooses %i", Rock || Paper || Scissors);
return 0;
}
int ComputerChoice (int rockpaperscissors){
return arc4random_uniform(2);
NSLog(@"Computer chooses ");
}
int main(int argc, const char * argv[])
{
`@autoreleasepool
{
PlayerChoice(0);
ComputerChoice(arc4random_uniform(2));`
}
return 0;
}
所以我真的不知道接下来该做什么。我正在尝试调用我的函数来返回玩家选择的值(0表示摇滚,1表示纸张,或2或剪刀),并为计算机选择生成随机数。之后我打算做一堆if语句来比较这两个值。帮助
答案 0 :(得分:0)
int Rock = 0;
int Paper = 1;
int Scissors = 2;
int PlayerChoice (){
int i = arc4random_uniform(3);
NSLog(@"Player chooses %i", i);
return i;
}
int ComputerChoice (){
int i = arc4random_uniform(3);
NSLog(@"Computer chooses %i", i);
return i;
}
int main(int argc, const char * argv[])
{
@autoreleasepool
{
int p = PlayerChoice();
int c = ComputerChoice();
if (p==c)
NSLog(@"Draw.");
else
if ((p==Rock&&c==Scissors)||(p==Scissors&&c==Paper)||(p==Paper&&c==Rock))
NSLog(@"Player Won.");
else
NSLog(@"Computer Won.");
}
return 0;
}