Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using Reversi.Cells;
- using Reversi.Domain;
- using System.Windows.Input;
- using System.Windows.Media;
- namespace ReversiGUI.ViewModels
- {
- class TileViewModel
- {
- private readonly ISquare square;
- private readonly ICommand placeStoneCommand;
- private readonly Game game;
- private readonly ICell<String> colorCell;
- public TileViewModel(ISquare square, Game game)
- {
- this.square = square;
- this.game = game;
- placeStoneCommand = new PlaceStoneCommando(this);
- colorCell = Cell.Derived(square.Owner, square.IsValidMove, DeriveKleur);
- }
- public ICell<String> ColorCell
- {
- get { return colorCell; }
- }
- private String DeriveKleur(Player owner, bool isValidMove)
- {
- if ((square.Owner.Value) == null)
- {
- if (square.IsValidMove.Value)
- {
- return "ValidMove";
- }
- else
- {
- return "NoTile";
- }
- }
- else
- {
- if ((square.Owner.Value) == Player.ONE)
- {
- return "PlayerOne";
- }
- else
- {
- return "PlayerTwo";
- }
- }
- }
- public ICell<bool> IsValidMove
- {
- get
- {
- return square.IsValidMove;
- }
- }
- public void PlaceStone()
- {
- if (square.IsValidMove.Value)
- {
- square.PlaceStone();
- }
- }
- public ICommand PlaceStoneCommand
- {
- get
- {
- return placeStoneCommand;
- }
- }
- private class PlaceStoneCommando : ICommand
- {
- private readonly TileViewModel model;
- public PlaceStoneCommando(TileViewModel model)
- {
- this.model = model;
- model.IsValidMove.PropertyChanged += IsValidMove_PropertyChanged;
- }
- void IsValidMove_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
- {
- if (CanExecuteChanged != null)
- CanExecuteChanged(this, new EventArgs());
- }
- public bool CanExecute(object parameter)
- {
- return model.IsValidMove.Value;
- //return true;
- }
- public event EventHandler CanExecuteChanged;
- public void Execute(object parameter)
- {
- model.PlaceStone();
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement