当前位置:网站首页>A lottery like scissors, stone and cloth (C language)
A lottery like scissors, stone and cloth (C language)
2022-07-03 09:52:00 【Embed it?】
A lottery 《 scissors 》(C Language )
Today we will introduce a game called :~~ scissors ~~ Oh !! cloth ……… He was actually drawn by lot .
A traditional scissors stone cloth , It looks something like this ——>
It's a judgment based on what happens to both sides , Who wins and who loses in a game .
But I don't think such a rule , In programming , Is it a little unfriendly to our programmers ?( Just a little bit of trouble ……)
So I came up with a simple method , To judge who wins and who loses .
Namely ,
* No Examination Consideration
What happens to players , It's numbers randomly given by the computer , To judge the victory 、 It's negative 、 It's a draw *
- 6、 ... and
Warm reminder : The header files of the following two functions are stdlib.h and time.h
adopt srand() Function and time() To produce a true random number
Re pass rand()%3, obtain 0、1、2 A certain number between
Then there is the use if sentence :
- if 0, Then the player wins ;
- if 1, Then the computer wins ;
- if 2, It's a draw ;
In this way, it looks like drawing lots ?
If you want to see your luck , Just copy the code and play a few games !
The code is as follows :
#include<stdio.h>
#include<stdlib.h>
#include<time.h>
int game();
void menu()
{
printf("#####################################\n");
printf("### ###\n");
printf("### 1、 Start 0、 sign out ###\n");
printf("### ###\n");
printf("#####################################\n");
}
int begin()
{
int x = 0;
printf(" type :1 or 0\n");
while(1)
{
printf(" Please select :");
scanf("%d",&x);
switch(x)
{
case 1:
printf("\n Successful entry into the game \n");
game();
printf("\n The game is over .\n 1 or 0\n");
break;
case 0:
printf(" Quit the game \n");
goto Loop;
break;
default:
printf(" Input format error , Please re-enter !\n");
break;
}
}
Loop:
return 0;
}
int game()
{
int ps = 0;
// Players and computers play tricks
int cop = rand()%3;//cop ~~ [0,2]
printf("\n The player :\n\n stone :0\n scissors :1\n cloth :2\n Please select :");
scanf("%d",&ps);
// Player stage
if(ps==0)
{
printf("\n Player out : stone \n");
}
else if(ps==1)
{
printf("\n Player out : scissors \n");
}
else if(ps==2)
{
printf("\n Player out : cloth \n");
}
// Computer phase + Judgment stage
if(cop==0)// When cop==0 when , Computer input .
{
if(ps==0)
{
printf(" Computer out : scissors \n");
}
else if(ps==1)
{
printf(" Computer out : cloth \n");
}
else if(ps==2)
{
printf(" Computer out : stone \n");
}
printf("\n The player wins !!\n");
}
else if(cop==1) // When cop==1 when , Computers win .
{
if(ps==0)
{
printf(" Computer out : cloth \n");
}
else if(ps==1)
{
printf(" Computer out : stone \n");
}
else if(ps==2)
{
printf(" Computer out : scissors \n");
}
printf("\n The computer wins !!\n");
}
else if(cop==2) // When cop==2 when , It ends in a draw .
{
if(ps==0)
{
printf(" Computer out : stone \n");
}
else if(ps==1)
{
printf(" Computer out : scissors \n");
}
else if(ps==2)
{
printf(" Computer out : cloth \n");
}
printf("\n It ends in a draw ……\n");
}
return 0;
}
int main()
{
srand((unsigned)time(NULL));//unsigned >= 0
menu();
begin();
return 0;
}
The above is purely Mengxin's speech , Don't be surprised to see the boss , Don't laugh .
边栏推荐
- Idea remote breakpoint debugging jar package project
- 编程思想比任何都重要,不是比谁多会用几个函数而是比程序的理解
- Hal library sets STM32 clock
- 学历是一张通行证,门票,你有了它,可以踏入更高层次的环境里
- Jetson nano custom boot icon kernel logo CBOOT logo
- Fundamentals of Electronic Technology (III)_ Integrated operational amplifier and its application__ Basic arithmetic circuit
- 当你需要使用STM32某些功能,而51实现不了时, 那32自然不需要学
- The cyclic shift of PUCCH in NR channel is generated by MATLAB
- [CSDN]C1训练题解析_第三部分_JS基础
- How MySQL modifies null to not null
猜你喜欢
[22 graduation season] I'm a graduate yo~
顺利毕业[2]-学生健康管理系统 功能开发中。。。
Nodemcu-esp8266 development board to build Arduino ide development environment
STM32 interrupt priority management
uniapp 实现微信小程序全局分享及自定义分享按钮样式
Directory and switching operation in file system
[combinatorics] Introduction to Combinatorics (combinatorial thought 2: mathematical induction | mathematical induction promotion | multiple induction thought)
Electronic product design, MCU development, circuit cloning
Fundamentals of Electronic Technology (III)__ Chapter 1 resistance of parallel circuit
我想各位朋友都应该知道学习的基本规律就是:从易到难
随机推荐
Hal library sets STM32 clock
UCI and data multiplexing are transmitted on Pusch (Part VI) -- LDPC coding
[22 graduation season] I'm a graduate yo~
手机都算是单片机的一种,只不过它用的硬件不是51的芯片
对于新入行的同学,如果你完全没有接触单片机,建议51单片机入门
Nr-prach: access scenario and access process
Patent inquiry website
MySQL 数据库基础知识(系统化一篇入门)
Runtime.getRuntime().gc() 和 Runtime.getRuntime().runFinalization() 的区别
Uncle Wang's blog directory [constantly updating]
1922. Count Good Numbers
一个可执行的二进制文件包含的不仅仅是机器指令
Successful graduation [2] - student health management system function development...
Nr--- Pusch I: sorting out the agreement process
Nodemcu-esp8266 development (vscode+platformio+arduino framework): Part 5 --blinker_ MIOT_ MULTI_ Outside (lighting technology app + Xiaoai classmate control socket multiple jacks)
Leetcode daily question (1856. maximum subarray min product)
Leetcode daily question (745. prefix and suffix search)
Fundamentals of Electronic Technology (III)_ Integrated operational amplifier and its application__ Basic arithmetic circuit
Characteristics of PUCCH formats
STM32 serial port usart1 routine