// main.c
// 猜拳游戏
// Created by Dast on 15/6/9.
// Copyright (c) 2015年 Dast. All rights reserved.
#include <stdio.h>
#include "stdlib.h"
int main(int argc, const char * argv[])
{
while (1)
{
// 定义变量
int compu,player;
//电脑出拳:随机数函数实现并输出显示
compu = arc4random_uniform(3);
printf("compu == %d\n",compu);
//玩家出拳:提示,输入,判定
printf("input num from stone=0,knife=1,cloth=2:");
scanf("%d",&player);
while (player < 0 || player > 2)
{
printf("input num Again:");
scanf("%d",&player);
}
// 比较, 输出结果
// 石头 0 剪刀1 布2
// 赢的条件:0对1,1对2,2对0.
if(player == 0 && compu == 1 ||player == 1 && compu == 2 || player == 2 && compu == 0 )
printf("u win\n");
else if (player == 1 && compu == 0 || player == 2 && compu == 1 || player == 0 && compu == 2 )
printf("computer win\n");
else
printf("tie\n");
}
return 0;
}
|
|