2026年游戏开发工程师面试笔试题集.docxVIP

  • 0
  • 0
  • 约7.2千字
  • 约 20页
  • 2026-08-13 发布于福建
  • 举报

第PAGE页共NUMPAGES页

2026年游戏开发工程师面试笔试题集

一、编程基础(5题,每题10分,共50分)

1.C++面向对象编程

题目:请编写一个`Player`类,包含私有属性`hp`(生命值)和`attack`(攻击力),公有方法`attackOther`(对其他玩家造成伤害),并在主函数中创建两个`Player`对象进行战斗,直到一方`hp`归零。要求使用构造函数刜始化属性,并在`attackOther`中检查是否击杀对方。

答案:

cpp

includeiostream

usingnamespacestd;

classPlayer{

private:

inthp;

intattack;

public:

Player(inthp,intattack):hp(hp),attack(attack){}

voidattackOther(Playertarget){

target.hp-=this-attack;

if(target.hp=0){

coutPlayer被击杀!endl;

}else{

cout攻击成功,对方剩余hp:target.hpendl;

}

}

boolisAlive()const{returnhp0;}

};

intmain(){

Pl

文档评论(0)

1亿VIP精品文档

相关文档