C# CS1503和x9;参数1:无法从';Poc.Core.Player';至';Poc.Interfaces.ischedulable';
对不起,我对编程还不熟悉,所以这可能是一个很容易解决的问题,我没有足够的知识知道如何解决 我用这个教程来做一个简单的地下城爬虫 在实现kobolds(我的项目中的变种人)的行为时,我会得到一个错误,说“参数1:无法从”Poc.Core.(Player/monster)”转换为“Poc.Interface.ISchedule” 这发生在DungeonMap.cs中的addplayer无效、addmonster无效和removemonster无效上,在CommandSystem.cs中的ActivateMonster无效上发生了两次 如果有人能帮我解决这个问题,我将不胜感激 问题空白:C# CS1503和x9;参数1:无法从';Poc.Core.Player';至';Poc.Interfaces.ischedulable';,c#,roguelike,C#,Roguelike,对不起,我对编程还不熟悉,所以这可能是一个很容易解决的问题,我没有足够的知识知道如何解决 我用这个教程来做一个简单的地下城爬虫 在实现kobolds(我的项目中的变种人)的行为时,我会得到一个错误,说“参数1:无法从”Poc.Core.(Player/monster)”转换为“Poc.Interface.ISchedule” 这发生在DungeonMap.cs中的addplayer无效、addmonster无效和removemonster无效上,在CommandSystem.cs中的Activa
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();
}
}
名称空间Poc.Systems
{
公共类调度系统
{
私人国际时间;
专用只读分类词典可调度;
公共调度系统()
{
_时间=0;
_scheduleables=新的SortedDictionary();
}
公共作废添加(可调度可调度)
{
int key=_time+可调度的.time;
if(!\u可调度的容器(键))
{
_Add(key,newlist());
}
_可调度[键]。添加(可调度);
}
公共无效删除(可计划)
{
找到KeyValuePair SchedulableListFound
=新的KeyValuePair(-1,null);
foreach(var scheduleablesList in _scheduleables)
{
if(可调度列表值包含(可调度))
{
SchedulableListFound=SchedulablesList;
打破
}
}
if(schedulablelistfound.Value!=null)
{
SchedulableListFound.Value.Remove(可调度);
如果(schedulablelistfound.Value.Count确保您的Actor
类(它是Player
和Monster
继承的)正在实现ischedulable
:
public class Actor : IActor, IDrawable, IScheduleable
{
// ... Previous Actor code omitted
// IScheduleable
public int Time
{
get
{
return Speed;
}
}
}
向我们展示您的代码是否确定Poc.Core.Player
实现了Poc.Interfaces.ischedulable
?