Question

I am looking at somebodies code and I was wondering if someone could explain to me what I am looking at here.

    public static KillerInspectorScene Instance
    {
        get 
        {
            if (instance == null) {
                throw new InvalidProgramException();
            }
            return instance;
        }
    }

I haven't seen a method like this before, can someone tell me what I'm looking at? I think I understand the body of the method. Can anyone tell me what this is exactly so I can look it up further on google? I have something similar below I cant figure out either.

    public KillerInspectorScene.States GetKillerResultState(Game.KillerActions action)
    {
        if (action == Game.KillerActions.Disguise) {
            return KillerInspectorScene.States.Disguise;
        }
        else if (action == Game.KillerActions.Kill) {
            return KillerInspectorScene.States.Kill;
        }
        else if (action == Game.KillerActions.Shift) {
            return KillerInspectorScene.States.Shift;
        }
        return KillerInspectorScene.States.Null;
    }

Help would be GREATLY appreciated. I can't look up the name of something I don't know the name to. Thanks in advance!

Was it helpful?

Solution

  1. The first method you looking at is a validation:
    If somehow the KillerInspectorScene instance is nullified it means that an other method in the program made an invalid operation regarding the logic of the game and so it will throw an error.

  2. The second method you looking at is a choice according to an action being made, it seems that there are 3 options for a killer to react and that method is "digesting" those options.

    It receives the action of the killer and returns the scene state according to that action.

I suggest that you check who is calling the methods and in which occasions exactly to learn more of your code.

Good Luck.

OTHER TIPS

You have a public static getter on a static property called Instance. The instance field is initialized somewhere else. If it is not initialized the getter throws an exception. The Instance property is globally accessible in your program.

The second is a method and part of a instance of your class. Given an action it returns some sort of KillerInspectorScene state.

You are looking at a singleton pattern.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top