Drop hier links of afbeeldingen om ze aan de editor toe te voegen.

Will you pass the skill check?

★☆☆

In a role playing game a player must perform a skill check if they want to succeed in an action they are attempting. Skill checks are performed with a twenty sided dice. The player has a skill (e.g. dexterity) and a modifier (to reflect any advantages or disadvantages in the situation). The skill and modifier are both integers. The skill, plus the dice roll, plus the modifier (which could be a negative number) must be more than a value decided by a "dungeon master" (the DM value) to succeed.

Dungeon master

Make

Write a program to output the result of a skill check. The user enters the skill value, the modifiers value and the number needed to pass. A roll of 1 is always a fail and a roll of 20 is always a success before skill and modifiers are taken into account. If the skill value, plus the modifiers is greater than equal to the number required to pass, the skill check is passed.

Success Criteria

Remember to add a comment before a subprogram, selection or iteration statement to explain its purpose.

Complete the subprogram called check_skill that:

  1. Returns one of five possible outcomes:
  2. Automatic pass: if skill plus modifiers is greater than or equal to the DM value plus 5. No dice is rolled.
  3. Critical fail: if the roll is a 1.
  4. Critical success: if the roll is a 20.
  5. Check passed: if the skill plus roll plus the modifier is greater or equal to the DM value.
  6. Check failed: if the ability plus roll plus the modifier is less than the DM value.

Complete the main program so that:

  1. The user can input the skill value as a positive integer.
  2. The user can input the modifier value as a positive or negative integer.
  3. The user can input the DM value.
  4. The outcome of the skill check is output.

Typical inputs and outputs from the program would be:

Enter the skill value:
15
Enter any modifiers:
2
Enter the number to pass:
12
Automatic pass
Enter the skill value:
6
Enter any modifiers:
-1
Enter the number to pass:
14
You rolled a 20
Critical success
Enter the skill value:
10
Enter any modifiers:
2
Enter the number to pass:
20
You rolled a 13
Check passed
🆘 If you're really stuck, use this Parsons code sorting exercise
Complete program
// Dungeon master program

using System;

class Submission
{
---
    // -------------------------
    // Globals
    // -------------------------
    static Random random_generator = new Random();


    // -------------------------
    // Subprograms
    //--------------------------
    // Function to return if a skill check is passed in DnD5e
---
    static string check_skill(int skill, int modifier, int dm_value)
    {
---
        // Check is always passed if skill is 5 or more than needed
        if (skill + modifier >= dm_value + 5)
        {
---
            return "Automatic pass";
---
        }
---
        else
        {
---
            int roll = random_generator.Next(1, 21);
            Console.WriteLine($"You rolled a {roll}");
---
            // A roll of 1 is a crit fail regardless of skill (house rule)
            if (roll == 1)
            {
---
                return "Critical fail";
---
            }
---
            // A roll of 20 is a crit success regardless of skill (house rule)
            else if (roll == 20)
            {
---
                return "Critical success";
---
            }
---
            else
            {
---
                // Check is passed if skill + dice + modifier is greater than or equal to the DM value
                if (skill + modifier + roll >= dm_value)
                {
---
                    return "Check passed";
---
                }
---
                else
                {
---
                    return "Check failed";
---
                }
---
            }
---
        }
---
    }
---


    // -------------------------
    // Main program
    // -------------------------
    public static void Main(string[] args)
    {
---
        Console.WriteLine("Enter the skill value:");
        int skill = Convert.ToInt32(Console.ReadLine());
        Console.WriteLine("Enter any modifiers:");
        int modifier = Convert.ToInt32(Console.ReadLine());
        Console.WriteLine("Enter the number to pass:");
        int dm_value = Convert.ToInt32(Console.ReadLine());
---
        string result = check_skill(skill, modifier, dm_value);
        Console.WriteLine(result);
---
    }
---
}