当前位置:网站首页>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 .
边栏推荐
- Project cost management__ Cost management technology__ Article 7 completion performance index (tcpi)
- SCM career development: those who can continue to do it have become great people. If they can't endure it, they will resign or change their careers
- Fundamentals of Electronic Technology (III)__ Logic gate symbols in Chapter 5
- numpy. Reshape() and resize() functions
- Getting started with JMX, MBean, mxbean, mbeanserver
- CEF下载,编译工程
- Leetcode daily question (1362. closest divisors)
- Flink learning notes (10) Flink fault tolerance mechanism
- 应用最广泛的8位单片机当然也是初学者们最容易上手学习的单片机
- 【力扣刷题笔记(二)】特别技巧,模块突破,45道经典题目分类总结,在不断巩固中精进
猜你喜欢

Programming ideas are more important than anything, not more than who can use several functions, but more than the understanding of the program

STM32 port multiplexing and remapping

Electronic product design, MCU development, circuit cloning

STM32 interrupt priority management

Nodemcu-esp8266 development (vscode+platformio+arduino framework): Part 4 --blinker_ DHT_ WiFi (lighting technology app control + temperature and humidity data app display)

How MySQL modifies null to not null

CEF download, compile project

手机都算是单片机的一种,只不过它用的硬件不是51的芯片
![Successful graduation [2] - student health management system function development...](/img/91/72cdea3eb3f61315595330d2c9016d.png)
Successful graduation [2] - student health management system function development...
![Uncle Wang's blog directory [constantly updating]](/img/91/72cdea3eb3f61315595330d2c9016d.png)
Uncle Wang's blog directory [constantly updating]
随机推荐
当你需要使用STM32某些功能,而51实现不了时, 那32自然不需要学
要選擇那種語言為單片機編寫程序呢
numpy. Reshape() and resize() functions
Education is a pass and ticket. With it, you can step into a higher-level environment
STM32 interrupt priority management
Leetcode daily question (2109. adding spaces to a string)
Project scope management__ Scope management plan and scope specification
QT qcombobox QSS style settings
MySQL 数据库基础知识(系统化一篇入门)
[CSDN]C1訓練題解析_第三部分_JS基礎
The number of weak characters in the game (1996)
Nodemcu-esp8266 development board to build Arduino ide development environment
MySQL environment variable configuration
Programming ideas are more important than anything, not more than who can use several functions, but more than the understanding of the program
IDEA远程断点调试jar包项目
UCI and data multiplexing are transmitted on Pusch - determine the bit number of harqack, csi1 and csi2 (Part II)
Hal library sets STM32 clock
Leetcode daily question (985. sum of even numbers after queries)
Matlab reads hexadecimal numbers and converts them into signed short
[CSDN]C1训练题解析_第四部分_Web进阶