Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using PiCross;
- using Cells;
- using System.Windows.Input;
- namespace ViewModel
- {
- public class SquareViewModel
- {
- private readonly IPlayablePuzzleSquare square;
- private readonly Left left;
- private readonly Right right;
- public SquareViewModel(IPlayablePuzzleSquare square)
- {
- this.square = square;
- left = new Left(this);
- right = new Right(this);
- }
- // Square
- public Cell<Square> Contents
- {
- get
- {
- return square.Contents;
- }
- }
- #region Click Commands
- private class Left : ICommand
- {
- private readonly SquareViewModel vm;
- public Left(SquareViewModel vm)
- {
- CanExecuteChanged += (a, b) => { };
- this.vm = vm;
- }
- public event EventHandler CanExecuteChanged;
- public bool CanExecute(object parameter)
- {
- return true;
- }
- public void Execute(object parameter)
- {
- if (vm.square.Contents.Value == Square.UNKNOWN || vm.square.Contents.Value == Square.EMPTY)
- {
- vm.square.Contents.Value = Square.FILLED;
- }
- else
- {
- if (vm.square.Contents.Value == Square.FILLED)
- {
- vm.square.Contents.Value = Square.UNKNOWN;
- }
- }
- }
- }
- private class Right : ICommand
- {
- private readonly SquareViewModel vm;
- public Right(SquareViewModel vm)
- {
- CanExecuteChanged += (a, b) => { };
- this.vm = vm;
- }
- public event EventHandler CanExecuteChanged;
- public bool CanExecute(object parameter)
- {
- return true;
- }
- public void Execute(object parameter)
- {
- if (vm.square.Contents.Value == Square.UNKNOWN || vm.square.Contents.Value == Square.FILLED)
- {
- vm.square.Contents.Value = Square.EMPTY;
- }
- else
- {
- if (vm.square.Contents.Value == Square.EMPTY)
- {
- vm.square.Contents.Value = Square.UNKNOWN;
- }
- }
- }
- }
- public ICommand LCC
- {
- get { return left; }
- }
- public ICommand RCC
- {
- get { return right; }
- }
- }
- #endregion
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement