easyx游戏编程:魔塔(c++语⾔开发)源码easyx游戏编程:魔塔(C++游戏开发)
我的编程环境是vs2019
#include "stdafx.h"是⾃带的,其他版本可能需要添加#include “stdafx.h”
还需要添加众多的图⽚这⾥我下载链接放下⾯了
代码
提取码:hzzd
除了下⾯代码外,⽆其他改动
#include<stdio.h>
#include<graphics.h>
#include<Windows.h>
#include<stdlib.h>
#include<mmsystem.h>
#include<conio.h>
#pragma comment(lib,"winmm.lib")
#define SIZE                60          //⼀张图⽚的像素
void Welcome();//游戏欢迎界⾯
void Init();//初始化游戏
void FindRole(int*,int*);//寻⼈物位置
void Book();//查看怪物⼿册
void Convey(char);//楼层传送
char*turn(int);//数字转化为字符串
void Game(int,int,int,int);//⼈物操作
/
/⾓⾊结构体
typedef struct _ROLEMAN
{
int HP;//⾎量
int att;//攻击⼒
int def;//防御⼒
int money;//⾦钱
int ykey;//黄钥匙
int bkey;//蓝钥匙
}ROLEMAN;
//怪物结构体
typedef struct _MONSTER
{
int HP;//⾎量
int att;//攻击⼒
int def;//防御⼒
int money;//掉落⾦钱
}MONSTER;
int map[6][13][13]//13是增加多余的墙,防⽌游戏过程中出现数组越界问题
{
//第⼀层地图
{
{0,0,0,0,0,0,0,0,0,0,0,0,0},
{0,25,1,10,11,10,1,1,1,1,1,1,0},
{0,0,0,0,0,0,0,0,0,0,0,1,0},
{0,8,1,1,2,1,0,6,4,1,0,1,0},
{0,1,13,1,0,1,0,7,8,1,0,1,0},
{0,0,2,0,0,1,0,0,0,2,0,1,0},
{0,4,1,1,0,1,2,12,15,12,0,1,0},
{0,4,1,1,0,1,2,12,15,12,0,1,0}, {0,1,14,1,0,1,0,0,0,0,0,1,0}, {0,0,2,0,0,1,1,1,1,1,1,1,0}, {0,1,1,1,0,0,2,0,0,0,2,0,0}, {0,8,1,4,0,4,1,1,0,1,12,1,0}, {0,8,30,4,0,1,17,1,0,10,9,10,0}, {0,0,0,0,0,0,0,0,0,0,0,0,0} },
//第⼆层地图
{
{0,0,0,0,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0,1,0,10,1,4,0,6,1,8,0,16,0}, {0,25,0,4,10,4,0,1,10,1,0,26,0}, {0,0,0,0,0,0,0,0,0,0,0,0,0}, },
//第五层地图
{
{0,0,0,0,0,0,0,0,0,0,0,0,0}, {0,33,0,1,11,2,1,0,1,1,2,1,0}, {0,2,0,1,1,0,4,0,10,10,0,11,0}, {0,2,2,12,1,0,1,0,4,4,0,1,0}, {0,0,0,0,2,0,12,0,4,4,0,1,0}, {0,4,1,15,1,0,1,0,0,0,0,1,0},
{0,4,1,15,1,0,1,0,0,0,0,1,0},
{0,4,1,1,12,0,1,10,1,1,1,1,0},
{0,0,14,0,0,0,1,0,0,0,0,11,0},
{0,1,1,1,1,0,10,0,1,1,1,1,0},
{0,9,4,8,1,0,1,0,10,0,0,0,0},
{0,0,0,0,0,0,1,0,1,0,1,29,0},
{0,26,19,1,1,1,1,0,1,2,1,28,0},
{0,0,0,0,0,0,0,0,0,0,0,0,0}
},
//boss地图
{
{0,0,0,0,0,0,0,0,0,0,0,0,0},
{0,36,36,36,36,0,32,0,36,36,36,36,0},
{0,36,36,36,36,0,1,0,36,36,36,36,0},
{0,36,36,36,36,0,35,0,36,36,36,36,0},
{0,36,36,36,36,0,1,0,36,36,36,36,0},
{0,36,36,36,36,0,35,0,36,36,36,36,0},
{0,36,36,36,36,0,1,0,36,36,36,36,0},
{0,36,36,36,36,0,35,0,36,36,36,36,0},
{0,36,36,36,36,0,1,0,36,36,36,36,0},
{0,36,36,36,36,0,1,0,36,36,36,36,0},
{0,36,36,36,36,0,1,0,36,36,36,36,0},
{0,36,36,36,36,0,16,0,36,36,36,36,0},
{0,0,0,0,0,0,0,0,0,0,0,0,0}
}
};
//初始化结构体变量
ROLEMAN roleman ={1000,100,100,0,0,0};//⾓⾊
MONSTER gslime ={35,18,1,1};//绿史莱姆
MONSTER rslime ={45,20,2,2};//红史莱姆
MONSTER bat ={35,38,3,3};//蝙蝠
MONSTER skull ={50,42,6,6};//骷髅⼈
MONSTER bskull ={55,52,12,8};//骷髅⼠兵
MONSTER wizard ={60,32,8,5};//法师
MONSTER protection ={100,50,15,15};//守卫
MONSTER sboss ={110,55,15,0};//boss侍卫
MONSTER boss ={120,60,20,0};//boss
//声明图⽚变量
IMAGE wall, floor, ydoor, bdoor, ykey, bkey, rstone, bstone, rliquid, bliquid;//墙,地板,黄门,蓝门,黄钥匙,蓝钥匙,红⽔晶,蓝⽔晶,红药⽔,蓝药⽔
IMAGE _gslime, _rslime, _bat, _skull, _bskull, _wizard;//绿史莱姆,红史莱姆,蝙蝠,骷髅⼈,骷髅⼠兵,法师
IMAGE roleup, roledown, roleleft, roleright, leader, helper, suffering, store;//⾓⾊朝向,同是塔中⼈,指引者,帮助者,狱友,商店
IMAGE stairsup, stairsdown, cage, sword, shield, convey;//上下楼梯,笼⼦,剑,盾,传送道具
IMAGE defend, _boss, _sboss, fire;
int level =0, buycount =0, money =20, defenceover =0, highlevel =1;//当前所在层数 - 1,在商店购买的次数,商店购买所需⾦钱,打败守卫的个数,去过的最⾼层数
bool book =false, updown =false, final =true, final2 =false;//是否得到怪物⼿册,传送道具;是否可以挑战最终boss,查看最终怪物⼿册
char str[10];
HWND hwnd;
//游戏欢迎界⾯
void Welcome()
{
initgraph(830,680);
//输出魔塔
settextstyle(150,150,"楷体");
settextcolor(RED);
outtextxy(120,100,"魔塔");
//输出按回车键开始游戏
settextstyle(40,40,"⿊体");
settextstyle(40,40,"⿊体");
settextcolor(WHITE);
outtextxy(90,450,"按任意键开始游戏");
//输出作者
settextstyle(32,16,"华⽂琥珀");
outtextxy(500,630,"制作⼈: 奇·⼤⼤ ");
_getch();
cleardevice();
settextstyle(16,8,"⿊体");
}
//初始化游戏
void Init()
{
//加载图⽚
loadimage(&wall,"魔塔/墙.jpg", SIZE, SIZE);
loadimage(&floor,"魔塔/地板.jpg", SIZE, SIZE);
loadimage(&ydoor,"魔塔/黄门.jpg", SIZE, SIZE); loadimage(&bdoor,"魔塔/蓝门.jpg", SIZE, SIZE); loadimage(&ykey,"魔塔/黄钥匙.jpg", SIZE, SIZE); loadimage(&bkey,"魔塔/蓝钥匙.jpg", SIZE, SIZE); loadimage(&rstone,"魔塔/红⽔晶.jpg", SIZE, SIZE); loadimage(&bstone,"魔塔/蓝⽔晶.jpg", SIZE, SIZE); loadimage(&rliquid,"魔塔/红药⽔.jpg", SIZE, SIZE); loadimage(&bliquid,"魔塔/蓝药⽔.jpg", SIZE, SIZE); loadimage(&_gslime,"魔塔/绿史莱姆.jpg", SIZE, SIZE); loadimage(&_rslime,"魔塔/红史莱姆.jpg", SIZE, SIZE); loadimage(&_bat,"魔塔/蝙蝠.jpg", SIZE, SIZE);
loadimage(&_skull,"魔塔/骷髅⼈.jpg", SIZE, SIZE); loadimage(&_bskull,"魔塔/骷髅⼠兵.jpg", SIZE, SIZE); loadimage(&_wizard,"魔塔/法师.jpg", SIZE, SIZE); loadimage(&roleup,"魔塔/⾓⾊上.jpg", SIZE, SIZE); loadimage(&roledown,"魔塔/⾓⾊下.jpg", SIZE, SIZE); loadimage(&roleleft,"魔塔/⾓⾊左.jpg", SIZE, SIZE); loadimage(&roleright,"魔塔/⾓⾊右.jpg", SIZE, SIZE); loadimage(&leader,"魔塔/指引者.jpg", SIZE, SIZE); loadimage(&helper,"魔塔/帮助者.jpg", SIZE, SIZE); loadimage(&suffering,"魔塔/狱友.jpg", SIZE, SIZE); loadimage(&store,"魔塔/商店.jpg", SIZE, SIZE); loadimage(&stairsup,"魔塔/上楼梯.jpg", SIZE, SIZE); loadimage(&stairsdown,"魔塔/下楼梯.jpg", SIZE, SIZE); loadimage(&cage,"魔塔/笼⼦.jpg", SIZE, SIZE); loadimage(&sword,"魔塔/剑.jpg", SIZE, SIZE);
loadimage(&shield,"魔塔/盾.jpg", SIZE, SIZE);图片下载站源码
loadimage(&convey,"魔塔/传送道具.jpg", SIZE, SIZE); loadimage(&defend,"魔塔/守卫.jpg", SIZE, SIZE); loadimage(&_boss,"魔塔/BOSS.jpg", SIZE, SIZE); loadimage(&_sboss,"魔塔/boss侍卫.jpg", SIZE, SIZE); loadimage(&fire,"魔塔/岩浆.jpg", SIZE, SIZE);
//背景⾳乐
mciSendString("open 魔塔/背景⾳乐.mp3 alias BGM",0,0,0); mciSendString("play BGM repeat",0,0,0)
;
//输出信息框及信息
rectangle(680,10,820,670);
outtextxy(700,75,"⽣命:");
outtextxy(700,100,"攻击:");
outtextxy(700,125,"防御:");
outtextxy(700,150,"⾦钱:");
outtextxy(700,210,"黄钥匙:");
outtextxy(700,235,"蓝钥匙:");
outtextxy(700,295,"当前层数:");
outtextxy(700,295,"当前层数:");
outtextxy(690,360,"当前武器:神圣剑");
outtextxy(690,385,"当前防具:神圣盾");
}
//画地图以及输出信息
void Draw()
{
int j, i;
for(j =1; j <=11; j++)
{
for(i =1; i <=11; i++)
{
switch(map[level][j][i])
{
case0:putimage((i -1)* SIZE +10,(j -1)* SIZE +10,&wall);break;
case1:putimage((i -1)* SIZE +10,(j -1)* SIZE +10,&floor);break;
case2:putimage((i -1)* SIZE +10,(j -1)* SIZE +10,&ydoor);break; case3:putimage((i -1)* SIZE +10,(j -1)* SIZE +10,&bdoor);break; case4:putimage((i -1)* SIZE +10,(j -1)* SIZE +10,&ykey);break;
case5:putimage((i -1)* SIZE +10,(j -1)* SIZE +10,&bkey);break;
case6:putimage((i -1)* SIZE +10,(j -1)* SIZE +10,&rstone);break; case7:putimage((i -1)* SIZE +10,(j -1)* SIZE +10,&bstone);break; case8:putimage((i -1)* SIZE +10,(j -1)* SIZE +10,&rliquid);break; case9:putimage((i -1)* SIZE +10,(j -1)* SIZE +10,&bliquid);break; case10:putimage((i -1)* SIZE +10,(j -1)* SIZE +10,&_gslime);break; case11:putimage((i -1)* SIZE +10,(j -1)* SIZE +10,&_rslime);break; case12:putimage((i -1)* SIZE +10,(j -1)* SIZE +10,&_bat);break; case13:putimage((i -1)* SIZE +10,(j -1)* SIZE +10,&_skull);break; case14:putimage((i -1)* SIZE +10,(j -1)* SIZE +10,&_bskull);break; case15:putimage((i -1)* SIZE +10,(j -1)* SIZE +10,&_wizard);break; case16:putimage((i -1)* SIZE +1
0,(j -1)* SIZE +10,&roleup);break; case17:putimage((i -1)* SIZE +10,(j -1)* SIZE +10,&roledown);break; case18:putimage((i -1)* SIZE +10,(j -1)* SIZE +10,&roleleft);break; case19:putimage((i -1)* SIZE +10,(j -1)* SIZE +10,&roleright);break; case20:
case21:putimage((i -1)* SIZE +10,(j -1)* SIZE +10,&leader);break; case22:putimage((i -1)* SIZE +10,(j -1)* SIZE +10,&helper);break; case23:putimage((i -1)* SIZE +10,(j -1)* SIZE +10,&suffering);break; case24:putimage((i -1)* SIZE +10,(j -1)* SIZE +10,&store);break; case25:putimage((i -1)* SIZE +10,(j -1)* SIZE +10,&stairsup);break; case26:putimage((i -1)* SIZE +10,(j -1)* SIZE +10,&stairsdown);break; case27:putimage((i -1)* SIZE +10,(j -1)* SIZE +10,&cage);break; case28:putimage((i -1)* SIZE +10,(j -1)* SIZE +10,&sword);break; case29:putimage((i -1)* SIZE +10,(j -1)* SIZE +10,&shield);break; case30:putimage((i -1)* SIZE +10,(j -1)* SIZE +10,&convey);break; case31:putimage((i -1)* SIZE +10,(j -1)* SIZE +10,&defend);break; case32:putimage((i -1)* SIZE +10,(j -1)* SIZE +10,&_boss);break; case33:putimage((i -1)* SIZE +10,(j -1)* SIZE +10,&_sboss);break; case34:putimage((i -1)* SIZE +10,(j -1)* SIZE +10,&floor);break; case35:putimage((i -1)* SIZE +10,(j -1)* SIZE +10,&_sboss);break; case36:putimage((i -1)* SIZE +10,(j -1)* SIZE +10,&fire);break;
}
}
}
//画游戏框
rectangle(10,10,670,670);
//消除之前的信息
setfillcolor(BLACK);
solidrectangle(740,75,772,91);//⽣命
solidrectangle(740,100,772,116);//攻击
solidrectangle(740,125,772,141);//防御

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。