2635: P4 游戏中的Human角色

时间限制: 1 Sec  内存限制: 128 MB

提交: 524  解决: 328

题目描述

在一个平面打斗游戏中,任何的角色(Role)都有血量(blood)和位置loc(此处loc是Location类的实例)属性。有了Role类,可以派生出不同的角色,如人、神仙、怪兽等。如下程序中,定义了Location类和Role类,人类(Human)中新增了姓名和攻击力数据成员,请为Human类设计成员函数,并实现Role类中的moveTo和addBlood两个成员函数。
请在begin和end中间写下需要的代码。你只能编辑并提交begin和end之间的代码。
#include <iostream>
using namespace std;
class Location
{
private:
    int x, y;
public:
    Location(int a, int b):x(a),y(b) {}
    int getX(){return x;}
    int getY(){return y;}
    void setXY(int a,int b) {x=a;y=b;};  //设置位置坐标
};
class Role
{
public:
    Role(int rblood, int rx, int ry):blood(rblood),loc(rx,ry) {}
    void moveTo(int rx, int ry);  //移动到(rx, ty)处,要改变loc的值
    void addBlood(int b); //增加血量,参数为负时,代表减少
protected:
    int blood;
    Location loc;
};
void Role::moveTo(int rx, int ry)

{

loc.setXY(rx,ry);

}

void Role::addBlood(int b) 

{

blood+=b;

}
//************* begin *****************
class Human: public Role
{
public:
private:
    string name;  // 姓名
    int attack;   // 攻击力
};
//************* end *****************
int main()
{
    string name;
    int att, blood, x, y;
    cin>>name>>att>>blood>>x>>y;
    Human hum(name,att,blood,x,y); //人name的攻击力att,血量blood,在(x,y)处
    hum.show();
    int incAtt, incBlood, newx, newy ;
    cin>>incAtt;
    cin>>incBlood;
    cin>>newx>>newy;
    hum.addAttack(incAtt);  //攻击力增加incAtt
    hum.addBlood(incBlood); //血量增加incBlood
    hum.moveTo(newx,newy);  //人移到了(news,newy)处
    hum.show();
    return 0;
}

输入

第一行:名字 血量 攻击力 位置,其中位置处是两个整数,代表平面x、y坐标
第二行:增加的攻击力
第三行:要增加的血量
第四行:新位置,用两个整数代表
输入的各部分之间用空格隔开

输出

分别用两行显示游戏角色的初始状态和调整参数后的状态
如“Avanda has 500 attack and 1000 blood in (4,3)”表示Avanda有500攻击力1000血量,在(4,3)位置处

样例输入

Avanda 500 1000 4 3
-300
200
2 5

样例输出

Avanda has 500 attack and 1000 blood in (4,3)
Avanda has 200 attack and 1200 blood in (2,5)

迷失在幽谷中的鸟儿,独自飞翔在这偌大的天地间,却不知自己该飞往何方……

#include <iostream>
using namespace std;
class Location
{
private:
int x, y;
public:
Location(int a, int b):x(a),y(b) {}
int getX()
{
return x;
}
int getY()
{
return y;
}
void setXY(int a,int b)
{
x=a;
y=b;
}; //设置位置坐标
};
class Role
{
public:
Role(int rblood, int rx, int ry):blood(rblood),loc(rx,ry) {}
void moveTo(int rx, int ry); //移动到(rx, ty)处,要改变loc的值
void addBlood(int b); //增加血量,参数为负时,代表减少
protected:
int blood;
Location loc;
};
void Role::moveTo(int rx, int ry)
{
loc.setXY(rx,ry);
}
void Role::addBlood(int b)
{
blood+=b;
}
class Human:public Role,public Location
{
public:
Human(string na,int att,int rblood,int rx,int ry):Location(rx,ry),Role(rblood,rx,ry),name(na),attack(att) {}
void show()
{
cout<<name<<" has "<<attack<<" attack and "<<blood<<" blood in ("<<getX()<<","<<getY()<<")"<<endl;
}
void addAttack(int a)
{
attack+=a;
}
void addBlood(int b)
{
Role::addBlood(b);
}
void moveTo(int rx,int ry)
{
Location::setXY(rx,ry);
}
private:
string name; // 姓名
int attack; // 攻击力
};
int main()
{
string name;
int att, blood, x, y;
cin>>name>>att>>blood>>x>>y;
Human hum(name,att,blood,x,y); //人name的攻击力att,血量blood,在(x,y)处
hum.show();
int incAtt, incBlood, newx, newy ;
cin>>incAtt;
cin>>incBlood;
cin>>newx>>newy;
hum.addAttack(incAtt); //攻击力增加incAtt
hum.addBlood(incBlood); //血量增加incBlood
hum.moveTo(newx,newy); //人移到了(news,newy)处
hum.show();
return 0;
}

YTU 2635: P4 游戏中的Human角色的更多相关文章

  1. 问题 C: P4 游戏中的Human角色

    题目描述 在一个平面打斗游戏中,任何的角色(Role)都有血量(blood)和位置loc(此处loc是Location类的实例)属性.有了Role类,可以派生出不同的角色,如人.神仙.怪兽等.如下程序 ...

  2. 游戏中的人工智能——初探AI

    一.游戏中的人工智能 让游戏具有挑战性: 让游戏好玩的关键因素是为之找到合适的难度等级: 人工智能在游戏中的作用是通过提供富有挑战性的竞争对象来让游戏更好玩,而在游戏中行动逼真的非玩家角色(NPC), ...

  3. Unity3D 游戏开发构架篇 ——角色类的设计与持久化

    在游戏开发中,游戏角色占了很大的篇幅,可以说游戏中所有的内容都是由主角所带动.这里就介绍一下角色类的设计和持久化. 一.角色类应用场景和设计思想 游戏中的角色类型不一而足,有不同的技能,有不同的属性等 ...

  4. 《Genesis-3D开源游戏引擎完整实例教程-2D射击游戏篇05:角色中弹》

    5.角色中弹 概述: 为了使游戏具有挑战性,大部分游戏设定中,游戏角色都有生命限制.即在游戏中,由于玩家的操控操控不当,导致游戏角色死亡游戏终止.打飞机游戏也不例外,当敌人击中角色的时候,角色宣判死亡 ...

  5. 论游戏中Buff的实现 [转]

    论游戏中Buff的实现 分类: C/C++ 游戏开发2012-09-13 14:30 574人阅读 评论(6) 收藏 举报 c++游戏开发 源地址:http://blog.codingnow.com/ ...

  6. Unity3d中角色模型和角色名字保持相对位置

    3D游戏中,经常遇到这样的情况.角色模型上需要显示角色名字或者血条等信息. 如果用一个摄像机会有可能出现名字或血条显示不正常等问题,所以我采用两个摄像机.一个渲染名字或血条等UI,另一个渲染角色模型. ...

  7. Unity优化方向——优化Unity游戏中的图形渲染(译)

    CPU bound:CPU性能边界,是指CPU计算时一直处于占用率很高的情况. GPU bound:GPU性能边界,同样的是指GPU计算时一直处于占用率很高的情况. 原文:https://unity3 ...

  8. Unity 2D游戏开发教程之游戏中精灵的跳跃状态

    Unity 2D游戏开发教程之游戏中精灵的跳跃状态 精灵的跳跃状态 为了让游戏中的精灵有更大的活动范围,上一节为游戏场景添加了多个地面,于是精灵可以从高的地面移动到低的地面处,如图2-14所示.但是却 ...

  9. 浅谈游戏中BUFF的设计要点

    其实这类帖子并没有多少的设计理论,对于策划的提升和帮助也并不大,原因其实在于其适用性太窄,当我要设计XX象棋的时候,它就滚一边去了. 废话不多说切入正题: 游戏中的BUFF/DEBUFF我们见过很多, ...

随机推荐

  1. vue 封装自定义组件

    组件结构 sjld >index.js >sjid.vue 最好单独放一个文件夹,有依赖的话装依赖 Sjld.vue 内容 <template id="sjld" ...

  2. 简谈Redis

    1.为什么使用redis 分析:博主觉得在项目中使用redis,主要是从两个角度去考虑:性能和并发.当然,redis还具备可以做分布式锁等其他功能,但是如果只是为了分布式锁这些其他功能,完全还有其他中 ...

  3. Go:冒泡排序

    package main import "fmt" func BubbleSort(arr *[5]int) { fmt.Println("排序前:", *ar ...

  4. JS 比较运算符 逻辑运算符

    逻辑运算符 三元运算符 摘自:http://www.w3school.com.cn/js/js_comparisons.asp

  5. 51NOD 2370 奈芙莲的护符

    >>这是原题传送门<< 答案参考来自 http://www.cnblogs.com/sugewud/p/9822933.html 思路:看到取值范围之后,仅有的思路还是暴力

  6. 集训第四周(高效算法设计)F题 (二分+贪心)

    Description   A set of n<tex2html_verbatim_mark> 1-dimensional items have to be packed in iden ...

  7. 九度oj 题目1202:排序

    题目1202:排序 时间限制:1 秒 内存限制:32 兆 特殊判题:否 提交:28802 解决:9408 题目描述: 对输入的n个数进行排序并输出. 输入: 输入的第一行包括一个整数n(1<=n ...

  8. add favorite & 收藏夹

    add favorite // 收藏夹 function favorite (){ var ctrl = (navigator.userAgent.toLowerCase()).indexOf(&qu ...

  9. IntentService用于服务中开启子线程的自动关闭

    package com.pingyijinren.test; import android.app.IntentService; import android.content.Intent; impo ...

  10. Ice Cave-CodeForces(广搜)

    链接:http://codeforces.com/problemset/problem/540/C You play a computer game. Your character stands on ...