(大家看看)花了一个礼拜编的一个 (小游戏)vc环境
#include <iostream>#include <stdlib.h>
#include <iomanip>
#include <string>
#include <ctime>
#include <conio.h>
#include <windows.h>
#include <cmath>
using namespace std;
SYSTEMTIME Time;
string name;
int HP=80,Defend=17,gold=50,expe=0,L=0,Attack=15;int boss[100]={0};int H[100]={80};
string weapon="弹弓",weapon0="布衣";int temp[100]={0,1,2,3,4,5,6,7,8,9,10,11};
class medicine
{
int med;medicine *next;
public:
medicine *create_medicine();
void show_medicine(medicine*);
void buy_medicine(int i,int x);
void drink_medicine(int i,int x);
};
medicine l;
medicine*head=l.create_medicine();
medicine* medicine::create_medicine()//创建结点
{
medicine*p1,*p2;
p1=new medicine;
p2=p1;
head=p1;
p2=p1;
p1=new medicine;
p2->next=p1;
delete p1;p2->next=NULL;
return head;
}
void medicine::drink_medicine(int j,int i)//删除链表结点
{
medicine*p=head;j=0;
while(p&&p->next->med!=i)
{
p=p->next;
j++;
}
if(!p)delete p;
else
{
medicine*l=p->next;
p->next=l->next;
delete l;
}
}
void medicine::show_medicine(medicine*h)
{
char m;medicine d;
h=::head;medicine*l=::head;
cout<<"药品信息如下:\n";//显示链表信息
while(h)
{
if(h->med==1)
cout<<h->med<<"------"<<"参丸,HP恢复 80"<<endl;
if(h->med==2)
cout<<h->med<<"------"<<"大参丸,HP恢复 150"<<endl;
if(h->med==3)
cout<<h->med<<"------"<<"人参,HP恢复 500"<<endl;
if(h->med==4)
cout<<h->med<<"------"<<"灵丹,HP恢复 1000"<<endl;
h=h->next;
}
if(head)
{
cout<<"你要服用的是:";cin>>m;char n=m;
while(l)
{
if(l->med!=1&&l->med!=2&&l->med!=3&&l->med!=4){m='0';}
else {m=n;break;}
l=l->next;
}
if(m=='1')
{cout<<"你快速服下参丸,HP恢复 了"<<endl;::HP+=80;if(::HP>H[L])::HP=H[L];d.drink_medicine(0,1);}
if(m=='2')
{cout<<"你快速服下大参丸,HP恢复 了"<<endl;::HP+=150;if(::HP>H[L])::HP=H[L];d.drink_medicine(0,2);}
if(m=='3')
{cout<<"你快速服下人参,HP恢复 了"<<endl;::HP+=500;if(::HP>H[L])::HP=H[L];d.drink_medicine(0,3);}
if(m=='4')
{cout<<"你快速服下灵丹,HP恢复 了"<<endl;::HP+=1000;if(::HP>H[L])::HP=H[L];d.drink_medicine(0,4);}
if(m!='1'&&m!='2'&&m!=3&&m!='4'){cout<<endl<<"没有这种药......\n";}
}
else
{cout<<"对不起,你的药品用完了\n";}
}
void medicine::buy_medicine(int i,int x)//向链表添加结点
{
medicine*p=head;int j=0;
while(p&&j<i-2)
{
p=p->next;
j++;
}
if(!p)delete p;
else
{
medicine*s;
s=new medicine;s->med=x;
s->next=p->next;
p->next=s;
}
}
class System:public medicine//游戏系统类继承medicine类
{
public:
void menu();
void upgrade();
void upgrade1(int ,int ,int );
void begin();
void map1();
void map2();
void sys(){system("pause");system("cls");}
void syst(){getche();system("cls");}
void root1();
void root2();
void map_weapon1();
void condition();
void map_tool1();
void show_tool0(string namew1,int money1,int add_attack1,string namew2,int money2,int add_attack2,string namew3,int money3,int add_attack3,string namew4,int money4,int add_attack4);
void show_my_weapon(int w,string nameweapon,int money,int add_attack);
void show_my_weapon0(int w,string nameweapon,int money,int add_attack);
void show_weapon1(string namew1,int money1,int add_attack1,string namew2,int money2,int add_attack2,string namew3,int money3,int add_attack3,string namew4,int money4,int add_attack4);
void show_weapon0(string namew1,int money1,int add_attack1,string namew2,int money2,int add_attack2,string namew3,int money3,int add_attack3,string namew4,int money4,int add_attack4);
void map(string north,string south,string west,string east)
{
System s;s.gotoxy(22,0);cout<<"菜单(m)";
s.gotoxy(8,48);cout<<(char)24<<" 北(w): "<<north<<" ";s.gotoxy(12,48);cout<<(char)25<<"南(s): ";cout<<south;
s.gotoxy(10,35);cout<<"西(a):";cout<<west;cout<<(char)27;s.gotoxy(10,52);cout<<(char)26<<"东(d): ";cout<<east;
}
void North(string north)
{
System s;s.gotoxy(0,0);cout<<"菜单";
s.gotoxy(8,48);cout<<(char)24<<" 北(w): "<<north<<" ";
}
void South(string south)
{
System s;s.gotoxy(0,0);cout<<"菜单";
s.gotoxy(12,48);cout<<(char)25<<"南(s): ";cout<<south;
}
void East(string east)
{
System s;s.gotoxy(0,0);cout<<"菜单";
s.gotoxy(10,52);cout<<(char)26<<"东(d): ";cout<<east;
}
void West(string west)
{
System s;s.gotoxy(0,0);cout<<"菜单";
s.gotoxy(10,35);cout<<"西(a):";cout<<west;cout<<(char)27;
}
void show1(int HP,int Attack,int Defend,int L,int expe)
{
HP=::HP;Attack=::Attack;L=::L;expe=::expe;
cout<<"\n\n\n英雄名字:\t"<<name<<"\n\n\n"<<"血气 HP:\t"<<HP<<"\n\n\n攻击:\t\t";cout<<Attack;cout<<"\n\n\n防卫力:\t\t"<<Defend<<"\n\n\n等级 L:\t\t"<<L<<"\n\n\n经验值:\t\t"<<expe<<"\n\n\n\n\n\n";system("pause");system("cls");
}
void gotoxy(int x,int y)
{
COORD position={0,0};
HANDLE hOut=GetStdHandle(STD_OUTPUT_HANDLE);
position.X=y;position.Y=x;
SetConsoleCursorPosition(hOut,position);
}
void laduo()
{
System s;
s.gotoxy(1,10);
cout<<"拉多镇";
}
void house()
{
System s;
s.gotoxy(2,26);
}
void where(){System s;s.gotoxy(14,16);cout<<"你想去哪?";}
void east()
{
System s;
system("cls");
for(int i=50;i>30;i=i-2){s.gotoxy(8,i);cout<<(char)26<<" ";}s.gotoxy(10,34);cout<<"你正在往东走....";s.gotoxy(16,50);s.sys();
}
void west()
{
System s;
system("cls");
for(int i=28;i>14;i=i-2){s.gotoxy(8,i);cout<<(char)27<<" ";}s.gotoxy(10,16);cout<<"你正在往西走....";s.gotoxy(16,50);s.sys();
}
void south()
{
System s;
system("cls");
for(int i=6;i<13;i++){s.gotoxy(i,32);cout<<(char)25;}s.gotoxy(15,32);cout<<"你正在往南走....";s.gotoxy(22,50);s.sys();
}
void north()
{
System s;
system("cls");
for(int i=12;i>5;i--){s.gotoxy(i,32);cout<<(char)24;}s.gotoxy(14,32);cout<<"你正在往北走....";s.gotoxy(22,50);s.sys();
}
void walk(char x)
{
System s;
if(x=='s'){cout<<"\n\n";s.setjindutiao(25,11);s.south();}
if(x=='w'){cout<<"\n\n";s.setjindutiao(25,11);s.north();}
if(x=='d'){cout<<"\n\n";s.setjindutiao(25,11);s.east();}
if(x=='a'){cout<<"\n\n";s.setjindutiao(25,11);s.west();}
}
void fight(string name0,int hp,int attack,int defend,int expe,int money);
void meet0(string name0,int hp0,int attack0,int defend0,int exp0,int gold0)
{
System sas;
system("cls");
sas.gotoxy(6,28);cout<<name0<<"出现了!进入战斗......\n\n";sas.gotoxy(14,16);system("pause");
sas.setjindutiao(20,10);system("cls");
sas.fight(name0,hp0,attack0,defend0,exp0,gold0);system("cls");
}
void meet1()
{
System ss;
srand(time(0));
int a=rand()%15;
switch(a)
{
case 0:
ss.meet0("生物炮",50,30,15,8,4);break;
case 1:
ss.meet0("加农炮",85,128,24,12,8);break;
case 2:
ss.meet0("食人花",110,60,10,15,20);break;
case 3:
case 4:
ss.meet0("水蛙",120,160,25,30,15);break;
case 5:
ss.meet0("金蚁",30,5,150,5,25);break;
default:
break;
}
}
void meet()
{
System ss;
srand(time(0));
int a=rand()%15;
if(a==0)
{
ss.meet0("巨蚁",20,10,5,1,2);
}
if(a==8)
{
ss.meet0("火焰枪",45,8,8,3,4);
}
if(a==10)
{
ss.meet0("杀人虫",45,8,10,3,3);
}
if(a==14||a==13)
{
ss.meet0("仿生蜗牛",65,12,12,10,6);
}
if(a==12)ss.meet0("金蚁",30,5,50,5,25);
}
/*
10计科班张文长游戏.zip
(11.69 KB)
大家有什么问题可以问额 ,比如 喝药系统、购物系统、坐标系统、升级系统、战斗系统、怪物系统、随机遇怪系统、人物状态系统、地图切换等等,或者哪里需要什么改动的,都可以提出来,欢迎大家发言
云中月 制作.zip
(580.28 KB)
[ 本帖最后由 zwcwu 于 2011-1-7 23:09 编辑 ]