Advertisement
Guest User

Untitled

a guest
May 28th, 2016
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.77 KB | None | 0 0
  1. using System;
  2. using PiCross;
  3. using Cells;
  4. using System.Windows.Input;
  5.  
  6. namespace ViewModel
  7. {
  8.     public class SquareViewModel
  9.     {
  10.         private readonly IPlayablePuzzleSquare square;
  11.  
  12.         private readonly Left left;
  13.         private readonly Right right;
  14.  
  15.         public SquareViewModel(IPlayablePuzzleSquare square)
  16.         {
  17.             this.square = square;
  18.             left = new Left(this);
  19.             right = new Right(this);
  20.         }
  21.  
  22.         // Square
  23.         public Cell<Square> Contents
  24.         {
  25.             get
  26.             {
  27.                 return square.Contents;
  28.             }
  29.         }
  30.  
  31.         #region Click Commands
  32.         private class Left : ICommand
  33.         {
  34.             private readonly SquareViewModel vm;
  35.  
  36.             public Left(SquareViewModel vm)
  37.             {
  38.                 CanExecuteChanged += (a, b) => { };
  39.                 this.vm = vm;
  40.             }
  41.  
  42.             public event EventHandler CanExecuteChanged;
  43.  
  44.             public bool CanExecute(object parameter)
  45.             {
  46.                 return true;
  47.             }
  48.  
  49.             public void Execute(object parameter)
  50.             {
  51.                 if (vm.square.Contents.Value == Square.UNKNOWN || vm.square.Contents.Value == Square.EMPTY)
  52.                 {
  53.                     vm.square.Contents.Value = Square.FILLED;
  54.                 }
  55.                 else
  56.                 {
  57.                     if (vm.square.Contents.Value == Square.FILLED)
  58.                     {
  59.                         vm.square.Contents.Value = Square.UNKNOWN;
  60.                     }
  61.                 }
  62.             }
  63.         }
  64.         private class Right : ICommand
  65.         {
  66.             private readonly SquareViewModel vm;
  67.  
  68.             public Right(SquareViewModel vm)
  69.             {
  70.                 CanExecuteChanged += (a, b) => { };
  71.                 this.vm = vm;
  72.             }
  73.  
  74.             public event EventHandler CanExecuteChanged;
  75.  
  76.             public bool CanExecute(object parameter)
  77.             {
  78.                 return true;
  79.             }
  80.  
  81.             public void Execute(object parameter)
  82.             {
  83.                 if (vm.square.Contents.Value == Square.UNKNOWN || vm.square.Contents.Value == Square.FILLED)
  84.                 {
  85.                     vm.square.Contents.Value = Square.EMPTY;
  86.                 }
  87.                 else
  88.                 {
  89.                     if (vm.square.Contents.Value == Square.EMPTY)
  90.                     {
  91.                         vm.square.Contents.Value = Square.UNKNOWN;
  92.                     }
  93.                 }
  94.             }
  95.         }
  96.  
  97.         public ICommand LCC
  98.         {
  99.             get { return left; }
  100.         }
  101.  
  102.         public ICommand RCC
  103.         {
  104.             get { return right; }
  105.         }
  106.     }
  107.  
  108.     #endregion
  109. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement