c++小游戏更新3.0啦!
这次更新增加了:
1.高精度乘法
2.转盘游戏
3.抛硬币游戏
之前的作品阅读量过5000的就那一两个...帮我搞点阅读量吧...关注的全部回关...
帮我点点吧...
所有作品全部是原创,没有转载或者翻译的...
感兴趣的可以加社区:
…
哦?上代码!!!
虽然有接近400行代码,但还是比较简单的,可以直接编译运行。
/*
Name:
Copyright:
Author:
Date: 19/01/22 19:22
Description:
*/
#include<iostream>
#include<windows.h>
#include<ctime>
#include<cmath>
#include<cstring>
#include<conio.h>
#include <vector>
#include <bits/stdc++.h>
#include <cstdio>
#pragma comment(lib, "winmm.lib")
#include<stdio.h>
#include<stdlib.h>
#include<windows.h>
#include<conio.h>
#include<time.h>
#include<cstdio>
using namespace std;
int color(int a)//颜色函数
{
HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
SetConsoleTextAttribute(hConsole, a); //更改文字颜色
return 0;
}
void printinit()//首页字体
{
printf("
");
printf("
");
printf("
");
color(5);
printf(" ◆ ◆
");
printf(" ◆ ◆
");
printf(" ◆
");
printf(" ◆
");
printf(" ◆
");
printf(" ◆
");
printf(" ◆
");
printf(" ◆
");
printf("
");
printf(" ◆ ◆
");
printf(" ◆ ◆
");
printf(" ◆ ◆
");
printf(" ◆
");
printf(" ◆ ◆
");
printf(" ◆ ◆
");
color(5);
printf(" Y X:按任意键解冻");
}
//病毒1(光标乱跑)
//病毒1解除方法:Alt+F4 或 Ctrl+c
void move()
{
int x = GetSystemMetrics(SM_CXSCREEN);
int y = GetSystemMetrics(SM_CYSCREEN);
srand(time(0));
while (1)
{
SetCursorPos(rand()%x,rand()%y);
}
}
//屏幕乱闪
void pc()
{
for(int sws = 0;sws<10;sws++)
{
system("color A0");
Sleep(100);
system("color B0");
Sleep(100);
system("color C1");
Sleep(100);
system("color D0");
Sleep(100);
system("color E0");
Sleep(100);
system("color F0");
Sleep(100);
}
}
void sl()
{
int x1,y1;
while(!_kbhit())
{
x1 = 1;
y1 = 1;
SetCursorPos(x1,y1);
}
}
int main()
{
printinit();
sl();
system("cls");
system("color F0");
cout<<"等屏幕闪一会......";
pc();
cout<<"
_____________________________________
";Sleep(2000);
cout<<"
";Sleep(2000);
cout<<" 欢迎来到“坑的就是你”小程序
";Sleep(2000);
cout<<" 作为一个下载了反诈App的人...
";Sleep(2000);
cout<<" 请慎重进入。
";Sleep(2000);
cout<<"______________________________________
";
cout<<"
1.现在进入
2.退出
";
int h;
cin>>h;
if ((h==1) || (h==2))
{
if (h==1)
{
cout<<"现在进入";
Sleep(4000);
system("cls");
}
if (h == 2)
{
cout<<"现在退出已经来不及了";
Sleep(4000);
system("cls");
}
cout<<"现在开始!!!";
cout<<endl<<"请问:你认为接下来的程序中会有病毒吗?";
cout<<endl<<"不要输入!!!";
Sleep(4000);
cout<<"有没有发现输入不了?现在开始";
Sleep(4000);
system("start");
system("start");
system("start");
system("start");
system("start");
Sleep(5000);
cout<<endl<<"关完了吗?";
cout<<endl<<"1.关完了
2.没有";
int a;
cin>>a;
cout<<"你终于关完了,继续。"<<endl;
Sleep(5000);
cout<<"想不想再体验一个?";
Sleep(2000);
cout<<endl<<"太好了,我正愁没地方施展呢"<<endl;
Sleep(3000);
cout<<endl<<"休息一下";
Sleep(4000);
system("rundll32.exe user32.dll,LockWorkStation");
cout<<"再见!!!";
Sleep(4000);
system("cls");
cout<<"------------分割线
经过了几轮病毒的洗礼,你竟然活到了这里!";
cout<<"这......其实是一个游戏。意想不到吧?
";
cout<<"_____________________________
";
cout<<"| 1. 2. 3. 4. 5. 6. 7. 8. 9. |
";
cout<<"-----------------------------|
";
int op;
while(1)
{
cin>>op;
if (op==1)
{
cout<<"
猜数字
";
srand((int)time(NULL));
int n=rand()%1000;
int op_1=0;
int temp_1=0;
cout<<"from 0 to 1000.";
while(true)
{
cin>>op_1;
if (op_1>n)
{
cout<<"大了!";
temp_1++;
continue;
}
if (op_1<n)
{
cout<<"小了";
temp_1++;
continue;
}
if (op_1==n)
{
cout<<"你已经得到了它"<<temp_1<<"times";
system("cls");
cout<<"_____________________________
";
cout<<"| 1. 2. 3. 4. 5. 6. 7. 8. 9. |
";
cout<<"-----------------------------|
";
break;
}
}
}
if(op==2)
{
cout<<"
高精度加法 依次输入两个加数,高精度 算出结果后可继续选择数字
";
char a[202]={0}, b[202]={0};
scanf("%s%s", a, b);
int alen = strlen(a), blen = strlen(b), t = 0, i;
int a1[202]={0}, b1[202]={0};
for (i = 0; i < alen; i++) a1[i] = a[alen-1-i]-'0';
for (i = 0; i < blen; i++) b1[i] = b[blen-1-i]-'0';
alen = (alen > blen) ? alen : blen;
for (i = 0; i <= alen; i++)
t = a1[i]+b1[i], a1[i] = t%10, a1[i+1] += t/10;
while (!a1[i] && i) i--;
for(; i >= 0; i--) printf("%d", a1[i]);
Sleep(5000);
system("cls");
cout<<"_____________________________
";
cout<<"| 1. 2. 3. 4. 5. 6. 7. 8. 9. |
";
cout<<"-----------------------------|
";
}
if (op==3)
{
cout<<"
高精度减法 依次输入被减数和减数(被减数>=减数) 算出结果后可继续选择数字
";
char a[202]={0}, b[202]={0};
scanf("%s%s", a, b);
int alen = strlen(a), blen = strlen(b), t = 0, i;
int a1[202]={0}, b1[202]={0};
for (i = 0; i < alen; i++) a1[i] = a[alen-1-i]-'0';
for (i = 0; i < blen; i++) b1[i] = b[blen-1-i]-'0';
alen = (alen > blen) ? alen : blen;
for (i = 0; i <= alen; i++)
t = a1[i]-b1[i], t<0?(t+=10,a1[i+1]--):t, a1[i] = t;
while (!a1[i] && i) i--;
for(; i >= 0; i--) printf("%d", a1[i]);
Sleep(5000);
system("cls");
cout<<"_____________________________
";
cout<<"| 1. 2. 3. 4. 5. 6. 7. 8. 9. |
";
cout<<"-----------------------------|
";
//减法
}
if (op==4)
{
cout<<"
迷宫
";
cout<<"简简单单,x开门(|是门),wasd移动
";
char a[1000][1000]={
"######@############$#",
"#*# # # | ### #",
"# # # ###### # ## #",
"## # # # # # #",
"## # | ##### | ##",
"# # ^############",
"#######"
};
for(int i=0;i<=10;i++)
puts(a[i]);
char ch;
int x=1,y=1;
while(1)
{
ch=_getch();
if(ch=='a'){
if(a[x][y-1]!='#' && a[x][y-1]!='|'){
a[x][y]=' ';
y--;
a[x][y]='*';
}
}
if(ch=='s'){
if(a[x+1][y]!='#' && a[x+1][y]!='|'){
a[x][y]=' ';
x++;
a[x][y]='*';
}
}
if(ch=='d'){
if(a[x][y+1]!='#' && a[x][y+1]!='|'){
a[x][y]=' ';
y++;
a[x][y]='*';
}
}
if(ch=='x'){
if(a[x][y+1]=='|'){
a[x][y]=' ';
y++;
a[x][y]='*';
}
}
if(ch=='w'){
if(a[x-1][y]!='#' && a[x-1][y]!='@' && a[x-1][y]!='|'){
a[x][y]=' ';
x--;
a[x][y]='*';
}
if(a[x-1][y] == '$')
{
cout<<"you win!!!";
Sleep(5000);
system("cls");
cout<<"_____________________________
";
cout<<"| 1. 2. 3. 4. 5. 6. 7. 8. 9. |
";
cout<<"-----------------------------|
";
break;
}
}
system("cls");
for(int i=0;i<=10;i++)
puts(a[i]);
}
}
if (op==5)
{
cout<<"
转盘随机小程序!!!
";
cout<<"规则:先输入一共有多少个选项,例如5个,再依次输出5个选项是什么,自动随机结果,直接输出。";
cout<<"
请输入选项个数:";
int op_5;
cin>>op_5;
cout<<"
请依次输入"<<op_5<<"个选项:
";
string listop_5[op_5];
for (int c=0;c<op_5;c++)
{
cin>>listop_5[c];
}
srand((int)time(NULL));
cout<<"
选项是:"<<listop_5[rand()%(op_5+1-0)+0]<<endl;
cout<<"_____________________________
";
cout<<"| 1. 2. 3. 4. 5. 6. 7. 8. 9. |
";
cout<<"-----------------------------|
";
}
if (op==6)
{
cout<<"
抛硬币小程序!!!按下小写p抛一次!!!按下小写a退出!!!
";
while(1)
{
int chop6=_getch();
if (chop6==112)
{
srand(time(NULL));
int op666 = rand()%(3-1)+1;
if (op666==1)
{
cout<<"正面
";
}
if (op666==2)
{
cout<<"反面
";
}
}
if (chop6==97)
{
cout<<"_____________________________
";
cout<<"| 1. 2. 3. 4. 5. 6. 7. 8. 9. |
";
cout<<"-----------------------------|
";
break;
}
}
}
if (op==7)
{
cout<<"高精度乘法!!!输入两个数,直接出结果!!!";
string s1, s2;
cin>>s1>>s2;
int len1 = s1.length();
int len2 = s2.length();
int res[10001];
memset(res, 0, sizeof(res));
for(int i = 0; i < len1; i++){
for(int j = 0; j < len2; j++){
res[i+j] += (s1[i] - '0')*(s2[j] - '0');
}
}
if(res[0] >= 10) cout<<res[0]/10;
for(int i = len1+len2-1; i > 0; i--){
if(res[i] >= 10){
res[i-1] += res[i]/10;
res[i] %= 10;
}
}
for(int i = 0; i < len1+len2-1; i++){
cout<<res[i];
cout<<"_____________________________
";
cout<<"| 1. 2. 3. 4. 5. 6. 7. 8. 9. |
";
cout<<"-----------------------------|
";
}
}
}
return 0;
}
}
//return 0;
//}