【经典】C++&RPG对战游戏 您所在的位置:网站首页 拳皇游戏代码 【经典】C++&RPG对战游戏

【经典】C++&RPG对战游戏

2023-10-08 22:36| 来源: 网络整理| 查看: 265

博文背景:

  还记大二上学期的时候看的这个C++&RPG游戏(博主大一下学期自学的php,涵盖oop内容),一个外校的同学他们大一学的C++,大二初期C++实训要求做一个程序填空,就是这个 RPG 对战游戏,有几处空需要填上,问我可以不,我就信誓旦旦的说OK,最后“万般无奈多方考究”才给将程序补充完整。最近在做毕业设计,用到C++&QT oop部分,重新温习了下C++ oop,就想起来大二的时候还“捣鼓”过这么个游戏,现重新看了下,进行整理总结,写下该博文。

--------------------华丽的分割线,开始正题-----------------

 本RPG游戏介绍:

  用户创建一个玩家,与AI进行PK,PK中,可以普通攻击(随机暴击、躲闪)、技能攻击、加血、加蓝。本游戏中指定了5个对手,任务失败或者打败所有对手游戏结束。

代码架构:

mian.cpp:控制游戏流程.

container.h container.cpp:物品类.

player.h player.cpp:角色类.

swordsman.h swordsman.cpp:剑士角色.

archer.h archer.cpp:弓箭手角色.

mage.h mage.cpp:魔法师角色.

每个角色都需要物品,每个角色都继承与角色类。

全部代码如下:

1 //======================= 2 // main.cpp 3 //======================= 4 5 // main function for the RPG style game 6 7 #include 8 #include 9 using namespace std; 10 11 #include "swordsman.h" 12 #include "archer.h" 13 #include "mage.h" 14 15 int main() 16 { 17 string tempName; 18 bool success=0; //flag for storing whether operation is successful 19 cout >tempName; // get player's name from keyboard input 21 player *human; // use pointer of base class, convenience for polymorphism 22 int tempJob; // temp choice for job selection 23 do 24 { 25 cout attack(enemy); 81 human->isLevelUp(); 82 enemy.isDead(); 83 break; 84 case 2: 85 success=human->specialatt(enemy); 86 human->isLevelUp(); 87 enemy.isDead(); 88 break; 89 case 3: 90 success=human->useHeal(); 91 break; 92 case 4: 93 success=human->useMW(); 94 break; 95 default: 96 break; 97 } 98 } 99 if(!enemy.death()) // If AI still alive 100 enemy.AI(*human); 101 else // AI died 102 { 103 cout0) 36 { 37 HP=HP+100; 38 if(HP>HPmax) // HP cannot be larger than maximum value 39 HP=HPmax; // so assign it to HPmax, if necessary 40 cout0) 57 { 58 MP=MP+100; 59 if(MP>MPmax) 60 MP=MPmax; 61 coutp.speed) && (rand()%100=LV*LV*75) 31 { 32 LV++; 33 AP+=4; 34 DP+=4; 35 HPmax+=8; 36 MPmax+=2; 37 speed+=2; 38 cout


【本文地址】

公司简介

联系我们

今日新闻

    推荐新闻

    专题文章
      CopyRight 2018-2019 实验室设备网 版权所有