0

对此仍然很陌生,所以我遇到了一些麻烦。谁能指引我正确的方向,那就太好了。这是我到目前为止的代码:

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 语句来比较这两个值。帮助?

4

1 回答 1

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;

}
于 2013-11-04T06:55:29.200 回答