- 游戏
- 2015-11-29 09:59:40 @
#include<iostream>
#include<fstream>
#include<cstdio>
#include<stdlib.h>
#include<windows.h>
#include<time.h>
#include<conio.h>
using namespace std;
#define MapWide 23
#define MaxMap 3
#define MaxRes 2
#define MaxEnemy 4
//Block data
#define Empty 0
#define Coin 1
#define Block 2
#define Block2 3
#define Barrier 4
#define Barrier2 5
#define Pow 6
#define Invisi 7
#define BlockCount 8
//Color data
#define DarkBlue 1
#define Brown 6
#define Blue 9
#define Red 12
#define Pink 13
#define Yellow 14
#define White 15
//Direction data
#define Up 0
#define Left 1
#define Down 2
#define Right 3
//SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),0);
bool FastMove=false;
char filename[30];
int PowTime;
int PlayerLife=3;
int Resourse=0;
int MapChosen=0;
int TotalCoin;
int CurrentCoin;
int map[MapWide][MapWide];
char BlockRes[MaxRes][BlockCount][3]={
{" ","·","■","□","━","┅","●"," "},
{" ","﹩","●","◎","━","┅","£"," "}
};
char ResName[MaxRes][31]={"Classic","I <3 money"};
const int save[MaxMap][MapWide][MapWide]={
{
{2,2,3,2,2,2,2,2,3,3,2,1,2,2,2,2,2,3,3,3,3,3,2},//0
{2,1,1,1,1,1,1,1,1,1,1,0,1,1,1,1,1,1,1,1,1,1,2},//1
{3,1,2,2,2,1,2,2,2,2,2,1,2,3,2,2,2,1,2,2,2,1,2},//2
{3,1,3,3,2,1,2,3,3,2,2,1,2,2,2,2,2,1,3,2,2,1,2},//3
{2,1,2,2,3,1,2,2,2,2,3,1,2,2,3,2,2,1,2,2,2,1,3},//4
{2,1,1,1,6,1,1,1,1,1,1,1,1,1,1,1,1,1,6,1,1,1,2},//5
{3,1,2,3,1,2,2,2,3,2,2,1,2,2,3,2,2,2,1,3,2,1,2},//6
{2,1,2,2,1,2,3,2,2,2,2,1,2,2,2,2,2,3,1,2,2,1,2},//7
{2,1,2,2,1,2,2,1,1,1,1,1,1,1,1,1,2,2,1,2,2,1,2},//8
{3,1,3,2,1,3,2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2,2,1,2,2,2,1,2,2,2,2,2,2,2,1,2,2,1,2},
{2,1,1,2,6,1,1,1,1,2,1,1,1,1,1,2,2,2,2,2,1,1,2},
{2,2,1,2,1,2,2,2,1,2,2,2,2,2,2,1,1,1,2,2,1,2,2},
{2,2,1,1,1,2,2,1,1,1,1,1,1,1,1,1,2,1,1,1,1,2,2},
{2,2,2,2,2,2,2,1,2,2,4,4,4,2,2,1,2,1,2,2,1,2,2},
{2,2,2,2,2,2,2,1,2,0,0,0,0,0,2,1,2,1,2,1,1,1,2},
{2,1,1,1,1,1,1,1,2,0,0,0,0,0,2,1,2,2,2,2,2,1,2},
{2,1,2,2,2,2,2,1,2,0,0,0,0,0,2,1,1,1,2,2,2,1,2},
{2,1,2,2,2,2,2,1,2,2,2,2,2,2,2,1,2,1,2,2,2,1,2},
{2,1,2,2,2,2,2,1,2,1,2,2,2,2,2,1,2,6,1,1,1,1,2},
{2,1,2,6,2,2,2,1,2,1,2,2,2,2,2,1,2,2,2,2,1,2,2},
{2,1,2,1,1,1,2,1,2,1,2,2,2,2,2,1,2,1,2,2,1,2,2},
{2,1,2,2,2,1,1,1,2,1,2,1,1,1,2,1,2,1,1,1,1,2,2},
{2,1,2,2,2,1,2,1,2,1,2,1,2,1,2,1,1,1,2,1,2,2,2},
{2,1,1,1,1,1,2,1,1,1,2,1,2,1,1,1,2,2,2,1,1,1,2},
{2,1,2,2,2,2,2,2,2,2,2,1,2,2,2,2,2,2,2,2,2,1,2},
{2,1,1,1,1,1,1,1,1,1,1,0,1,1,1,1,1,1,1,1,1,1,2},
{2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2}
}
};
char MapName[MaxMap][31]={"Classic","Money(or Maswell?)","A-Maze-ing"};
void SetPos(int i,int j)
{
COORD pos={i,j};
HANDLE Out=GetStdHandle(STD_OUTPUT_HANDLE);
SetConsoleCursorPosition(Out, pos);
}
void HideCurSor()
{
CONSOLE_CURSOR_INFO info={1,0};
HANDLE Out=GetStdHandle(STD_OUTPUT_HANDLE);
SetConsoleCursorInfo(Out,&info);
}
void ShowCurSor()
{
CONSOLE_CURSOR_INFO info={1,1};
HANDLE Out=GetStdHandle(STD_OUTPUT_HANDLE);
SetConsoleCursorInfo(Out,&info);
}
void ChangeSpeed()
{
FastMove=1;
SetPos(50,20);
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),Red);
cout<<"×2 Go Pac, Go, Go, Pac!";
}
void SpeedSlow()
{
FastMove=0;
SetPos(50,20);
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),White);
cout<<"×1 ";
}
int Circle(int num)
{
while(!(num>=0&&num<MapWide))
{
if(num<0)num+=MapWide;
if(num>=MapWide)num-=MapWide;
}
return num;
}
struct PLAYER
{
int direction;
int posx;
int posy;
int spawnx;
int spawny;
void setspawn(int x,int y)
{
spawnx=x;
spawny=y;
}
void spawn()
{
posx=spawnx;
posy=spawny;
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),Yellow);
SetPos(2*posx,posy);
cout<<"●";
}
void despawn()
{
SetPos(2*posx,posy);
cout<<" ";
}
void tp(int x,int y)
{
posx=x;
posy=y;
}
void GoUp()
{
if(map[Circle(posy-1)][posx]==Coin||map[Circle(posy-1)][posx]==Empty||map[Circle(posy-1)][posx]==Pow)
{
despawn();
posy=Circle(posy-1);
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),Yellow);
SetPos(posx*2,posy);
cout<<"●";
if(map[posy][posx]==Coin)
{
CurrentCoin--;
}
if(map[posy][posx]==Pow)
{
PowTime=100;
}
map[posy][posx]=Empty;
}
}
void GoDown()
{
if(map[Circle(posy+1)][posx]==Coin||map[Circle(posy+1)][posx]==Empty||map[Circle(posy+1)][posx]==Pow)
{
despawn();
posy=Circle(posy+1);
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),Yellow);
SetPos(posx*2,posy);
cout<<"●";
if(map[posy][posx]==Coin)
{
CurrentCoin--;
}
if(map[posy][posx]==Pow)
{
PowTime=100;
}
map[posy][posx]=Empty;
}
}
void GoLeft()
{
if(map[posy][Circle(posx-1)]==Coin||map[posy][Circle(posx-1)]==Empty||map[posy][Circle(posx-1)]==Pow)
{
despawn();
posx=Circle(posx-1);
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),Yellow);
SetPos(posx*2,posy);
cout<<"●";
if(map[posy][posx]==Coin)
{
CurrentCoin--;
}
if(map[posy][posx]==Pow)
{
PowTime=100;
}
map[posy][posx]=Empty;
}
}
void GoRight()
{
if(map[posy][Circle(posx+1)]==Coin||map[posy][Circle(posx+1)]==Empty||map[posy][Circle(posx+1)]==Pow)
{
despawn();
posx=Circle(posx+1);
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),Yellow);
SetPos(posx*2,posy);
cout<<"●";
if(map[posy][posx]==Coin)
{
CurrentCoin--;
}
if(map[posy][posx]==Pow)
{
PowTime=100;
}
map[posy][posx]=Empty;
}
}
};
PLAYER pac;
struct ENEMY
{
bool freakout;
int freakoutcolor;
int deathtime;
int direction;
int colordata;
int posx;
int posy;
int spawnx;
int spawny;
void setspawn(int x,int y)
{
spawnx=x;
spawny=y;
}
void tp(int x,int y)
{
posx=x;
posy=y;
}
void spawn()
{
posx=spawnx;
posy=spawny;
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),colordata);
SetPos(2*posx,posy);
cout<<"●";
}
void despawn()
{
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),White);
SetPos(2*posx,posy);
printf("%s",BlockRes[Resourse][map[posy][posx]]);
}
void GoUp()
{
direction=Up;
if(Test(Up)==Coin||Test(Up)==Empty||Test(Up)==Barrier2||Test(Up)==Pow)
{
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),White);
despawn();
posy=Circle(posy-1);
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),freakout?freakoutcolor:colordata);
SetPos(posx*2,posy);
cout<<"●";
}
}
void GoDown()
{
direction=Down;
if(Test(Down)==Coin||Test(Down)==Empty||Test(Down)==Barrier2||Test(Down)==Pow)
{
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),White);
despawn();
posy=Circle(posy+1);
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),freakout?freakoutcolor:colordata);
SetPos(posx*2,posy);
cout<<"●";
}
}
void GoLeft()
{
direction=Left;
if(Test(Left)==Coin||Test(Left)==Empty||Test(Left)==Barrier2||Test(Left)==Pow)
{
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),White);
despawn();
posx=Circle(posx-1);
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),freakout?freakoutcolor:colordata);
SetPos(posx*2,posy);
cout<<"●";
}
}
void GoRight()
{
direction=Right;
if(Test(Right)==Coin||Test(Right)==Empty||Test(Right)==Barrier2||Test(Right)==Pow)
{
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),White);
despawn();
posx=Circle(posx+1);
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),freakout?freakoutcolor:colordata);
SetPos(posx*2,posy);
cout<<"●";
}
}
void Go(int dir)
{
if(dir==Up)GoUp();
if(dir==Down)GoDown();
if(dir==Left)GoLeft();
if(dir==Right)GoRight();
}
int Test(int dir)
{
if(dir==Up)return map[Circle(posy-1)][posx];
else if(dir==Down)return map[Circle(posy+1)][posx];
else if(dir==Left)return map[posy][Circle(posx-1)];
else if(dir==Right)return map[posy][Circle(posx+1)];
}
bool IfCanGo(int dir)
{
return Test(dir)==Empty||Test(dir)==Coin||Test(dir)==Barrier2||Test(dir)==Pow;
}
};
ENEMY enemy[MaxEnemy];
void DrawMap()
{
for(int i=0;i<MapWide;i++)
{
SetPos(0,i);
for(int j=0;j<MapWide;j++)
{
printf("%s",BlockRes[Resourse][map[i][j]]);
if(map[i][j]==Coin)
TotalCoin++;
}
}
CurrentCoin=TotalCoin;
}
void SetRes(int resnum)
{
Resourse=resnum;
}
void SetMap(int mapnum)
{
MapChosen=mapnum;
for(int i=0;i<MapWide;i++)
for(int j=0;j<MapWide;j++)
map[i][j]=save[mapnum][i][j];
}
void UpdateCoin()
{
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),White);
SetPos(61,5);
printf("%3d/%-3d",CurrentCoin,TotalCoin);
}
void Init()
{
pac.setspawn(11,21);
enemy[0].setspawn(9,10);
enemy[1].setspawn(13,10);
enemy[2].setspawn(9,12);
enemy[3].setspawn(13,12);
pac.tp(11,21);
for(int i=0;i<MaxEnemy;i++)
{
enemy[i].tp(enemy[i].spawnx,enemy[i].spawny);
enemy[i].freakoutcolor=DarkBlue;
}
enemy[0].colordata=Brown;
enemy[1].colordata=Blue;
enemy[2].colordata=Pink;
enemy[3].colordata=Red;
TotalCoin=0;
}
void ClearMap()
{
for(int i=0;i<23;i++)
{
SetPos(0,i);
cout<<" ";
}
}
void ChooseMap()
{
ClearMap();
SetPos(12,3);
cout<<"请输入地图编号(Enter为随机,B为返回)";
for(int i=0;i<MaxMap;i++)
{
SetPos(12,4+i);
printf("%d %s",i,MapName[i]);
}
srand(time(0)%0x10000);
while(1)
{
if(GetAsyncKeyState(13))
{
SetMap(rand()%MaxMap);
ClearMap();
return;
}
for(int i=0;i<MaxMap;i++)
if(GetAsyncKeyState(i+48)||GetAsyncKeyState(i+0x60))
{
SetMap(i);
ClearMap();
return;
}
if(GetAsyncKeyState(66))
{
ClearMap();
return;
}
}
}
void ChooseRes()
{
ClearMap();
SetPos(12,3);
cout<<"请输入资源编号(Enter为随机,B为返回)";
for(int i=0;i<MaxRes;i++)
{
SetPos(12,4+i);
printf("%d %s",i,ResName[i]);
}
srand(time(0)%0x10000);
while(1)
{
if(GetAsyncKeyState(13))
{
SetRes(rand()%MaxRes);
ClearMap();
return;
}
for(int i=0;i<MaxRes;i++)
if(GetAsyncKeyState(i+48)||GetAsyncKeyState(i+0x60))
{
SetRes(i);
ClearMap();
return;
}
if(GetAsyncKeyState(66))
{
ClearMap();
return;
}
}
}
void CostomMap()
{
ClearMap();
SetPos(0,3);
cout<<"请输入地图名字(#号开始,无空格)";
ShowCurSor();
cin.ignore(1024,'#');
SetPos(0,4);
scanf("%29s",filename);
ifstream fin(filename,ios::in|ios::binary);
SetPos(0,4);
cout<<"读取中......";
int bina;
for(int i=0;i<MapWide;i++)
{
for(int j=0;j<MapWide;j+=2)
{
bina=fin.get();
map[i][j]=bina>>4;
map[i][j+1]=bina%16;
}
map[i][MapWide-1]=fin.get();
}
HideCurSor();
}
void PlayerMoving()
{
if(GetAsyncKeyState(VK_UP))
{
pac.GoUp();
UpdateCoin();
}
else if(GetAsyncKeyState(VK_DOWN))
{
pac.GoDown();
UpdateCoin();
}
else if(GetAsyncKeyState(VK_LEFT))
{
pac.GoLeft();
UpdateCoin();
}
else if(GetAsyncKeyState(VK_RIGHT))
{
pac.GoRight();
UpdateCoin();
}
}
bool IfDie()
{
for(int i=0;i<MaxEnemy;i++)
if(enemy[i].posx==pac.posx&&enemy[i].posy==pac.posy)
if(PowTime>0)
{
enemy[i].deathtime=100;
enemy[i].despawn();
enemy[i].tp(enemy[i].spawnx,enemy[i].spawny);
}
else
return false;
return true;
}
void AllSpawn()
{
pac.spawn();
for(int i=0;i<MaxEnemy;i++)
enemy[i].spawn();
}
void AllClear()
{
pac.despawn();
for(int i=0;i<MaxEnemy;i++)
enemy[i].despawn();
}
void Welcome()
{
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),White);
SetPos(15,3);
cout<<"█████████████████████";
SetPos(15,4);
cout<<"█ 吃豆人小游戏^_^ █";
SetPos(15,5);
cout<<"█ Made by: Rageleague Inc. █";
SetPos(15,6);
cout<<"█ ";
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),Yellow);
cout<< "●";
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),White);
cout<< " ······· █";
SetPos(15,7);
cout<<"█ 永远不要在本程序下输入你的信息 █";
SetPos(15,8);
cout<<"█┅┅┅┅┅叫我华丽丽的分界线┅┅┅┅┅█";
SetPos(15,9);
cout<<"█Rageleague的第一个程序(开玩笑的是游戏)█";
SetPos(15,10);
cout<<"█ 规则很简单,吃掉所有的痘痘就赢了 █";
SetPos(15,11);
cout<<"█不要被幽灵吃掉(本自同根生相\"歼\"何太急)█";
SetPos(15,12);
cout<<"█ 吃掉大痘痘就可以反吃 █";
SetPos(15,13);
cout<<"█ pacmac 0.2.1 █";
SetPos(15,14);
cout<<"█ █";
SetPos(15,15);
cout<<"█按M设置地图,R设置材质,C选择自定义地图 █";
SetPos(15,16);
cout<<"█ 按Enter见开始游(sao)戏(pi)吧 █";
SetPos(15,17);
cout<<"█████████████████████";
}
void PrintData()
{
SetPos(50,5);
cout<<"剩余金币数:";
UpdateCoin();
}
void Gaming()
{
srand(time(0)%0x10000);
for(int i=PlayerLife;i>0;i--)
{
PowTime=0;
AllClear();
SetPos(50,15);
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),Yellow);
cout<<"剩余命数:";
for(int j=1;j<=3;j++)
if(j<=i)cout<<"●";
else cout<<" ";
AllSpawn();
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),White);
Sleep(1000-FastMove*500);
SetPos(50,0);
printf("%s",MapName[MapChosen]);
Sleep(1000-FastMove*500);
SetPos(50,1);
cout<<"Ready... ";
Sleep(1000-FastMove*500);
SetPos(50,1);
cout<<"Steady...";
Sleep(1000-FastMove*500);
SetPos(50,1);
cout<<"Go! ";
Sleep(1000-FastMove*500);
SetPos(50,1);
cout<<" ";
for(int i=1;i<=3;i++)
{
map[9][i+9]=Barrier2;
SetPos(2*(i+9),9);
printf("%s",BlockRes[Resourse][map[9][i+9]]);
}
while(IfDie())
{
PlayerMoving();
if(CurrentCoin==0)
return;
if(!IfDie())break;
for(int i=0;i<MaxEnemy;i++)
{
if(enemy[i].deathtime>0)
{
enemy[i].deathtime--;
}
else
if(enemy[i].IfCanGo(enemy[i].direction))
{
if(enemy[i].IfCanGo((enemy[i].direction+1)%4)||enemy[i].IfCanGo((enemy[i].direction+3)%4))
{
if(rand()%2==0)enemy[i].Go(enemy[i].direction);
else if(enemy[i].IfCanGo((enemy[i].direction+1)%4)&&enemy[i].IfCanGo((enemy[i].direction+3)%4))
if(rand()%2==0)enemy[i].Go((enemy[i].direction+1)%4);
else enemy[i].Go((enemy[i].direction+3)%4);
else if(enemy[i].IfCanGo((enemy[i].direction+1)%4))
enemy[i].Go((enemy[i].direction+1)%4);
else enemy[i].Go((enemy[i].direction+3)%4);
}
else
{
enemy[i].Go(enemy[i].direction);
}
}
else
{
if(enemy[i].IfCanGo((enemy[i].direction+1)%4)||enemy[i].IfCanGo((enemy[i].direction+3)%4))
{
if(enemy[i].IfCanGo((enemy[i].direction+1)%4)&&enemy[i].IfCanGo((enemy[i].direction+3)%4))
if(rand()%2==0)enemy[i].Go((enemy[i].direction+1)%4);
else enemy[i].Go((enemy[i].direction+3)%4);
else if(enemy[i].IfCanGo((enemy[i].direction+1)%4))
enemy[i].Go((enemy[i].direction+1)%4);
else enemy[i].Go((enemy[i].direction+3)%4);
}
else enemy[i].Go((enemy[i].direction+2)%4);
}
}
if(GetAsyncKeyState(VK_SPACE))
ChangeSpeed();
else
SpeedSlow();
Sleep((200-FastMove*100)/((PowTime>0)+1));
if(PowTime>0)
{
PowTime--;
for(int i=0;i<MaxEnemy;i++)
enemy[i].freakout=true;
}
else
for(int i=0;i<MaxEnemy;i++)
enemy[i].freakout=false;
}
}
}
int main()
{
srand(time(0)%0x10000);
HideCurSor();
SetMap(0);
Welcome();
while(!GetAsyncKeyState(13))
{
if(GetAsyncKeyState(77))
{
ChooseMap();
Welcome();
}
if(GetAsyncKeyState(82))
{
ChooseRes();
Welcome();
}
if(GetAsyncKeyState(67))
{
CostomMap();
Welcome();
}
}
Init();
ClearMap();
DrawMap();
PrintData();
SpeedSlow();
Gaming();
SetPos(20,11);
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),White);
if(CurrentCoin==0)
cout<<"Victory!";
else
cout<<"Defeat!";
Sleep(3000);
return 0;
}
8 条评论
-
sslz/lyw LV 7 @ 2016-10-31 11:39:51
很浪啊····
-
2016-08-26 18:03:08@
顶一个,真不错
-
2016-07-23 16:18:18@
顶一个吧
-
2016-07-23 16:18:02@
666666
-
2016-07-23 16:17:18@
顶一个
-
2015-11-29 17:41:48@
srO
-
2015-11-29 10:20:15@
#include<iostream>
#include<cstring>
#include<cstdio>
#include<fstream>
#include<windows.h>
#define MapWide 23
#define BlockCount 8
using namespace std;
//char trash[1000];
int map[MapWide][MapWide];
int posx,posy;
char BlockRes[BlockCount][3]={"[]","·","■","□","━","┅","●","×"};
void SetPos(int i,int j)
{
COORD pos={i,j};
HANDLE Out=GetStdHandle(STD_OUTPUT_HANDLE);
SetConsoleCursorPosition(Out, pos);
}
void HideCurSor()
{
CONSOLE_CURSOR_INFO info={1,0};
HANDLE Out=GetStdHandle(STD_OUTPUT_HANDLE);
SetConsoleCursorInfo(Out,&info);
}
void ShowCurSor()
{
CONSOLE_CURSOR_INFO info={1,1};
HANDLE Out=GetStdHandle(STD_OUTPUT_HANDLE);
SetConsoleCursorInfo(Out,&info);
}
void DrawMap()
{
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),15/*White*/);
for(int i=0;i<MapWide;i++)
{
SetPos(0,i);
for(int j=0;j<MapWide;j++)
{
printf("%s",BlockRes[map[j][i]]);
}
cout<<" "<<i;
}
SetPos(0,MapWide);
for(int i=0;i<MapWide;i++)
printf("%2d",i);
}
int Circle(int num)
{
while(!(num>=0&&num<MapWide))
{
if(num<0)num+=MapWide;
if(num>=MapWide)num-=MapWide;
}
return num;
}
void MapAllSet()
{
while(1)
for(int i=0;i<BlockCount;i++)
{
if(GetAsyncKeyState(i+48)||GetAsyncKeyState(i+0x60))
{
for(int k=0;k<MapWide;k++)
for(int j=0;j<MapWide;j++)
map[k][j]=i;
DrawMap();
return;
}
}
}
char filename[30];
bool data[4];
void Saving()
{
SetPos(0,30);
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),15/*White*/);
cout<<"保存到文件(<30byte,以#开头,不能打空格):";
SetPos(0,31);
ShowCurSor();
cin.ignore(1024,'#');
SetPos(0,31);
cout<<" ";
SetPos(0,31);
scanf("%29s",filename);
ofstream fout(filename,ios::out|ios::binary);
cout<<"保存中,请不要关闭文件";
for(int i=0;i<MapWide;i++)
{
for(int j=0;j<MapWide;j+=2)
{
fout.put((map[j][i]<<4)+map[j+1][i]);
}
fout.put(map[MapWide-1][i]);
}}
void SetChamber()
{
for(int i=9;i<=13;i++)
for(int j=10;j<=12;j++)
map[i][j]=0;
for(int i=10;i<=12;i++)
map[i][9]=4;
DrawMap();
}
void LoadFile()
{
SetPos(0,30);
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),15/*White*/);
cout<<"请输入地图名字(#号开始,无空格)";
ShowCurSor();
cin.ignore(1024,'#');
SetPos(0,31);
scanf("%29s",filename);
ifstream fin(filename,ios::in|ios::binary);
SetPos(0,4);
int bina;
for(int i=0;i<MapWide;i++)
{
for(int j=0;j<MapWide;j+=2)
{
bina=fin.get();
map[j][i]=bina>>4;
map[j+1][i]=bina%16;
}
map[i][MapWide-1]=fin.get();
}
HideCurSor();
DrawMap();
Sleep(1000);
}
int main()
{
HideCurSor();
DrawMap();
SetPos(50,3);
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),15/*White*/);
cout<<"地图编辑器0.2.30";
SetPos(50,4);
cout<<"0是空地[]";
SetPos(50,5);
cout<<"1是痘痘·";
SetPos(50,6);
cout<<"2是格子■";
SetPos(50,7);
cout<<"3是格子2□";
SetPos(50,8);
cout<<"4是围墙━";
SetPos(50,9);
cout<<"5是开启的围墙┅";
SetPos(50,10);
cout<<"6是大痘痘:P●";
SetPos(50,12);
cout<<"按上下左右来移动";
SetPos(50,13);
cout<<"数字键替换格子";
SetPos(50,20);
cout<<"按F11保存";
while(!GetAsyncKeyState(0x7A/*enter*/))
{
if(GetAsyncKeyState(VK_UP))
{
SetPos(2*posx,posy);
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),15/*White*/);
printf("%s",BlockRes[map[posx][posy]]);
posy=Circle(posy-1);
SetPos(2*posx,posy);
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),144/*Background blue*/);
printf("%s",BlockRes[map[posx][posy]]);
Sleep(100);
}
if(GetAsyncKeyState(VK_DOWN))
{
SetPos(2*posx,posy);
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),15/*White*/);
printf("%s",BlockRes[map[posx][posy]]);
posy=Circle(posy+1);
SetPos(2*posx,posy);
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),144/*Background blue*/);
printf("%s",BlockRes[map[posx][posy]]);
Sleep(100);
}
if(GetAsyncKeyState(VK_LEFT))
{
SetPos(2*posx,posy);
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),15/*White*/);
printf("%s",BlockRes[map[posx][posy]]);
posx=Circle(posx-1);
SetPos(2*posx,posy);
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),144/*Background blue*/);
printf("%s",BlockRes[map[posx][posy]]);
Sleep(100);
}
if(GetAsyncKeyState(VK_RIGHT))
{
SetPos(2*posx,posy);
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),15/*White*/);
printf("%s",BlockRes[map[posx][posy]]);
posx=Circle(posx+1);
SetPos(2*posx,posy);
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),144/*Background blue*/);
printf("%s",BlockRes[map[posx][posy]]);
Sleep(100);
}
for(int i=0;i<BlockCount;i++)
if(GetAsyncKeyState(i+48)||GetAsyncKeyState(i+0x60))
{
map[posx][posy]=i;
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),144/*Background blue*/);
SetPos(2*posx,posy);
printf("%s",BlockRes[map[posx][posy]]);
}
if(GetAsyncKeyState(81/*q*/))
MapAllSet();
if(GetAsyncKeyState(192/*~*/))
LoadFile();
if(GetAsyncKeyState(87))
SetChamber();
}
Saving();
} -
2015-11-29 10:03:04@
大触一枚,鉴定完毕
- 1