这是我定义结构的方式(假设 VB.Net-fu 没有让我失望):
Public Class Decision
Public Property Title As String
Public Property Description As String
Public Property FirstChoice As Decision
Public Property SecondChoice As Decision
End Class
这Title
是您在选择该选项的按钮上或上方显示的内容。
这Description
是您做出选择后所显示的内容,并且正在做出下一个决定。
如果FirstChoice
orSecondChoice
为空,您可以选择隐藏按钮。这将允许您只选择一个选项,并将其倾斜到框架的一侧,以获得戏剧性的效果。例如:
You've found yourself in a narrow corridor
[Go Right]
如果您想启用两个以上的选择,或者至少让您自己在未来可以自由选择,您可以像这样定义您的数据结构:
Public Class Decision
Public Property Title As String
Public Property Description As String
Public Property Decisions As New List(Of Decision)
End Class
您可以使用ListBox
或GridView
样式控件将其显示给用户,或者根据列表中有多少项目,可以选择在列表框和按钮之间切换。
顺便说一句,数据结构是有意递归的。这变成了一个树结构,并且在树的每个节点上,您都有一个决策,并且可能是子决策。
通常你不会循环这样的结构,但在这种情况下你没有理由不能这样做。如果您遇到“游戏结束”风格的情况,您的选择可以简单地回到开始,这将链接到根实例(因此是一个“循环图”)。
编辑
这是一个代码示例,向您展示如何将它们挂钩:
Dim darkAlley = New Decision With
{
.Title = "Dark Alley",
.Description = "You are in a deep dark alley." _
+ " The night surrounds you and you feel a bit claustrophobic." _
+ " Obvious exits are east and Salisbury street."
}
Dim eastOfDarkAlley = New Decision With
{
.Title = "East of Dark Alley",
.Description = "You are mauled by a bear!" _
+ " He was a dire bear, so he had rabies. Start over?"
}
Dim salisburyStreet = New Decision With
{
.Title = "Salisbury street",
.Description = "Mmm... Ground beef... Blarrghlhlap (*tongue hangs out*)"
}
darkAlley.FirstChoice = eastOfDarkAlley
darkAlley.SecondChoice = salisburyStreet
eastOfDarkAlley.FirstChoice = darkAlley
salisburyStreet.FirstChoice = darkAlley