我正在使用视觉工作室开发基于文本的Visual Basic游戏,我很确定我的一个变量的数据没有被传递给我的一个事件,所以当事件执行时,它会填充一些0。我环顾四周试图找到一个修复,但因为我是初学者,我不能确定我能做些什么。
已编辑: 继承人的代码
Public Class Entity
Private ename As String
Private esymbol As Char
Private ecolor As ConsoleColor
Private ex As Integer
Private ey As Integer
Public Property name() As String
Get
Return ename
End Get
Set(ByVal value As String)
ename = value
End Set
End Property
Public Property symbol() As Char
Get
Return esymbol
End Get
Set(ByVal value As Char)
esymbol = value
End Set
End Property
Public Property color() As ConsoleColor
Get
Return ecolor
End Get
Set(ByVal value As ConsoleColor)
ecolor = value
End Set
End Property
Public Property x() As Integer
Get
Return ex
End Get
Set(ByVal value As Integer)
ex = value
End Set
End Property
Public Property y() As Integer
Get
Return ey
End Get
Set(ByVal value As Integer)
ey = value
End Set
End Property
Public Sub New(ByVal ename As String, ByVal esymbol As Char, ByVal ecolor As ConsoleColor, ByVal ex As Integer, ByVal ey As Integer)
ename = name
esymbol = symbol
ecolor = color
ex = x
ey = y
End Sub
End Class
Public Class Adventurer
Inherits Entity
Public Sub New(ByVal name As String, ByVal x As Integer, ByVal y As Integer)
MyBase.New(name, "@", ConsoleColor.Magenta, x, y)
End Sub
End Class
Module VbQuest
Public Sub Main()
Console.Title = "VB Quest"
Console.SetWindowSize(80, 35)
Console.Clear()
Console.WriteLine("Welcome to VB Quest!")
Console.WriteLine("What is your name?")
Console.Write(">")
Dim name As String = Console.ReadLine()
Static player = New Adventurer(name, 1, 1)
Console.Clear()
DrawPlayer(player)
Console.ReadKey()
End Sub
Sub DrawPlayer(ByVal player As Entity)
Console.SetCursorPosition(player.x, player.y)
Console.ForegroundColor = player.color
Console.Write(player.symbol)
Console.ResetColor()
End Sub
End Module
答案 0 :(得分:0)
Entity
构造函数中的分配顺序错误
将其更改为
Public Sub New(ByVal ename As String, ByVal esymbol As Char, ByVal ecolor As ConsoleColor, ByVal ex As Integer, ByVal ey As Integer)
name = ename
symbol = esymbol
color = ecolor
x = ex
y = ey
End Sub