C++背景移動
現在有很多像我一樣的同學喜歡用C++來做一點小游戲自娛自樂,我這里有一個移動背景的程式,如果對你有幫助的話,可以借鑒一下,
#include<bits/stdc++.h>
#include<windows.h>
#include<conio.h>
#include<thread>
using namespace std;
char a;
string Map[1000];
int tx=100,ty=200,x=125,y=250;
int wp[1000];
void hide()
{
HANDLE handle = GetStdHandle(STD_OUTPUT_HANDLE);
CONSOLE_CURSOR_INFO CursorInfo;
GetConsoleCursorInfo(handle, &CursorInfo);
CursorInfo.bVisible = false;
SetConsoleCursorInfo(handle, &CursorInfo);
}
void csh()
{
SYSTEMTIME systemtime;
GetLocalTime(&systemtime);
srand(systemtime.wMinute * systemtime.wSecond * systemtime.wMilliseconds);
SetConsoleTitle("Don't Stave");
hide();
}
void cls()
{
COORD pos = {0,0};
HANDLE hOut = GetStdHandle(STD_OUTPUT_HANDLE);
SetConsoleCursorPosition(hOut, pos);
}
void loading_things(char t,int n)
{
int x,y;
for(int i=0;i<n;i++)
{
x=rand()%250;
y=rand()%500;
while(Map[x][y]!='.')
{
x=rand()%500;
y=rand()%500;
}
Map[x][y]=t;
}
}
void l_k(int x,int y)
{
Map[x][y]='.';
}
void loading_map()
{
for(int i=0;i<500;i++)
{
for(int j=0;j<1000;j++)
{
Map[i]=Map[i]+" ";
}
}
for(int i=0;i<250;i++)
{
for(int j=0;j<500;j++)
{
Map[i][j]='.';
}
}
loading_things('G',1000);
loading_things('T',500);
loading_things('S',500);
}
void would()
{
while(1)
{
cls();
for(int i=x-12;i<x+12;i++)
{
for(int j=y-24;j<y+24;j++)
{
if(i<0||j<0||i>250||j>500)
{
cout<<" ";
}
else
if(i==x&&j==y)
{
cout<<"@";
}
else
cout<<Map[i][j];
}
cout<<endl;
}
a=getch();
if(a=='w'&&x>0)
{
x--;
}
else
if(a=='s'&&x<249)
{
x++;
}
else
if(a=='a'&&y>0)
{
y--;
}
else
if(a=='d'&&y<499)
{
y++;
}
}
}
int main()
{
csh();
loading_map();
would();
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/240465.html
標籤:其他
上一篇:力扣292.Nim游戲---動態規劃與巧妙的數學思想
下一篇:推箱子——帶有圖形界面
