Beispiel #1
0
        public void Merge(CellItem[] items, Action moveAction, Action <int> counterAction, Action <string> messageAction)
        {
            if (this.IsEmpty)
            {
                return;
            }
            CellItem tempItem = null;

            for (int i = 0; i < items.Length; i++)
            {
                if (items[i].IsEmpty)
                {
                    tempItem = items[i];
                    continue;
                }
                else
                {
                    if (items[i].value == this.value)
                    {
                        items[i].Plus();
                        this.Value = 0;
                        counterAction(items[i].Value);
                        moveAction();
                        return;
                    }
                    break;
                }
            }
            if (tempItem != null)
            {
                tempItem.Value = this.value;
                this.Value     = 0;
                moveAction();
            }
        }
Beispiel #2
0
        private void SetRandomCell()
        {
            var      random = new Random();
            CellItem cell   = PlayField.Where(x => x.IsEmpty).OrderBy(x => random.Next()).First();

            if (cell != null)
            {
                cell.SetRandomValue();
            }
        }
Beispiel #3
0
        private void NewGame()
        {
            Count = 0;
            int k = 0;

            for (int y = 0; y < 4; y++)
            {
                for (int x = 0; x < 4; x++)
                {
                    PlayField[k] = new CellItem(x, y);
                    k++;
                }
            }
            SetRandomCell();
            SetRandomCell();
            OnPropertyChanged("PlayField");
        }