C++抽象类练习题——games

这是一篇关于C++编程的博客,详细介绍了如何实现一个涉及抽象类的游戏对象系统。文章通过一个名为'games'的问题,讨论了抽象类的概念,强调了在抽象类中定义的虚函数必须在子类中实现。博客还提供了示例输入/输出和代码,展示了游戏对象如工人、狂热者和塔的行为,包括移动、攻击、修复和建造。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Description:

In this problem, you should complete some classes.

You can see more details in sample input / output and main.cpp

Each gameobject will have position,speed, and 10HP.

When you select a gameobject, we will hear it’s voice.You should print this voice.

When you select a worker, you will hear “Scv good to go, sir!”
When you select a zealot, you will hear “My life for Aiur!”
When you select a tower, you will hear nothing, and you can replace it by a “~”

We describe the speed as a vector (dx, dy)
For the three gameobjects, they are (1, 1) (2, 2) and (0, 0). (Tower cannot move.)
When a object moves, you should print where he moves to.

Zealot and tower can attack other objects and their damages are 1.

Worker can repair an object.

When worker build a building, you should print a triangle by ‘*’ with different height.

For example, if the worker build a building with 3 you should print
+
+++
+++++

sample input

1 1
2 2
3 3
4

sample output

test for select:
Scv good to go, sir!
My life for Aiur
~

test for move:
Worker moves to (2, 2)
Zealot moves to (4, 4)
Tower cannot move

test for attack:
Zealot’s hp is 9
Tower’s hp is 9

test for repair:
Zealot’s hp is 10

test for build:
+
+++
+++++
+++++++

题目说明:
题目描述中三角形可能看上去可能会有些问题。高度为3的三角形,第一层为2个空格和一个+,第二层为1个空格和三个+,第三层为5个+

关于move函数,对于原本在(x,y)的对象,移动到(x+dx, y+dy)

为避免奇怪错误,repair 和 attack传参数请传gameobject*

解答:

#ifndef HEADER_H
#define HEADER_H
#include<iostream>
using namespace std;
class gameobject {
    protected:
        double x, y;
        double dx, dy;
        int hp;
    public:
        gameobject(double x = 0, double y = 0, double dx = 0, double dy = 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值