- //
- // main.c
- // 剪刀石头布
- //
- // Created by apple on 15/5/24.
- // Copyright (c) 2015年 双元课堂(王建军). All rights reserved.
- //
- #include <stdio.h>
- #include <stdlib.h>
- int main(int argc, const char * argv[]) {
-
- printf("欢迎来到石头剪刀布游戏!\n");
- int flag=0;
- printf("输入0进入游戏,退出游戏请输入其他数字!\n");
- scanf("%d",&flag);
- while(!flag)
- {
- int clientCount=0;
- int computerCount = arc4random_uniform(3)+1;
-
- printf("请输入一个1-3的整数重新进入游戏,输入其他数退出游戏\n");
- scanf("%d",&clientCount);
-
- if(clientCount==computerCount)
- {
- printf("真遗憾,平局!\n");
- }
- else if((computerCount==1&&clientCount==2)||(computerCount==2&&clientCount==3)||(computerCount==3&&clientCount==1))
- {
- printf("恭喜你,赢了!\n");
- }
-
- else if((computerCount==1&&clientCount==3)||(computerCount==2&&clientCount==1)||(computerCount==3&&clientCount==2))
- {
-
- printf("运气太臭,输了!\n");
- }
- else
- {
- flag=1;
- }
-
- }
- printf("退出游戏!\n");
- return 0;
- }
复制代码 |
|