Wizards and Warriors C# -

My code works fine in visual studio 2022 and visual studio code and several other online C# code editors, but for some reason in exercism code editor it wont work with plenty errors reporting

It is unlikely that anyone here can help you without access to your code and more information about the errors. So please provide your code and quote your errors.

Format code like this:

```csharp
public static class HelloWorld
{
    public static string Hello() => "Hello, World!";
}
```

this renders as

public static class HelloWorld
{
    public static string Hello() => "Hello, World!";
}
1 Like

One common error in earlier exercises is printing values when the tests expect you to return values.

using System;

public abstract class Character
{


    protected string _characterType;

    public Character(string characterType)
    {
        this._characterType = characterType;
    }

    public abstract int DamagePoints(Character target);

    public virtual bool Vulnerable() => false;

    public override string ToString() => $"Character is a {this._characterType}";

}

class Warrior : Character
{
    public Warrior(string characterType) : base(characterType)
    {
    }

    public override int DamagePoints(Character target) => target.Vulnerable() ? 10 : 6;
}

class Wizard : Character
{
    private bool _spellPrepared;

    public Wizard(string characterType) : base(characterType)
    {
        this._spellPrepared = false;
    }

    public override int DamagePoints(Character target) => this._spellPrepared ? 12 : 3;

    public void PrepareSpell() => this._spellPrepared = true;

    public override bool Vulnerable() => this._spellPrepared ? false : true;


}
WizardsAndWarriorsTests.cs(10,26): error CS7036: There is no argument given that corresponds to the required parameter 'characterType' of 'Wizard.Wizard(string)'
WizardsAndWarriorsTests.cs(18,27): error CS7036: There is no argument given that corresponds to the required parameter 'characterType' of 'Warrior.Warrior(string)'
WizardsAndWarriorsTests.cs(26,27): error CS7036: There is no argument given that corresponds to the required parameter 'characterType' of 'Warrior.Warrior(string)'
WizardsAndWarriorsTests.cs(34,26): error CS7036: There is no argument given that corresponds to the required parameter 'characterType' of 'Wizard.Wizard(string)'
WizardsAndWarriorsTests.cs(42,26): error CS7036: There is no argument given that corresponds to the required parameter 'characterType' of 'Wizard.Wizard(string)'
WizardsAndWarriorsTests.cs(51,26): error CS7036: There is no argument given that corresponds to the required parameter 'characterType' of 'Wizard.Wizard(string)'
WizardsAndWarriorsTests.cs(59,26): error CS7036: There is no argument given that corresponds to the required parameter 'characterType' of 'Wizard.Wizard(string)'
WizardsAndWarriorsTests.cs(60,27): error CS7036: There is no argument given that corresponds to the required parameter 'characterType' of 'Warrior.Warrior(string)'
WizardsAndWarriorsTests.cs(69,26): error CS7036: There is no argument given that corresponds to the required parameter 'characterType' of 'Wizard.Wizard(string)'
WizardsAndWarriorsTests.cs(70,31): error CS7036: There is no argument given that corresponds to the required parameter 'characterType' of 'Wizard.Wizard(string)'
WizardsAndWarriorsTests.cs(78,27): error CS7036: There is no argument given that corresponds to the required parameter 'characterType' of 'Warrior.Warrior(string)'
WizardsAndWarriorsTests.cs(79,26): error CS7036: There is no argument given that corresponds to the required parameter 'characterType' of 'Wizard.Wizard(string)'
WizardsAndWarriorsTests.cs(87,27): error CS7036: There is no argument given that corresponds to the required parameter 'characterType' of 'Warrior.Warrior(string)'
WizardsAndWarriorsTests.cs(88,26): error CS7036: There is no argument given that corresponds to the required parameter 'characterType' of 'Wizard.Wizard(string)'

@pavlejovanovic34 Just to be sure: did you modify the tests while working on your local machine?

I’m not familiar with C#, but I am investigating right now.

My best guess is that Wizard and Warrior are not supposed to take an argument. The errors are about such missing arguments to these constructors in the tests file.

Similar to @MatthijsBlom, I don’t know C#. However, the stub file has:


class Wizard : Character
{
    public Wizard() : base("TODO")
    {
    }
    ...
}

Note the function signature in the base doesn’t have an argument to the Wizard constructor. You’re probably not supposed to change that.

No, I didn’t, I tried without the arguments in Wizard and Warrior, but then I have the error that the argument is not given

No, even if I left it like that it causes error → argument not given

1 Like

@pavlejovanovic34 When I take your solution and remove the parameters from Warrior and Wizard I

  • no longer get the no argument given error in the tests file, but
  • do get a new error in the solution file: The name 'characterType' does not exist.

This latter error is easily remedied: just remove the characterType argument.

Then a new error appears (in the solution file): no argument given. However, this is not the same error as before: the errors in the tests file mentioned Warrior and Wizard, but this one is about Character.

So apparently you must provide base with a string argument. Which one? Unclear; I suggest just making something up (say, worrier and whiz) and seeing what happens.

To make sure that you have the right tests, run exercism download --exercise=wizards-and-warriors --track=csharp --force.

1 Like

Yes, I’ve just tried that with “Wizard” and “Warrior” and it works.
Thanks for the help!

The solution to the problem is to provide base with a string literal like “Wizard” in order to pass all tests.
Anyway, thank you all for the help!