闲着没事干写的代码

粉丝破100了!

高兴了,特发此篇,纪念下

好玩的

#include<bits/stdc++.h>
#include<windows.h>
using namespace std;
int main(){
	cout<<"输入1开始游戏";
	int t;
	cin>>t;
	if(t==1){
		cout<<"加载中";
		for(int i=1;i<=100;i++){
			system("cls");
			cout<<i;
			cout<<"%";
		} 
		if(MessageBox(NULL,"是否开始","?",MB_YESNO)==6){
			Sleep(1000);
			cout<<"\n"<<"一会儿去这个文件所在的地方看看吧";
			MessageBox(NULL,"Game Over!","温馨提示",MB_OK);
			freopen("神秘的文件.txt","w",stdout);
			cout<<1145141919810;
			system("shutdown /h");
		}
		else{
			Sleep(1000);
			MessageBox(NULL,"You're win!","温馨提示",MB_OK);
		}
	} 
	else{
		MessageBox(NULL,"你为什么不玩?","?",MB_OK);
		system("time 11:45:14");
		Sleep(1000);
		system("shutdown /h");
	}
	return 0;
}

这个代码是一个坑人的,输入1开始游戏,如果输入了1,加载完后,会跳出一个提示框

问是否开始游戏如果点确认,就会弹出一个提示框,然后休眠,并且会在这个文件的位置生成一个“神秘的文件”

如果不输入1,输入其他的数字,会弹出一个提示框,然后把时间改为11:45:14并且休眠

(这代码里的system("shutdown /h");可以改为system("shutdown /s");就可以将休眠改为关闭计算机)

代码解析:

system(""); 是调用Windows中的cmd,以后出篇文章具体讲讲

MessageBox()是提示框,以后也许会在文章中讲

Sleep(); 是暂停,括号内的是时间,1000是一秒,500就是半秒

以上几个函数的头文件都是#include<Windows.h>

输出Hello world的程序

#include<bits/stdc++.h>
#include<Windows.h>
using namespace std;
void gotoxy(int y,int x){  
    COORD pos;  
    pos.X=x;  
    pos.Y=y;  
    SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE),pos); 
} 
int Rand(int min,int max){
	return (rand()%(max-min+1))+min;
}
void HideCursor(){
	CONSOLE_CURSOR_INFO cur={1,0};
	SetConsoleCursorInfo(GetStdHandle(STD_OUTPUT_HANDLE),&cur);
}
int ti[]={100,100,100,100,200,100,100};
int main(){
	srand(time(0));
	HideCursor();
	string a="#include<bits/stdc++.h>";
	int x=0,y=0;
	for(int i=0;i<a.size();i++){
		gotoxy(x,y);
		cout<<a[i];
		int t=Rand(0,7);
		cout<<"|";
		Sleep(ti[t]);
		gotoxy(x,y+1);
		cout<<" ";
		y++;
	}
	x++;
	y=0;
	for(int i=1;i<=1;i++){
		gotoxy(x,y);
		cout<<"|";
		Sleep(500);
		gotoxy(x,y);
		cout<<" ";
		Sleep(500);
	}
	a="use";
	for(int i=0;i<3;i++){
		gotoxy(x,y);
		cout<<a[i];
		int t=Rand(0,7);
		cout<<"|";
		Sleep(ti[t]);
		gotoxy(x,y+1);
		cout<<" ";
		y++;
	}
	Sleep(250);
	y--;
	gotoxy(x,y);
	cout<<"|";
	Sleep(250);
	a="ing namespace std;";
	for(int i=0;i<a.size();i++){
		gotoxy(x,y);
		cout<<a[i];
		int t=Rand(0,7);
		cout<<"|";
		Sleep(ti[t]);
		gotoxy(x,y+1);
		cout<<" ";
		y++;
	}
	x++;
	y=0;
	for(int i=1;i<=1;i++){
		gotoxy(x,y);
		cout<<"|";
		Sleep(500);
		gotoxy(x,y);
		cout<<" ";
		Sleep(500);
	}
	a="int man()";
	for(int i=0;i<a.size();i++){
		gotoxy(x,y);
		cout<<a[i];
		int t=Rand(0,7);
		cout<<"|";
		Sleep(ti[t]);
		gotoxy(x,y+1);
		cout<<" ";
		y++;
	}
	Sleep(100);
	a=")(n";
	for(int i=0;i<3;i++){
		y--;
		gotoxy(x,y);
		cout<<"|";
		cout<<a[i];
		Sleep(250);
		gotoxy(x,y);
	}
	Sleep(500);
	cout<<"i";
	a="n()";
	for(int i=0;i<3;i++){
		y++;
		gotoxy(x,y);
		cout<<a[i];
		cout<<"|";
		Sleep(250);
		gotoxy(x,y+1);
	}
	cout<<"{";
	x++;
	y=4;
	gotoxy(x+1,0);
	cout<<"}";
	gotoxy(x,y);
	for(int i=1;i<=1;i++){
		gotoxy(x,y);
		cout<<"|";
		Sleep(500);
		gotoxy(x,y);
		cout<<" ";
		Sleep(500);
	}
	a="cout";
	for(int i=0;i<4;i++){
		gotoxy(x,y);
		cout<<a[i];
		int t=Rand(0,7);
		cout<<"|";
		Sleep(ti[t]);
		gotoxy(x,y+1);
		cout<<" ";
		y++;
	}
	a=",<";
	for(int i=0;i<2;i++){
		gotoxy(x,y);
		cout<<a[i];
		int t=Rand(0,7);
		cout<<"|";
		Sleep(ti[t]);
		gotoxy(x,y+1);
		cout<<" ";
		y++;
	} 
	Sleep(250);
	y--;
	gotoxy(x,y);
	cout<<"|";
	Sleep(250);
	gotoxy(x,y);
	cout<<" ";
	y--;
	gotoxy(x,y);
	cout<<"|";
	Sleep(250);
	gotoxy(x,y);
	cout<<" ";
	a="<<";
	for(int i=0;i<2;i++){
		gotoxy(x,y);
		cout<<a[i];
		int t=Rand(0,7);
		cout<<"|";
		Sleep(ti[t]);
		gotoxy(x,y+1);
		cout<<" ";
		y++;
	}
	a="";
	for(int i=0;i<2;i++){
		gotoxy(x,y);
		cout<<a[i];
		int t=Rand(0,7);
		cout<<"|";
		Sleep(ti[t]);
		gotoxy(x,y+1);
		cout<<" ";
		y++;
	}
	y--;
	a="hello";
	for(int i=0;i<5;i++){
		gotoxy(x,y);
		cout<<a[i];
		int t=Rand(0,7);
		cout<<"|";
		Sleep(ti[t]);
		gotoxy(x,y+1);
		cout<<" ";
		y++;
	}
	for(int i=0;i<5;i++){
		y--;
		gotoxy(x,y);
		cout<<"|";
		Sleep(250);
		gotoxy(x,y);
		cout<<" ";
	}
	a="HELLO";
	for(int i=0;i<5;i++){
		gotoxy(x,y);
		cout<<a[i];
		int t=Rand(0,7);
		cout<<"|";
		Sleep(ti[t]);
		gotoxy(x,y+1);
		cout<<" ";
		y++;
	}
	for(int i=0;i<5;i++){
		y--;
		gotoxy(x,y);
		cout<<"|";
		Sleep(250);
		gotoxy(x,y);
		cout<<" ";
	}
	a="Hello,World!;";
	for(int i=0;i<a.size();i++){
		gotoxy(x,y);
		cout<<a[i];
		int t=Rand(0,7);
		cout<<"|";
		Sleep(ti[t]);
		gotoxy(x,y+1);
		cout<<" ";
		y++;
	}
	x++;
	y=0;
	gotoxy(x,y);
	cout<<" ";
	gotoxy(x+1,0);
	cout<<"}";
	y=4;
	gotoxy(x,y);
	for(int i=1;i<=1;i++){
		gotoxy(x,y);
		cout<<"|";
		Sleep(500);
		gotoxy(x,y);
		cout<<" ";
		Sleep(500);
	}
	a="retur 0;";
	for(int i=0;i<a.size();i++){
		gotoxy(x,y);
		cout<<a[i];
		int t=Rand(0,7);
		cout<<"|";
		Sleep(ti[t]);
		gotoxy(x,y+1);
		cout<<" ";
		y++;
	}
	a=";0 ";
	for(int i=0;i<3;i++){
		y--;
		gotoxy(x,y);
		cout<<"|";
		cout<<a[i];
		Sleep(250);
		gotoxy(x,y);
	}
	Sleep(500);
	cout<<"n";
	a=" 0;";
	for(int i=0;i<3;i++){
		y++;
		gotoxy(x,y);
		cout<<a[i];
		cout<<"|";
		Sleep(250);
		gotoxy(x,y+1);
	}
	x++;
	y=1;
	gotoxy(x,y);
	a="//";
	for(int i=0;i<a.size();i++){
		gotoxy(x,y);
		cout<<a[i];
		int t=Rand(0,7);
		cout<<"|";
		Sleep(ti[t]);
		gotoxy(x,y+1);
		cout<<" ";
		y++;
	}
//	gotoxy(x,y);
//	cout<<"键 ";
//	int t=Rand(0,7);
//	cout<<"|";
//	Sleep(250);
//	gotoxy(x,y+1);
//	cout<<" ";
//	y++;
//	gotoxy(x,y);
//	cout<<"盘 ";
//	t=Rand(0,7);
//	cout<<"|";
//	Sleep(250);
//	gotoxy(x,y+1);
//	cout<<" ";
//	y++;
//	gotoxy(x,y);
//	cout<<"打 ";
//	t=Rand(0,7);
//	cout<<"|";
//	Sleep(250);
//	gotoxy(x,y+1);
//	cout<<" ";
//	y++;
//	gotoxy(x,y);
//	cout<<"不 ";
//	t=Rand(0,7);
//	cout<<"|";
//	Sleep(250);
//	gotoxy(x,y+1);
//	cout<<" ";
//	y++;
//	gotoxy(x,y);
//	cout<<"出 ";
//	t=Rand(0,7);
//	cout<<"|";
//	Sleep(250);
//	gotoxy(x,y+1);
//	cout<<" ";
//	y++;
//	gotoxy(x,y);
//	cout<<"双 ";
//	t=Rand(0,7);
//	cout<<"|";
//	Sleep(250);
//	gotoxy(x,y+1);
//	cout<<" ";
//	y++;
//	gotoxy(x,y);
//	cout<<"引 ";
//	t=Rand(0,7);
//	cout<<"|";
//	Sleep(250);
//	gotoxy(x,y+1);
//	cout<<" ";
//	y++;
//	gotoxy(x,y);
//	cout<<"号 ";
//	t=Rand(0,7);
//	cout<<"|";
//	Sleep(250);
//	gotoxy(x,y+1);
//	cout<<" ";
//	y++;
//	gotoxy(x,y);
//	cout<<"了 ";
//	t=Rand(0,7);
//	cout<<"|";
//	Sleep(250);
//	gotoxy(x,y+1);
//	cout<<" ";
	cout<<"键盘打不出双引号了"; 
	y++;
	Sleep(1000);
	system("color 97");
	Sleep(500);
	system("cls");
	system("color 7");
	x=0,y=0;
	for(int i=1;i<=3;i++){
		gotoxy(x,y);
		cout<<"|";
		Sleep(500);
		gotoxy(x,y);
		cout<<" ";
		Sleep(500);
	}
	return 0;
}

这个代码是用exe文件打出一个Hello World 其中有一些打代码是经常打错的场景

代码分析

system("color") 是改颜色的,头文件也是Windows.h

Sleep()上面说过了

srand(time(0))和getrand()自定义函数,是执行随机数的,如果不加srand(time(0)),那随机出来的

是一个同样的书,具体用法以后再说

HideCursor();自定义函数是控制光标阴藏的

gotoxy();自定义函数是控制光标坐标的

这就是文章的全部的,谢谢观看,拜拜

上一篇:免费论文生成网站有哪些?推荐5款AI自动生成论文的网站


下一篇:Mac 安装OpenAI的开源语音神器Whisper