Example #1
0
        public bool PutRandomValue()
        {
            MoveCount++;
            var cells = cellList.Where(i => i.Value == 0).ToList();

            if (cells.Count == 0)
            {
                return(false);
            }

            var index = rnd.Next(0, cells.Count);
            int value;

            if (MoveCount < 20)
            {
                value = 2;
            }
            else
            {
                var dice = rnd.Next(0, 10);
                value = dice == 0 ? 4 : 2;
            }
            var cell = cells[index];

            cell.Value = value;
            CellCreated?.Invoke(this, new CellCreatedEventArgs(new CellData(cell)));
            return(true);
        }
Example #2
0
        public void PutValue(int x, int y, int value)
        {
            var target = cellBoard[x, y];

            if (target.Value > 0)
            {
                var from = new CellData(target);
                target.Value = value;
                CellMoved?.Invoke(this, new CellMovedEventArgs(from, new CellData(target), null));
            }
            else
            {
                target.Value = value;
                CellCreated?.Invoke(this, new CellCreatedEventArgs(new CellData(target)));
            }
            SaveUndo();
        }
Example #3
0
        public void FillEmpltyPlaces()
        {
            for (var col = 0; col < SIZE; col++)
            {
                for (var row = 0; row < SIZE; row++)
                {
                    if (Grid[col, row] == null)
                    {
                        Grid[col, row] = new Cell
                        {
                            Type = GenerateType(),
                            Col  = col,
                            Row  = row
                        };

                        CellCreated.Invoke(null, Grid[col, row]);
                    }
                    ;
                }
            }
        }