今天闲来无事,突然后室瘾发作,一通撞墙后,我determination去编写Level!小游戏
首先,来上窗口背景:
Window.h
|-Window_Set 窗口设置
#include<windows.h>
using namespace std;
void Window_Set(void){
HBITMAP hBitmap = (HBITMAP)LoadImage(NULL, "background.jpg", IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE);
HWND hWnd = GetConsoleWindow();
HDC hDC=GetDC(hWnd);
HDC hMemDC = CreateCompatibleDC(hDC);
SelectObject(hMemDC, hBitmap);
BITMAP bmp;
GetObject(hBitmap, sizeof(BITMAP), &bmp);
RECT rect;
GetClientRect(hWnd, &rect);
StretchBlt(hDC, 0, 0, rect.right, rect.bottom, hMemDC, 0, 0, bmp.bmWidth, bmp.bmHeight, SRCCOPY);
ReleaseDC(hWnd, hDC);
DeleteDC(hMemDC);
DeleteObject(hBitmap);
return;
}
之后,常用函数:
void.h
|-color 颜色
|--Out_Win 胜利输出
|---Out_ 正常输出
|----sleep 等待
|-----dead_Message 死亡信息
|------Out_Dead 嗝屁输出
#include<bits/stdc++.h>
#include<fstream>
#include<windows.h>
#include<time.h>
#define KEY_DOWN(VK_NONAME) ((GetAsyncKeyState(VK_NONAME) & 0x8000) ? 1:0)
using namespace std;
//12310024727727722051547701968560956856095510671191010017320231253274034661432361431280312903196031970328203299420313272133194010151216100331412311915338113284031252141014311801014317012101712464776856095021032003128104415827902411410319524101413228023712103193279024114237022702280237023601413103133237023602350102522260227022802371210122370241122710280027901031302280237023601024334711710172371210122370100140241028001031322370102453471191014237010142410271028002790103132237010243347121010152370227022802370238010122800103132237023601024334711434721534710100236023502340233023201012237010132800103132237010244347112347216102142800103132237010243347103472133469131021628001031322370102423471133472123469032701410143270010314223701024134711210133472034680327015101332700103135224022502260227022802370100237010245347213327001013212010123270141031382370100237010244347103472032701410153270123471010313923701002370102433471133472032701310153270131031392280100237010245347103270141016327001031422370102463471123270121013327014103142237010246347112327019103125170102162370102493270151031422370101223701031962380101223701031992370103199237010319923701031992370103199237010319923701031992360103179325703390121031753256010133256010153256010133256121014339003257023803257033901431910103170325703256121003256131003257123256121012325612325701003236133390032600326403390121000123192010316832561232571328103256143257032560281032561332570325503257032560323602190014101301333900103167325603441032671434250325603255032560342503437028003442032561224503178034250003121021900153425010000342503390121031673256034410326703266123267001231780245000342502710281032560342500031780012312002190323603390034250012339003410133390010316832560245032670326612326700123178001231801401234660012323602190342503236033901423701031713256000326703266123267001231780013342500133466031780346612323602190323601014001031723256000326714344100031780342500153466123178034661232360219032360101432340103172325603425001434250325603473123441032701232
void color(int ForgC, int BackC) {
WORD wColor = ((BackC & 0x0F) << 4) + (ForgC & 0x0F);
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), wColor);
}
void Out_Win(){
system("cls");
system("start https://code.xueersi.com");
MessageBox(GetForegroundWindow(),"Game Win!","You Run Out Of Level ! !",1);
}
void Out_(int n,int k,int m,double len,int h){
color(4,4);
for(int i=0;i<50;i++){
cout<<" ";
}
cout<<endl;
color(4,7);
m=m%50;
for(int i=m;i<m+50;i++){
if(i%10==0){
cout<<"E ";
}else{
if(i%10==1){
cout<<"X ";
}else{
if(i%10==2){
cout<<"I ";
}else{
if(i%10==3){
cout<<"T ";
}else{
color(4,12);
cout<<" ";
}
}
}
}
color(4,7);
}
color(14,4);
cout<<endl<<"剩余"<<len<<"米"<<endl;
cout<<"■▲●"<<endl;
cout<<"■●■■"<<endl;
cout<<"|| ■●"<<endl<<"∪|| ";
color(7,4);
for(int i=5;i<k;i++){
cout<<" ";
}
color(14,12);
cout<<"(◎)";
color(13,4);
cout<<endl<<"■■●";
color(0,12);
for(int i=5;i<k;i++){
cout<<" ";
}
color(6,12);
string s;
if(n==0){
s="↑↓";
}else{
s="↓↑";
}
cout<<s<<endl;
color(4,4);
for(int i=0;i<50;i++){
cout<<" ";
}
color(4,12);
}
void sleep(float time){
for(int i=0;i<100000000*time;i++){
cout<<"";
}
}
void say(int i,string str,float speed){
cout<<str[i];
sleep(speed);
if(i!=str.size()){
say(i+1,str,speed);
}else{
cout<<endl;
}
}
void P(){
system("pause");
}
void p(){
cout<<endl;
P();
cout<<endl;
}
void Start(){
system("cls");
system("mode con cols=100 lines=20");
system("title Level!");
system("color c0");
}
string dead_Massage(int x){
string Massage[]={
"你被悲尸吃了",
"你被笑靥嚼成了碎碎!",
"你被派对客以蛋糕的身份邀请进了派对",
"你被寄生寄生了",
"你被钝人阿巴阿巴了",
"你被zsxy2015和蔡徐坤笑死了",
"你摔了个跤,无了",
"你摔了个跤,无了",
"你被死亡飞蛾■■■了",
"你被细菌neng死了",
"你被窃皮者干掉了",
"你被爆酸者酸死了",
"你被健尸撅了",
"你摔了个跤,无了",
"你摔了个跤,无了",
"你摔了个跤,无了",
};
return Massage[x];
}
void Out_Dead(){
system("cls");
color(4,12);
for(int i=0;i<50;i++){
cout<<"■";
}
cout<<endl;
color(4,7);
cout<<endl;
string s;
s=dead_Massage(rand()%16);
cout<<endl<<endl<<endl<<s<<endl;
cout<<" =●"<<endl;
color(4,7);
for(int i=0;i<50-3;i++){
cout<<"■";
}
color(4,12);
pD();
MessageBox(GetForegroundWindow(),"Game over!","You Dead!",1);
for(int i=0;i<10;i++){
MessageBox(GetForegroundWindow(),"Game over!","error!",1);
}
}
最后,再来完成主程序:
Level!.cpp
首先,把头文件导入一下,把该#define的define了
#include<bits/stdc++.h>
#include<fstream>
#include<windows.h>
#include"Window.h"
#include<time.h>
#include"void.h"
#define KEY_DOWN(VK_NONAME) ((GetAsyncKeyState(VK_NONAME) & 0x8000) ? 1:0)
using namespace std;
之后,
变量与窗口:
Window_Set();
Start();
double Lenth=16090;
int i=0,k=15;
int cnt=0,R=0,h=0;
最后
循环游戏主体,嗝屁或胜利时tui出:
while(1){
Out_(i%2,k,i,Lenth,h);
i++;
if(KEY_DOWN(VK_RIGHT)||KEY_DOWN('D')){
cnt++;
Lenth-=0.07*cnt;
}else{
if(R==0){
k--;
cnt=0;
R=5;
}else{
cnt=0;
R--;
}
}
if(cnt>=k&&k<23){
cnt-=k;
k++;
}
if(k<=5){
Out_Dead();
return 0;
}
Lenth-=rand()%4+1;
if(Lenth<0.09){
Out_Win();
break;
}
system("cls");
}