Esempio n. 1
0
        public static ICodemaker CreateCodemaker(IGameOptions options, ICodemaker lastCodemaker)
        {
            var type = ShellEx.PromptPlayerType("Codemaker", lastCodemaker?.Type);

            ShellEx.WriteKeyValue("Codemaker", type.ToString().ToLower());

            switch (type)
            {
            case PlayerType.Human:
                return(new HumanCodemaker(options));

            case PlayerType.Computer:
                PegPattern code;
                var        codeType = Shell.PromptEnum <ComputerCodeType>("Choose secret code", ComputerCodeType.Random);
                switch (codeType)
                {
                case ComputerCodeType.Random:
                    code = options.Palette.GetRandomPattern(options);
                    break;

                case ComputerCodeType.Custom:
                    code = ShellEx.PromptPegPattern("Enter secret code", options);
                    break;

                default:
                    throw new Exception($"Unknown code type");
                }
                ShellEx.WriteKeyValue("Code", codeType.ToString().ToLower());
                return(new ComputerCodemaker(options, code));

            default: throw new Exception($"Unknown player type: {type}");
            }
        }
Esempio n. 2
0
        public static ICodebreaker CreateCodebreaker(IGameOptions options, ICodebreaker lastCodebreaker)
        {
            var type = ShellEx.PromptPlayerType("Codebreaker", lastCodebreaker?.Type);

            ShellEx.WriteKeyValue("Codebreaker", type.ToString().ToLower());

            switch (type)
            {
            case PlayerType.Human:
                return(new HumanCodebreaker(options));

            case PlayerType.Computer:
                PegPattern initialGuess;
                var        initialGuessType = Shell.PromptEnum <ComputerInitialGuessType>("Choose initial guess", ComputerInitialGuessType.Default);
                switch (initialGuessType)
                {
                case ComputerInitialGuessType.Default:
                    initialGuess = null;
                    break;

                case ComputerInitialGuessType.Random:
                    initialGuess = options.Palette.GetRandomPattern(options);
                    break;

                case ComputerInitialGuessType.Custom:
                    initialGuess = ShellEx.PromptPegPattern("Enter initial guess", options);
                    break;

                default:
                    throw new Exception($"Unknown initial guess type");
                }
                ShellEx.WriteKeyValue("Initial guess", initialGuessType.ToString().ToLower());
                return(new ComputerCodebreaker(options, initialGuess));

            default: throw new Exception($"Unknown player type: {type}");
            }
        }
Esempio n. 3
0
 public static PlayerType PromptPlayerType(string playerTypeName, PlayerType?defaultPlayerType = null)
 {
     return(Shell.PromptEnum($"{playerTypeName} player type", defaultPlayerType));
 }