- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在使用两个类制作一个基于类的库存系统:一个用于角色,一个用于元素。
Code by Ryan Newell - NEW14136796 Uclan Student (Need to put this in so plagarism monitors won't flag me for copying my own work)
这是我到目前为止得到的。
///Code by Ryan Newell - NEW14136796 Runshaw College - Uclan
#include<iostream> //Base C++ required #
#include<string> //Allows input of strings
#include<iomanip> //Base C++ required #
#include <conio.h> //Getchar error workaround
#include <cstdlib> // Provides EXIT_SUCCESS
#include <fstream> // Allows output of txt files
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include <vector>
#include <utility>
#include <Windows.h>//ConsoleSleep
using namespace std;
class itemspell{
string itemname; //Name ((( what if items are the same name ? make difficult for finding statements ? maybe more char with same name item ?
string itemtype; // Spell/Weapon/Armour/Magic Misc?
string itemact; // What type of action does this item do ?
string itemdesc; // Some random ingame description
itemspell* inext; //The next pointer location
bool isspell; //Is Spell Boolean
bool isweapon; // Weapon
bool isarmour; // So on so forth
bool ismisc; // Misc
bool offensiveitem; //Offensive item
bool defensiveitem; // defensive item
bool passiveitem; // Passive effect
int damage;
int armour;
int magicbonus;
int magicresistance;
int cost;
void item_spellsearch(itemspell* ihead, itemspell* &ipast, itemspell* &icurrent)
{
string search;
if (ihead==NULL)
{
cout<<"There are no items on the list to search"<<endl;
}
else
{
cout<<"Enter the type item you are searching for :"<<endl;
getline(cin,search);
icurrent=ihead; //current pointer goes to -> header
cout<<icurrent<<" "<<search<<" "<<icurrent->itemtype<<endl;
while(icurrent!=NULL && search>icurrent->itemname)
{
cout<<"Item Type:"<<icurrent->itemtype<<" "<<cout<<icurrent->itemname<<endl;
ipast=icurrent; //Past = new current pointer
icurrent=icurrent->inext; //current pointer = next pointer
}
}
}
public:
itemspell()//Building a new item // -- Cannot put byref / by values in here remember, needs to be default constructor for some reason ??
{
cout<<"Enter Item Type: "<<endl;
getline(cin,itemtype);
cout<<"Enter Item Name: "<<endl;
getline(cin,itemname);
cout<<"Enter Item Description: "<<endl;
getline(cin,itemdesc);
cout<<"Enter Item Action :"<<endl;
getline(cin,itemact);
}
~itemspell()//Delete record output
{
cout<<"Item being deleted"<<endl;
Sleep(500);
cout<<"Item deleted"<<endl;
getch();
}
void additemspell(itemspell* &ihead) // Add record code
{
itemspell *icurrent;
itemspell *ipast;
itemspell *newitem;
newitem = new itemspell; // New itemspell
if (ihead == NULL || newitem->itemname<ihead->itemname) //If no header or itemname is null;
{
newitem->inext = ihead;
ihead = newitem;
}
else
{
icurrent= ihead;
while(icurrent !=NULL&&icurrent->itemname<newitem->itemname) // While the current char Does not equal NULL/"Nothing and charcurrent itemname = newitemitemname"
{
ipast=icurrent;
icurrent=icurrent->inext;
}
newitem->inext=icurrent; // Sets the next char to current and the past char to next to add in new record.
ipast->inext=newitem;
}
}
void deleteitemspell(itemspell* &ihead) /// Getting the address of the itemspell not the itemspell itself
{
itemspell *ipast=NULL, *icurrent=NULL;
item_spellsearch(ihead, ipast, icurrent);
if(ihead!=NULL)
if(icurrent==NULL)
{
cout<<"ERROR: No itemspell Found"<<endl;
Sleep(500);
cout<<"returning to menu... press enter"<<endl;
getch();
}
else
{
if (icurrent == ihead)
{
ihead = ihead->inext;
}
else
{
ipast->inext=icurrent->inext; //Resets the pointer and header's back to previous positions....
delete icurrent;// Calls the deletion of the itemspell entry.
cout<<"itemspell found was deleted press enter to confirm"<<endl;
getch();
}
}
}
class character
{
string forename;
string surname;
string nickname;
string race;
string alignment;
string alignment_type;
string character_class;
int Strength; //Strength
int Intelligence; //Magick 2
int Willpower; //Magick 1
int Endurance; //Health
int Agility; //Agility
int StartingWealth; //StartingWealth
character* char_itemp; // Character - Item pointer - Adress location of the characters items
character* char_next; // Next Pointer Value- Points to the location of the next person in the Dynamic Linked List
我想做的是,当我创建一个新项目时,我希望能够将该项目提供给角色使用。
我知道我需要在字符类中创建一个指针值以指向 itemspell 类,但我不确定该怎么做并且可以在一些帮助下做。
本质上,当从项目类中的构造函数调用项目类时,我想让字符类指向项目类。
如果可以的话,请不要只提供代码。相反,请突出显示我应该更改的区域并提供建议示例。我的学位类(class)严格禁止抄袭。
伪代码
When newitemspell created
get input charactername ()
:
if no current itemspell created for that character
add item to
character->charactername
else
add item to next pointer character->charactername
最佳答案
通过查看您的代码并查看您要完成的目标的描述符,您为什么不创建一个 Inventory 类来处理用户项目?它应该能够处理 99% 的任何您想做的事情。让我知道这个例子是否与您想要做的一样。
老实说,我完全不知道您要在代码中做什么。正如之前的用户提到的,“链接”两个类是为基类提供所需类的变量的简单问题。例如:
#include <vector> //I prefer to use vectors for just about any list of objects.
//It's just more convenient for me.
using std::vector;
class Inventory //A handler for all of your character's stuff.
{
private:
vector<object_class> objs; //To actually store an array of whatever objects
//you need to.
//Just some example functions to make the class useful.
public:
int MAX = -1; //The size limit for the inventory. This can be used as a useful
//statistic in the specific inventory, depending on how it's being
//used. My example shows the value at -1, which, at least for me,
//means that any maximum size checks being done won't bother it
//because I usually have a setting of -1 as being unlimited.
getItem(int slot); //Return item
removeItem(int slot) //Removing items
addItem(object_class object) //Adding items
}
这只是从这里开始的非常简单的编程。您需要做的就是创建类型为 Inventory
的变量。对 object_class
的任何引用都只是您希望 Inventory 处理的任何对象的类类型的通用填充。当您使用派生类时,这很可能是基类。
class Character //The character class with all kinds of stuff to needs to be handled
{
public:
Inventory items; //A regular inventory bag for items.
Inventory equip; //The items the character is currently using.
Inventory spells; //An alternate use for Inventory to be used as a handler for
//spell lists and other cool stuff.
}
从这里您应该能够了解到底发生了什么。库存没有“链接”到角色。 Character 具有三个类型为 Inventory 的变量,Inventory 类本身将处理其 vector 中项目的所有添加、删除、排序和检索。
现在你可以让一切都像这样:
int main(int argc, char *argv[])
{
Character player;
Armor shield = new Armor(); //A dummy object
player.items.addItem(shield); //Assuming the Inventory is setup to handle Armor items.
//This will add the shield to the player's inventory.
player.items.MAX = 10; //Setting the maximum capacity of items to 10, obviously.
Armor A = player.items.getItem(0); //returns the piece of armor in the first spot in the vector.
}
我通常会为这样的事情编写更模块化的代码,例如将 Inventory 设为模板类,但我离题了。这只是为了向您展示如何将一个类对象附加到另一个类对象。
我希望这与您正在搜索的内容完全一样。如果不是,请尝试更具体地重写您的问题。
关于c++ - 动态链接列表 RPG 库存程序 - 帮助(如何链接到类?),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29688019/
作为背景,我一直在根据 Ray Wenderlich 的教程开发一款角色扮演游戏。 (示例)http://www.raywenderlich.com/1163/how-to-make-a-tile-b
有谁知道在哪里可以找到 RP 游戏开发的类图示例?类似here的东西会很有用的。我不是在寻找可以盲目复制的东西,而是在寻找不同的示例,这些示例为我在尝试用铅笔记下自己的类时发现的问题绘制了各种解决方案
我的代码有问题,当调用时,它似乎使战斗持续的时间比应有的时间长。 我认为问题出在 if 语句上,所以我一直在研究它们,但我似乎无法把它弄对。 class Enemy: def __init__
我的 RPG 统计代码有点问题。我希望人们使用 6 个基本属性(力量、敏捷、体质、智力、智慧和魅力),最小值为 10。创建角色时,我希望他们有 15 点可以使用,并且在我的代码,一切正常,除非你在到达
我正在尝试制作一个角色扮演游戏战斗系统,您可以在其中与地精作战。不幸的是,我用来制作运气系统的随机发生器并没有像我想要的那样工作。出于某种原因,当我希望它每次都是不同的值时,随机变量在每个循环中总是相
我正在为我的研究开发一款角色扮演游戏,我们需要使用设计模式,并且我正在尝试编写动态角色技能。例如,我会有一些元素,在装备后,会添加角色以前没有的新技能(治疗...)。 为此,我想使用装饰器模式,但是使
我正在用 js 制作一个网络 Angular 色扮演游戏,使用 melon JS 和 SQL DB 以及 PHP。这个问题是关于如何存储每个非玩家 Angular 色 (NPC) 的已完成任务和当前任
鉴于以下树结构,每个登录的玩家都可以拥有当前和已完成级别的数据、每个级别的任务、每个任务的 NPC 以及每个 NPC 的多个任务......我正在尝试找出最好的方法存储每个玩家的当前和完成数据。 我之
所以我一直在学习 C++ 和 SDL 来制作一些基本的 2d 游戏。我想创建一个类似于魔兽世界的游戏,但它是一个 2D 版本。我希望它在线并使用数据库或其他东西来启动数据,如黄金数量、HP 等。不过我
既然我终于弄清楚了类继承在 ruby 中的工作原理,我正在为文本 rpg 设计一个库存系统。但是,有些怪癖我无法弄清楚。 项目类别: class Item attr_accessor :n
我需要帮助在我的文字 RPG 游戏中设置检查点。我给用户两种选择,其中之一会导致他们被杀。他们死后,我想让他们回到检查点的起点,但我不知道该怎么办。 我尝试过 while (true) {, cont
我正在制作一个角色扮演游戏,但是,我现在遇到了一个错误。玩家的角色可以在所有四个主要方向上移动,但如果您向右、向上或向下移动,玩家就会卡住。 此外,错误似乎有一些逻辑: 如果向下移动,角色会卡在向下移
为了练习,我正在使用 Java 创建一个基于文本的 RPG。我目前正在使用 .properties 文件来处理字符信息。我知道 YAML 可能是一个更好的选择,但我不太确定如何实现它。使用属性,创建库
我正在编写 RPG 程序,我希望角色对象创建控制其“能力”的对象 每个字符都有一个字符串变量 powerOne、PowerTwo 等。 powerOne =“攻击” 我需要一种方法来做到这一点: "
我不确定我的代码有什么问题,我正在尝试创建一个 while 循环,该循环将使用在 SQL 中声明的游标获取字段(代码)中的下一个字符。目标是通过循环获取下一个匹配的字符。然后我想在循环结束时返回结果。
我在 RPG 中编写了一个监控程序,用于检查 fax/400 是否正常运行。 现在我希望这个程序每 15 分钟检查一次。 我没有在作业调度程序中每 15 分钟放置一个作业(这很难管理),而是使用 DL
我需要为我的 RPG 程序中的现有物理文件创建一个新成员。我知道有两种方法,但我必须说,我都不喜欢: 使用QCMDEXC调用ADDPFM 编写一个 CL 程序,调用 ADDPFM 并从 RPG 调用它
我只是在玩一个基于文本的 RPG,我想知道,命令解释器究竟是如何实现的,现在有没有更好的方法来实现类似的东西?编写大量 if 语句很容易,但这似乎很麻烦,特别是考虑到大多数情况下 pick up th
我正在尝试创建一个过程,该过程将采用一个数组并返回已使用元素的计数(为什么这不是 BIF??)。我正在努力寻找一种将未知大小的数组传递给我的程序的方法。 类似... P count B
我正在尝试制作一个简单的基于文本的游戏。 while True: choice = raw_input('>>: ') aa = choice.split() if aa[0]
我是一名优秀的程序员,十分优秀!