/// <summary>
        /// Constructor
        /// Initializes varables
        /// </summary>
        public BoardViewModel(ReversiBoard board, OptionsViewModel options)
        {
            this.Rows  = new List <BoardRowViewModel>();
            this.Board = board;
            this.game  = new ReversiGame(board.Width, board.Height);

            for (int f = 0; f < board.Height; f++)
            {
                var boardRow = new BoardRowViewModel(game);
                boardRow.SetWidth(board.Width);
                for (int s = 0; s < board.Width; s++)
                {
                    boardRow.Squares[s].Owner          = game.Board[new Vector2D(s, f)];
                    boardRow.Squares[s].PositionSquare = new Vector2D(s, f);
                }
                Rows.Add(boardRow);
            }
            this.CurrentPlayer = game.CurrentPlayer.ToString();
            this.BlackStones   = game.Board.CountStones(Player.BLACK);
            this.WhiteStones   = game.Board.CountStones(Player.WHITE);

            this.PlayMusic = new PlayMusicCommand(new MediaPlayer());
            this.Options   = options;
            this.EndGame   = new EndGameCommand(this, Options);

            this.BlackPlayer = Options.StartScreen.NameBlack;
            this.WhitePlayer = Options.StartScreen.NameWhite;
            SetWinner();
            this.Command = new PutStoneNewBoardCommand(this);
        }
Exemple #2
0
 public BoardSquareViewModel(BoardRowViewModel parent, int index)
 {
     this.Parent   = parent;
     this.Index1   = parent.Index;
     this.Index2   = index;
     this.Owner    = ReversiBoard[Position];
     this.PutStone = new PutStoneCommand(this);
 }
        public BoardViewModel(ReversiBoard board, OptionsViewModel options)

        {
            this.spel = new ReversiGame(board.Width, board.Height);
            this.Rows = new List <BoardRowViewModel>();

            this.bord          = board;
            this.black         = bord.CountStones(Player.BLACK);
            this.white         = bord.CountStones(Player.WHITE);
            this.currentPlayer = spel.CurrentPlayer;
            this.options       = options;

            //timer



            var timeService = ServiceLocator.Current.GetInstance <ITimeService>();

            _start = timeService.Now;

            _timer       = ServiceLocator.Current.GetInstance <ITimerService>();
            _timer.Tick += Timer_Tick;
            _timer.Start(new TimeSpan(0, 0, 0, 0, 100));

            //this.Milliseconds = modelTimer.Milliseconds;

            for (var i = 0; i < board.Height; i++)
            {
                var rij = new BoardRowViewModel(spel);

                for (var j = 0; j < board.Width; j++)
                {
                    rij.Squares[j].speler  = spel.Board[new Vector2D(j, i)]; //breedte hoogte, j breedte i hoogte
                    rij.Squares[j].Positie = new Vector2D(j, i);             // nu is er aan elke square een juiste positie toegekend
                }
                Rows.Add(rij);
            }

            this.Command    = new PutStoneCommand(this); // heeft een board nodig dus daarom de this we gaan deze direct meegeven
            this.commandend = new ToEndCommand(options, this);
        }
Exemple #4
0
        public BoardViewModel(ReversiBoard reversiBoard, OptionsViewModel options)
        {
            try
            {
                this.game = new ReversiGame(reversiBoard.Width, reversiBoard.Height);
                System.Diagnostics.Debug.WriteLine(reversiBoard.Width);
            }
            catch
            {
                this.game = new ReversiGame(6, 6);
            }
            this.Rows           = new List <BoardRowViewModel>();
            this.Command        = new PutStoneCommand(this);
            this.restartCommand = new RestartCommand(this);
            this.optionsView    = options;
            this.endGameCommand = new EndGameCommand(optionsView, this);

            _timer          = new DispatcherTimer(DispatcherPriority.Render);
            _timer.Interval = TimeSpan.FromSeconds(1);
            _timer.Tick    += (sender, args) =>
            {
                CurrentTime = DateTime.Now.ToLongTimeString();
            };
            _timer.Start();

            for (int i = 0; i < game.Board.Height; i++)
            {
                var boardRow = new BoardRowViewModel(game);
                for (int j = 0; j < game.Board.Width; j++)
                {
                    boardRow.Squares[j].Owner          = game.Board[new Vector2D(j, i)];
                    boardRow.Squares[j].SquarePosition = new Vector2D(j, i);
                }
                Rows.Add(boardRow);
            }
        }