CS1503 参数 1:无法从 'Poc.Core.Player' 转换为 'Poc.Interfaces.IScheduleable'



对不起,我对编程很陌生,所以这可能是一个很容易解决的问题,我的知识不够,不知道如何修复

我使用这个教程作为一个简单的地牢爬虫https://bitbucket.org/FaronBracy/roguesharpv3tutorial/src/master/

当涉及到实现kobolds(我的项目中的突变体(的行为时,我会收到一个错误,说"参数1:无法从Poc.Core.(Player/monster("转换为"Poc.Interface.ISchedule">

这种情况发生在地下城地图中的addplayer虚空、addmonster虚空和removegmonster虚空上,在CommandSystem.cs 中的ActivateMonsters虚空上发生了两次

如果有人能帮我解决这个问题,我将不胜感激

问题空隙:

public void AddPlayer(Player player)
{
Game.Player = player;
SetIsWalkable(player.X, player.Y, false);
UpdatePlayerFieldOfView();
**Game.SchedulingSystem.Add(player);**
}


public void AddMonster(Monster monster)
{
_monsters.Add(monster);
// After adding the monster to the map make sure to make the 
cell not walkable
SetIsWalkable(monster.X, monster.Y, false);
**Game.SchedulingSystem.Add( monster );**
}

public void RemoveMonster(Monster monster)
{
_monsters.Remove(monster);
SetIsWalkable(monster.X, monster.Y, true);
**SchedulingSystem.Remove(monster);**
}

public void ActivateMonsters()
{
IScheduleable scheduleable = Game.SchedulingSystem.Get();
if (scheduleable is Player)
{
IsPlayerTurn = true;
**Game.SchedulingSystem.Add(Game.Player);**
}
else
{
Monster monster = scheduleable as Monster;
if (monster != null)
{
monster.PerformAction(this);
**Game.SchedulingSystem.Add(monster);**
}
ActivateMonsters();
}
}

然后我的调度系统代码

namespace Poc.Systems
{
public class SchedulingSystem
{
private int _time;
private readonly SortedDictionary<int, List<IScheduleable>> _scheduleables;
public SchedulingSystem()
{
_time = 0;
_scheduleables = new SortedDictionary<int, List<IScheduleable>>();
}

public void Add(IScheduleable scheduleable)
{
int key = _time + scheduleable.Time;
if (!_scheduleables.ContainsKey(key))
{
_scheduleables.Add(key, new List<IScheduleable>());
}
_scheduleables[key].Add(scheduleable);
}
public void Remove(IScheduleable scheduleable)
{
KeyValuePair<int, List<IScheduleable>> scheduleableListFound
= new KeyValuePair<int, List<IScheduleable>>(-1, null);
foreach (var scheduleablesList in _scheduleables)
{
if (scheduleablesList.Value.Contains(scheduleable))
{
scheduleableListFound = scheduleablesList;
break;
}
}
if (scheduleableListFound.Value != null)
{
scheduleableListFound.Value.Remove(scheduleable);
if (scheduleableListFound.Value.Count <= 0)
{
_scheduleables.Remove(scheduleableListFound.Key);
}
}
}

public IScheduleable Get()
{
var firstScheduleableGroup = _scheduleables.First();
var firstScheduleable = firstScheduleableGroup.Value.First();
Remove(firstScheduleable);
_time = firstScheduleableGroup.Key;
return firstScheduleable;
}
// Get the current time (turn) for the schedule
public int GetTime()
{
return _time;
}

{
_time = 0;
_scheduleables.Clear();
}
}

}

确保PlayerMonster继承的Actor类正在实现IScheduleable:

public class Actor : IActor, IDrawable, IScheduleable
{
// ... Previous Actor code omitted

// IScheduleable
public int Time
{
get
{
return Speed;
}
}
}

最新更新