2016-12-18 42 views
-4

我正在使用視覺工作室在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 
+1

【如何提問](http://stackoverflow.com/help/how-to-ask) – tkausl

+3

你好!歡迎來到堆棧溢出 - 請你能將代碼發佈到你的問題中(作爲格式化文本而不是截圖)?你也應該刪除儘可能多的不相關的東西來形成一個[mcve] - 當你這樣做的時候你會經常解決你自己的問題。 –

+0

作爲一種幫助去除不相關的東西,屬性應該是自動屬性,除非你在getter或setter中做某事。如果您在y = y時遇到問題,請使用me.y = y – jmoreno

回答

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