Пример #1
0
        public MainWindowViewModel()
        {
            _client  = new HttpClient();
            _baseURL = "https://localhost:44351/api/MasterMind";
            _gameId  = -1;
            Attempts = new ObservableCollection <Attempt>();


            GetValidCharacters();
            CreateGameCommand  = new GeneralNoParameterCommand(CreateGame);
            AttemptGameCommand = new GeneralNoParameterCommand(() =>
            {
                ValueOne   = string.IsNullOrWhiteSpace(ValueOne) ? "A" : ValueOne.ToUpper();
                ValueTwo   = string.IsNullOrWhiteSpace(ValueTwo) ? "A" : ValueTwo.ToUpper();
                ValueThree = string.IsNullOrWhiteSpace(ValueThree) ? "A" : ValueThree.ToUpper();
                ValueFour  = string.IsNullOrWhiteSpace(ValueFour) ? "A" : ValueFour.ToUpper();
                OnPropertyChanged("ValueOne");
                OnPropertyChanged("ValueTwo");
                OnPropertyChanged("ValueThree");
                OnPropertyChanged("ValueFour");

                string completeAttempt = $"{_gameId}_{ValueOne}{ValueTwo}{ValueThree}{ValueFour}";
                AttemptGame(completeAttempt);
            });
        }
Пример #2
0
        public Func <string>[] GetFuncsWithOperationStringResult()
        {
            int    amount   = 50;
            string splitter = "=";
            Type   type     = typeof(T);

            Program.Center(amount, $"Type = {type.Name}", splitter);
            Func <string>[] actions = new Func <string>[]
            {
                () => GetStringBinaryOperator(ValueOne, ValueTwo, "+", new Func <dynamic, dynamic, dynamic>((c1, c2) => c1 + c2)),
                () => GetStringBinaryOperator(ValueOne, ValueTwo, "-", new Func <dynamic, dynamic, dynamic>((c1, c2) => c1 - c2)),
                () => GetStringBinaryOperator(ValueOne, ValueTwo, "*", new Func <dynamic, dynamic, dynamic>((c1, c2) => c1 * c2)),
                () => GetStringBinaryOperator(ValueOne, ValueTwo, "/", new Func <dynamic, dynamic, dynamic>((c1, c2) => c1 / c2)),
                () => GetStringBinaryOperator(ValueOne, ValueTwo, "%", new Func <dynamic, dynamic, dynamic>((c1, c2) => c1 % c2)),
                () => GetStringBinaryOperator(ValueOne, ValueTwo, "&", new Func <dynamic, dynamic, dynamic>((c1, c2) => c1 & c2)),
                () => GetStringBinaryOperator(ValueOne, ValueTwo, "|", new Func <dynamic, dynamic, dynamic>((c1, c2) => c1 | c2)),
                () => GetStringBinaryOperator(ValueOne, ValueTwo, "&&", new Func <dynamic, dynamic, dynamic>((c1, c2) => c1 && c2)),
                () => GetStringBinaryOperator(ValueOne, ValueTwo, "||", new Func <dynamic, dynamic, dynamic>((c1, c2) => c1 || c2)),
                () => GetStringBinaryOperator(ValueOne, ValueTwo, "??", new Func <dynamic, dynamic, dynamic>((c1, c2) => c1 ?? c2)),
                () => GetStringBinaryOperator(ValueOne, ValueTwo, "^", new Func <dynamic, dynamic, dynamic>((c1, c2) => c1 ^ c2)),
                () => GetStringBinaryOperator(ValueOne, ValueTwo, ">", new Func <dynamic, dynamic, dynamic>((c1, c2) => c1 > c2)),
                () => GetStringBinaryOperator(ValueOne, ValueTwo, "<", new Func <dynamic, dynamic, dynamic>((c1, c2) => c1 < c2)),
                () => GetStringBinaryOperator(ValueOne, ValueTwo, "<=", new Func <dynamic, dynamic, dynamic>((c1, c2) => c1 <= c2)),
                () => GetStringBinaryOperator(ValueOne, ValueTwo, ">=", new Func <dynamic, dynamic, dynamic>((c1, c2) => c1 >= c2)),
                () => GetStringBinaryOperator(ValueOne, ValueTwo, "==", new Func <dynamic, dynamic, dynamic>((c1, c2) => c1 == c2)),
                () => GetStringBinaryOperator(ValueOne, ValueTwo, "!=", new Func <dynamic, dynamic, dynamic>((c1, c2) => c1 != c2)),
                () => GetStringBinaryOperator(ValueOne, ValueTwo, ">>", new Func <dynamic, dynamic, dynamic>((c1, c2) => c1 >> c2)),
                () => GetStringBinaryOperator(ValueOne, ValueTwo, "<<", new Func <dynamic, dynamic, dynamic>((c1, c2) => c1 << c2)),
                () => GetStringBinaryOperator(ValueOne, ValueTwo, "=", new Func <dynamic, dynamic, dynamic>((c1, c2) => c1     = c2)),
                () => GetStringBinaryOperator(ValueOne, ValueTwo, "+=", new Func <dynamic, dynamic, dynamic>((c1, c2) => c1   += c2)),
                () => GetStringBinaryOperator(ValueOne, ValueTwo, "-=", new Func <dynamic, dynamic, dynamic>((c1, c2) => c1   -= c2)),
                () => GetStringBinaryOperator(ValueOne, ValueTwo, "*=", new Func <dynamic, dynamic, dynamic>((c1, c2) => c1   *= c2)),
                () => GetStringBinaryOperator(ValueOne, ValueTwo, "/=", new Func <dynamic, dynamic, dynamic>((c1, c2) => c1   /= c2)),
                () => GetStringBinaryOperator(ValueOne, ValueTwo, "%=", new Func <dynamic, dynamic, dynamic>((c1, c2) => c1   %= c2)),
                () => GetStringBinaryOperator(ValueOne, ValueTwo, ">>=", new Func <dynamic, dynamic, dynamic>((c1, c2) => c1 >>= c2)),
                () => GetStringBinaryOperator(ValueOne, ValueTwo, "<<=", new Func <dynamic, dynamic, dynamic>((c1, c2) => c1 <<= c2)),
                () => GetStringBinaryOperator(ValueOne, ValueTwo, "&=", new Func <dynamic, dynamic, dynamic>((c1, c2) => c1   &= c2)),
                () => GetStringBinaryOperator(ValueOne, ValueTwo, "|=", new Func <dynamic, dynamic, dynamic>((c1, c2) => c1   |= c2)),
                () => GetStringBinaryOperator(ValueOne, ValueTwo, "??=", new Func <dynamic, dynamic, dynamic>((c1, c2) => c1 ??= c2)),
                () => GetStringTernary(ValueOne, ValueTwo),
                () => GetStringUnaryOperator(ValueOne, "~", new Func <dynamic, dynamic>((c1) => ~c1)),
                () => GetStringUnaryOperator(ValueOne, "!", new Func <dynamic, dynamic>((c1) => !c1)),
                () => GetStringUnaryOperator(ValueOne, "++", new Func <dynamic, dynamic>((c1) => ++ c1)),
                () => GetStringUnaryOperator(ValueOne, "++", new Func <dynamic, dynamic>((c1) => c1++), IsPostFix: true),
                () => GetStringUnaryOperator(ValueOne, "--", new Func <dynamic, dynamic>((c1) => -- c1)),
                () => GetStringUnaryOperator(ValueOne, "--", new Func <dynamic, dynamic>((c1) => c1--), IsPostFix: true),
                () => $"default(T) = {default(T)}",
                () => $"GetType() = {ValueOne.GetType()}",
                () => $"c1 is dynamic = {ValueOne is dynamic}",
                () => $"c2 is object = {ValueOne is object}",
                () => $"c2 is int = {ValueOne is int}",
                () => $"c1 as object = {ValueOne as object ?? "Not Succesfull"}",
            };
            return(actions);
        }