编写剪刀(scissor)、石头(stone)、布(cloth)游戏
来源:互联网 发布:substr_replace php 编辑:程序博客网 时间:2024/04/29 07:19
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
int main(void)
{
int user = -1;
int computer = -1;
int result = -1;
char gesture[3][16] = {"scissor","stone", "cloth"};
#if 0
printf("%s\n", gesture[0]);
printf("%s\n", gesture[1]);
printf("%c\n", gesture[1][3]);
#endif
#if 1
srand(time(NULL));
while (1) {
// 1. 提示用户进行输入
INPUT:
printf("Please input thegesture (0 - scissor 1 - stone 2 - cloth 3 - quit):\n");
// 2. 接收用户的输入
scanf("%d", &user);
if (user < 0 || user > 3) {
goto INPUT;
}
if (user == 3) {
break;
}
// 3. 程序随机生成石头、剪刀、布中的一种
computer = rand() % 3;
// 4. 打印用户输入和电脑生成的信息
printf("\nYour:%s\tComputer: %s\n", gesture[user], gesture[computer]);
// 5. 根据游戏规则,判断输赢结果
// (U - C + 4 ) % 3 - 1
result = (user - computer + 4) %3 - 1;
// 6. 输出结果
if (result > 0) {
printf("You Win!\n");
} else if (result == 0) {
printf("Draw!\n");
} else {
printf("You lose!\n");
}
}
#endif
printf("Thanks for yourjoin!\n");
return 0;
}
- 编写剪刀(scissor)、石头(stone)、布(cloth)游戏
- scissor-stone-cloth Game develpment
- java编写剪刀石头布游戏
- (scissor , rock , paper) 三星题 剪刀石头布
- 剪刀、石头、布游戏
- 剪刀石头布游戏
- 剪刀石头布游戏
- 石头剪刀布游戏
- 剪刀石头布游戏
- 石头剪刀布游戏
- 石头,剪刀,布游戏
- 石头-剪刀-布游戏
- 石头剪刀布游戏
- 石头剪刀布游戏
- 石头、剪刀布游戏
- Java 小例子:编写石头剪刀布游戏
- Python编写的一个简单的石头剪刀布游戏
- 游戏_石头,剪刀,布
- Django-Rest-Framework 教程: 快速入门
- 已知一个数出现的次数超过了一半,请用O(n)的复杂度的算法找出这个数
- android充电
- spring定时任务+线池程实现
- AlphaAnimation 、AnimationDrawable
- 编写剪刀(scissor)、石头(stone)、布(cloth)游戏
- 最全中文停用词表整理(1893个)
- VC环境下的灵活运用
- 会员订单列表(二)
- git常用命令
- Django-Rest-Framework 教程: 1. 序列化 (Serialization)
- Metasploit学习笔记之——情报搜集
- 【深入理解javascript原型和闭包系列 】 历时半月完稿,求推荐
- 堆排序实现及应用