2015-04-02 64 views
-2

我正在工作到我的遊戲的服務器端,它幾乎完成,但今天我遇到了問題...此遊戲基於2種形式,觸地和死亡競賽,在遊戲結束時,服務器必須知道結果。這是一個在線遊戲。當我結束比賽或者球員出去時,服務器崩潰了,不應該是,它只是回到房間。它給我以下錯誤:無法對類型輸入對象「類型」c#

[ERROR]: Unable to cast object of type 'B3S.Core.Data.GameScore' to type 'B3S.Core.Data.TDGameScore'. 
    in B3S.Core.Data.Player.SetNewTDStats(Boolean win) 
    in B3S.Core.Data.Room.BroadcastBriefing(Boolean result) 
    in B3S.Core.Data.Room.<BeginResult>d__2b.MoveNext() 
--- End of stack trace --- 
    in System.Runtime.CompilerServices.AsyncMethodBuilderCore.<ThrowAsync>b__1(Object state) 
    in System.Threading.QueueUserWorkItemCallback.WaitCallback_Context(Object state) 
    in System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx) 
    in System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx) 
    in System.Threading.QueueUserWorkItemCallback.System.Threading.IThreadPoolWorkItem.ExecuteWorkItem() 
    in System.Threading.ThreadPoolWorkQueue.Dispatch() 
    in System.Threading._ThreadPoolWaitCallback.PerformWaitCallback() 

任何人都可以幫助我?

這是B3S.Core.Data.GameScore的源:

public class GameScore 
    { 
     public DateTime JoinTime { get; set; } 
     public uint TotalPoints { get; set; } 

     public virtual uint CalculateEXP() 
     { 
      return 0; 
     } 
    } 

這是B3S.Core.Data.TDGameScore的源:

public class TDGameScore : GameScore 
{ 
    public uint TDScore { get; set; } 
    public uint TDAssists { get; set; } 

    public uint Kills { get; set; } 
    public uint KillAssists { get; set; } 
    public uint Offense { get; set; } 
    public uint OffenseAssists { get; set; } 
    public uint Defense { get; set; } 
    public uint DefenseAssists { get; set; } 
    public uint Recovery { get; set; } 

    public override uint CalculateEXP() 
    { 
     var ts = DateTime.Now - JoinTime; 
     if (ts.TotalSeconds < 0 || TotalPoints == 0) 
      return 0; 
     return (uint)ts.TotalSeconds/4 + (TDScore * 15) + (100 * TotalPoints/(500 + 2 * TotalPoints) * 14); 
    } 
} 
+1

錯誤信息的哪部分你不明白? – SLaks 2015-04-02 17:28:27

+1

我建議您使用不以可能冒犯某些人的貶義詞開頭的不同名稱空間名稱。 – deloreyk 2015-04-02 18:16:38

+0

我必須使用TDGameScore,因爲它甚至是GameScore,但有其他屬性,因爲它是TouchDown遊戲模式。 – 2015-04-02 18:25:19

回答

1

的TDGameScore是子類(派生類)的GameScore。 最有可能的是,你傳遞了一個不是TDGameScore的GameScore實例。您必須檢查何時創建了有問題的實例,以及它爲什麼不是正確的子類型。

+0

我不知道如何編輯工作...... 我嘗試了很多東西,但總是出現同樣的錯誤。 – 2015-04-02 18:23:32

相關問題