Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using ReactiveUI;
- using System;
- using System.Collections.Generic;
- using MeksMathGame.Models;
- using System.Reactive.Linq;
- using System.Linq;
- namespace MeksMathGame.ViewModels;
- public class HomeScreenViewModel : ViewModelBase
- {
- public string? _information;
- public string? _selectedDiff;
- public string? _maxQues;
- public List<string?>? _difficulties;
- public List<string?>? _numberRange;
- public HomeScreenViewModel()
- {
- List<string> info = new()
- {
- "Welcome to the Math Game! There are 5 buttons on the right side.",
- "To play a game, select a difficulty and the number of questions you",
- "want to answer below, and then click a game button to the right.",
- "To go back to select another user, click the Back button. To view",
- "all the games you've played, click the Previous Games button",
- "\n\nEasy => Number Ranges Between 0 and 300",
- "\nMedium => Number Ranges Between 0 and 600",
- "\nHard => Number Ranges Between 0 and 900"
- };
- Information = string.Join(" ", info);
- Difficulties = new() { "Select One", "Easy", "Medium", "Hard" };
- var numbers = Enumerable.Range(1, 25);
- NumberRange = new() { "Select One" };
- NumberRange.AddRange(numbers.Select(x => x.ToString()));
- SelectedDiff = Difficulties[0];
- MaxQues = NumberRange[0];
- IObservable<bool> numQuesOk = this.WhenAnyValue(
- x => x.MaxQues,
- x => x != "Select One");
- IObservable<bool> diffOk = this.WhenAnyValue(
- x => x.SelectedDiff,
- x => x != "SelectOne");
- IObservable<bool> okEnabled = numQuesOk
- .Concat(diffOk);
- Play = ReactiveCommand.Create<string, Game>(gameType => PlayGame(gameType), okEnabled);
- PreviousGames = ReactiveCommand.Create<string, Game>(gameType => ShowPreviousGames(gameType));
- BackButton = ReactiveCommand.Create<string, Game>(gameType => SendBackButton(gameType));
- }
- public Game PlayGame(string gameType)
- {
- int? totalQues = Convert.ToInt32(MaxQues);
- return new Game
- {
- TotalQuestions = totalQues,
- Difficulty = SelectedDiff,
- GameType = gameType
- };
- }
- public Game ShowPreviousGames(string gameType)
- {
- return new Game { GameType = "Previous Games" };
- }
- public Game SendBackButton(string gameType)
- {
- return new Game { GameType = "Back Button" };
- }
- #region Getters/Setters
- public string? Information
- {
- get => _information;
- set => this.RaiseAndSetIfChanged(ref _information, value);
- }
- public string? SelectedDiff
- {
- get => _selectedDiff;
- set => this.RaiseAndSetIfChanged(ref _selectedDiff, value);
- }
- public string? MaxQues
- {
- get => _maxQues;
- set => this.RaiseAndSetIfChanged(ref _maxQues, value);
- }
- public List<string?>? Difficulties
- {
- get => _difficulties;
- set => this.RaiseAndSetIfChanged(ref _difficulties, value);
- }
- public List<string?>? NumberRange
- {
- get => _numberRange;
- set => this.RaiseAndSetIfChanged(ref _numberRange, value);
- }
- #endregion
- public ReactiveCommand<string, Game> Play { get; }
- public ReactiveCommand<string, Game> PreviousGames { get; }
- public ReactiveCommand<string, Game> BackButton { get; }
- }
Advertisement
Add Comment
Please, Sign In to add comment