Class design and implementation A simple process of designing a game

Design and Implementation of Class 1 of Big Job

1. The purpose of the experiment

  1. Master class design and implementation
  2. Learn how to discover classes and their members based on descriptions, and have preliminary object-oriented analysis and design capabilities

2. Experimental content

  1. Please select a game you are familiar with, analyze the classes involved in a scene, and the attributes and behaviors of each class, and complete the class definition.
  2. Please select a simple game process of the game, analyze the objects involved and the interactions between them, and complete the game process framework of the process.

3. Experimental results

Please describe the analysis process in words, give the class definition and game framework in the form of pseudo-code, name it with "student number + name", and upload it to BlackBoard - Online Homework Column - Big Homework 1.

Fourth, the experimental process

I'm a beginner, so don't give a shit about it.

When I saw this topic, I thought of the game of King Glory. I wanted to design a small process for heroes to fight wild monsters, but it was limited to my own level, so I could only abstract and abstract it, simplify and simplify, and then simplify, and finally: the hero fights a wild monster, Both sides will lose blood every time they fight, but the hero's experience will increase. If the experience increases to a certain level, the hero's level will increase, and the level increase will strengthen its own health and damage, until one of the fighting sides dies (wild monsters must die).

Choose to describe the simplistic process of jungler in King's Glory, which involves two categories, one is hero and the other is wild monster.

For the hero class, its attributes are defined as health, level, experience and damage. Its behavior is that the health value will be reduced due to damage from monsters in the process of fighting monsters, and at the same time, its own experience will also increase, and the experience will increase to a certain level of hero level. It will increase, and the level increase will strengthen its own health and damage.

For the class of wild monsters, its attributes are defined as health value and damage, and its behavior is that the health value will be reduced due to hero damage during the process.

5. Code

//类界面 
class hero//定义英雄类 
{
	private:
		int hp;//生命值 
		int rank;//等级 
		int exp;//经验 
		int damage;//伤害 
	public:
		void initial();//初始化 
		void Uprank();//升级 
		int Upexp();//经验增加 
		int Hp(int damage);//掉血 
		int Damage();//返回伤害值		
};
class monster//定义野怪 
{
	private:
		int hp;//生命值 
		int damage;//伤害 
	public:
		void initial();//初始化 
		int Hp(int damgage);//掉血 
		int Damage();//返回伤害值	
};
//类定义 
void hero::initial()//英雄初始化 
{
	hp=1000;
	rank=1;
	exp=0;
	damage=100;	
}
int hero::Upexp()//增加经验 
{
	return exp+=10;
}
void hero::Uprank()//升级 
{
	rank++;//等级提升 
	hp=hp+200;//生命值增加 
	damage=damage+50;//伤害强化 
}
int hero::Hp(int damage)//掉血 
{
	return hp=hp-damage;
}
int hero::Damage()//返回伤害值 
{
	return damage;
}
void monster::initial()//野怪初始化 
{
	hp=500;
	damage=30;
}
int monster::Hp(int damage)//掉血 
{
	return hp=hp-damage;
}
int monster::Damage()//返回伤害值 
{
	return damage;
}
//
int main()
{
	hero Jungle;//定义Jungle这个英雄 
	monster Boss;//定义boss这个野怪 
	Jungle.initial();
	Boss.initial();
	while(Jungle.Hp(Boss.Damage())||Boss.Hp(Jungle.Damage()))//开打直到其中一方挂掉 
	{
		if(Jungle.Upexp()%100==0)//打一次经验提升,经验每提升100就升一级 
		Jungle.Uprank();
	}		
} 

Guess you like

Origin blog.csdn.net/weixin_62264287/article/details/123532964