CS1503 Argument 1: cannot convert from 'Poc.Core.Player' to 'Poc.Interfaces.IScheduleable'

118 Views Asked by At

sorry im newish to programming so this may be an easy solvable problem that im not knowledgeable enough to know how to fix

Im using this tutorial for a simple dungeon crawler https://bitbucket.org/FaronBracy/roguesharpv3tutorial/src/master/

when it came to implementing the behaviors of the kobolds (mutants in my project) i would get an error saying 'Argument 1: cannot convert from 'Poc.Core.(Player/monster)" to "Poc.Interface.ISchedule"

this was happening on the addplayer void, addmonster void, and removemonster void in the DungeonMap.cs and twice on the ActivateMonsters void in CommandSystem.cs

i would appreciate it so much if someone could help me fix this problem

problem voids:

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();
        }
    }

then my Scheduling System code

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();
    }
}

}

1

There are 1 best solutions below

0
On

Make sure that your Actor class, which Player and Monster inherit from, is implementing IScheduleable:

public class Actor : IActor, IDrawable, IScheduleable
{
  // ... Previous Actor code omitted
 
  // IScheduleable
  public int Time
  {
    get
    {
      return Speed;
    }
  }
}