RPG库存系统和装备项目系统 [英] RPG Inventory system and Equip Item System

查看:80
本文介绍了RPG库存系统和装备项目系统的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

伙计们,我一直在VB 2010中开发一款RPG游戏,现在我已经添加了一些物品并赋予了它们一些属性,但是我有点困惑和困惑.我目前有一个包含28个图片框和28个``库存设置&数量''(inv1,inv2等),并且在加载库存表格时,图片会根据设置及其下方的数字进行相应更新,以显示您当前拥有的商品数量.然后,我希望能够单击项目并装备"它,然后将其显示在称为字符屏幕"的另一种形式上.

这是我目前的一些编码:

负载下的库存更新

Hey guys, I''ve been working on a RPG game in VB 2010 and I''ve gotten to the point where I am adding items and giving them properties but I''m a bit confused and stuck. I currently have a form with 28 picture boxes and 28 ''inventory settings & amounts'' (inv1, inv2, etc) and on loading the inventory form the pictures are updated accordingly to the setting and a number below it to show the amount you currently have of the item. Then I want to be able to click the items and it "equips" it which will then show up on a different form called the ''Character Screen''.

Here is some of my current coding for it:

Inventory updating on load

If My.Settings.inv4 = "fvisage" Then
    inv4.Image = My.Resources.fVisage
    inve4.Text = My.Settings.fvisage
ElseIf My.Settings.inv4 = "draBody" Then
    inv4.Image = My.Resources.draBody
    inve4.Text = My.Settings.drabody
ElseIf My.Settings.inv4 = "dralegs" Then
    inv4.Image = My.Resources.draLegs
    inve4.Text = My.Settings.dralegs
ElseIf My.Settings.inv4 = "draboots" Then
    inv4.Image = My.Resources.draBoots
    inve4.Text = My.Settings.draboots
ElseIf My.Settings.inv4 = "drahelm" Then
    inv4.Image = My.Resources.draHelm
    inve4.Text = My.Settings.drahelm
ElseIf My.Settings.inv4 = "clothbody" Then
    inv4.Image = My.Resources.clothBody
    inve4.Text = My.Settings.clothbody
ElseIf My.Settings.inv4 = "clothlegs" Then
    inv4.Image = My.Resources.clothLegs
    inve4.Text = My.Settings.clothlegs
ElseIf My.Settings.inv4 = "clothboots" Then
    inv4.Image = My.Resources.clothBoots
    inve4.Text = My.Settings.clothboots
ElseIf My.Settings.inv4 = "clothhat" Then
    inv4.Image = My.Resources.clothHelm
    inve4.Text = My.Settings.clothhat
ElseIf My.Settings.inv4 = "plaBody" Then
    inv4.Image = My.Resources.plaBody
    inve4.Text = My.Settings.plabody
ElseIf My.Settings.inv4 = "plalegs" Then
    inv4.Image = My.Resources.plaLegs
    inve4.Text = My.Settings.plalegs
ElseIf My.Settings.inv4 = "plaboots" Then
    inv4.Image = My.Resources.plaBoots
    inve4.Text = My.Settings.plaboots
ElseIf My.Settings.inv4 = "plahelm" Then
    inv4.Image = My.Resources.plaHelm
    inve4.Text = My.Settings.plahelm
ElseIf My.Settings.inv4 = "maiBody" Then
    inv4.Image = My.Resources.maiBody
    inve4.Text = My.Settings.maibody
ElseIf My.Settings.inv4 = "mailegs" Then
    inv4.Image = My.Resources.maiLegs
    inve4.Text = My.Settings.mailegs
...
...
...
...



从战斗中获得物品战利品,并将其存储在第一个开放式库存槽中



Gaining item loot from a fight and it being stored in the first open inventory slot

If My.Settings.inv2 = "" Or My.Settings.inv2 = "fvisage" Then
                                   My.Settings.inv2 = "fvisage"
                                   My.Settings.fvisage = My.Settings.fvisage + 1
                                   MsgBox("You gained: " + fgold.ToString + " gold" & vbNewLine & "You gained: " + fExp.ToString + " experience." & vbNewLine & "You gained: " + fExp.ToString + " experience." & vbNewLine & "You''ve also found a Flaming Visage!", vbOKOnly, "Loot")

                               ElseIf My.Settings.inv3 = "" Or My.Settings.inv3 = "fvisage" Then
                                   My.Settings.inv3 = "fvisage"
                                   My.Settings.fvisage = My.Settings.fvisage + 1
                                   MsgBox("You gained: " + fgold.ToString + " gold" & vbNewLine & "You gained: " + fExp.ToString + " experience." & vbNewLine & "You''ve also found a Flaming Visage!", vbOKOnly, "Loot")

                               ElseIf My.Settings.inv4 = "" Or My.Settings.inv4 = "fvisage" Then
                                   My.Settings.inv4 = "fvisage"
                                   My.Settings.fvisage = My.Settings.fvisage + 1
                                   MsgBox("You gained: " + fgold.ToString + " gold" & vbNewLine & "You gained: " + fExp.ToString + " experience." & vbNewLine & "You''ve also found a Flaming Visage!", vbOKOnly, "Loot")

                               ElseIf My.Settings.inv5 = "" Or My.Settings.inv5 = "fvisage" Then
                                   My.Settings.inv5 = "fvisage"
                                   My.Settings.fvisage = My.Settings.fvisage + 1
                                   MsgBox("You gained: " + fgold.ToString + " gold" & vbNewLine & "You gained: " + fExp.ToString + " experience." & vbNewLine & "You''ve also found a Flaming Visage!", vbOKOnly, "Loot")

                               ...
                               ...
                               ...
                               ...



这是我单击图片框之一时发生的设备"方法
在这种情况下,正是在切换的情况下切换到my.settings.inv2
中存储的内容



This is my "equip" method that occurs when clicking one of the picture boxes
it is in a switch case that switches to, in this perticular case, what is stored in my.settings.inv2

Case clothbody
                If My.Settings.clothbody - 1 = 0 Then
                    If My.Settings.body = "" Then
                        inv2.Image = My.Resources.nothng
                        My.Settings.inv2 = ""
                        inve2.Text = "-"
                        chrScreen.body.Image = My.Resources.clothBody
                        My.Settings.armor = My.Settings.armor + 30
                        My.Settings.body = "clothbody"
                        My.Settings.clothbody = My.Settings.clothbody - 1
                    ElseIf My.Settings.body = "clothbody" Then
                    Else
                        Dim x As String
                        Dim mre As String
                        x = My.Settings.body
                        mre = "my.resources." & x
                        My.Settings.body = "clothbody"
                        If My.Settings.inv2 = x Then
                            inv2.Image = My.Resources.nothng
                            inve2.Text = "-"
                        ElseIf My.Settings.inv3 = x Then
                            inv3.Image.Tag = mre
                            inv3.Image = inv3.Image.Tag
                            inve3.Text = "-"
                        ElseIf My.Settings.inv4 = x Then
                            inv4.Image = My.Resources.nothng
                            inve4.Text = "-"
                        ElseIf My.Settings.inv5 = x Then
                            inv5.Image = My.Resources.nothng
                            inve5.Text = "-"
                        ElseIf My.Settings.inv6 = x Then
                            inv6.Image = My.Resources.nothng
                            inve6.Text = "-"
                        ElseIf My.Settings.inv7 = x Then
                            inv7.Image = My.Resources.nothng
                            inve7.Text = "-"
                        ElseIf My.Settings.inv8 = x Then
                            inv8.Image = My.Resources.nothng
                            inve8.Text = "-"
                        ElseIf My.Settings.inv9 = x Then
                            inv9.Image = My.Resources.nothng
                            inve9.Text = "-"
                        ElseIf My.Settings.inv10 = x Then
                            inv10.Image = My.Resources.nothng
                            inve10.Text = "-"
                        ElseIf My.Settings.inv11 = x Then
                            inv11.Image = My.Resources.nothng
                            inve11.Text = "-"
                        ElseIf My.Settings.inv12 = "" Then
                            inv12.Image = My.Resources.nothng
                            inve12.Text = "-"
                        ElseIf My.Settings.inv13 = x Then
                            inv13.Image = My.Resources.nothng
                            inve13.Text = "-"
                        ElseIf My.Settings.inv14 = x Then
                            inv14.Image = My.Resources.nothng
                            inve14.Text = "-"
                        ElseIf My.Settings.inv15 = x Then
                            inv15.Image = My.Resources.nothng
                            inve15.Text = "-"
                        ElseIf My.Settings.inv16 = x Then
                            inv16.Image = My.Resources.nothng
                            inve16.Text = "-"
                        ElseIf My.Settings.inv17 = x Then
                            inv17.Image = My.Resources.nothng
                            inve17.Text = "-"
                        ElseIf My.Settings.inv18 = x Then
                            inv18.Image = My.Resources.nothng
                            inve18.Text = "-"
                        ElseIf My.Settings.inv19 = x Then
                            inv19.Image = My.Resources.nothng
                            inve19.Text = "-"
                        ElseIf My.Settings.inv20 = x Then
                            inv20.Image = My.Resources.nothng
                            inve20.Text = "-"
                        End If
                        End If
                ElseIf My.Settings.clothbody = 0 Then
                        inv2.Image = My.Resources.nothng
                        My.Settings.inv2 = ""
                        inve2.Text = "-"
                Else
                        chrScreen.body.Image = My.Resources.clothBody
                        My.Settings.armor = My.Settings.armor + 30
                        My.Settings.clothbody = My.Settings.clothbody - 1
                        inve2.Text = My.Settings.clothbody
                        My.Settings.body = "clothbody"

                End If



假设整个"Elseif my.settings.inv2 = x then"是为了在您已经在该插槽中装有某个物品但似乎不起作用并且我似乎无法抓住该物品的情况下准备的.从字符屏幕中单击项目",然后将其带回到清单屏幕,而不会引起问题.

现在,我知道我的代码效率很低而且很长,可能总体上是不必要的,但是我陷入了困惑和困惑,不知道应该怎么做.我尝试创建一个新类并创建一个函数,以便能够以其他形式调用该函数,以查找下一个以inv2开头的可用插槽(无论inv1总是有黄金,即使您拥有0金),但没有成功,因为我什至不知道从哪里开始.

我需要知道创建库存系统以及装备和未装备物品的最有效方法,找到空库存槽并将物品放入其中的最有效方法.

在此先感谢您,希望大家度过愉快的一天. :)



The whole ''Elseif my.settings.inv2 = x then'' thing was suppossed to be for in cases where you already have a item equipped in that slot but that seems to not work and I can''t seem to grab the ''item'' from the character screen and bring it back to the inventory screen without causing a problem.

Now, I know my code is very inefficient and long and probably overall unnecessary but I''m stuck and confused and have no idea what I should be doing. I tried creating a new class and making a function, that I''d be able to call on in a different form, to find the next available slot starting with inv2 (inv1 always has gold in it no matter what, even if you have 0 gold) but that didn''t work cause I again didn''t even know where to start.

I need to know the most efficient way of creating a inventory system and being able to equip and unequipped items, most efficient way of finding empty inventory slot and putting an item into it.

Thank you in advance and I hope you all have a great day. :)

推荐答案

您的问题是一个长的if-then-else块,而不是具有一些索引容器.更改switch语句并不会真正有帮助.在我的文章动态方法分派器,不再需要长的switch语句!"中,我以一种非常通用的形式解释了一种正确的方法.请参阅:
动态方法分派器 [
Your problem is a long if-then-else block, instead of having some indexed container of data. A change to switch statement won''t really help. I explain one of the right approaches in a very universal form in my article "Dynamic Method Dispatcher, No more long switch statements!". Please see:
Dynamic Method Dispatcher[^].

—SA


这篇关于RPG库存系统和装备项目系统的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆