コード例 #1
0
 /// <summary>
 /// Конструкотор по умолчанию
 /// </summary>
 private GameField()
 {
     InitRandom();
     InitField();
     Shuffle();
     FieldChanged?.Invoke();
 }
コード例 #2
0
        public void Translate(Time delta)
        {
            if (GeneralDuration.Value == null)
            {
                return;
            }

            if (delta == Time.Zero)
            {
                return;
            }

            foreach (var item in items)
            {
                var newduration = item.Duration + delta;

                ItemMoved?.Invoke(item.Duration, newduration, item.Value);

                item.Duration = newduration;
            }

            elements_start.Translate(delta);
            elements_end.Translate(delta);

            FieldChanged?.Invoke(GeneralDuration.Value | (GeneralDuration.Value + delta));
            GeneralDuration.Value += delta;
        }
コード例 #3
0
ファイル: Game.cs プロジェクト: JustickDM/TetrisConsole
        /// <summary>
        /// Функция опускания фигуры на единицу и проверка упала или еще летит
        /// </summary>
        public void MakeIteration()
        {
            IsEndGame = GetIsEndGame();

            if (!IsEndGame)
            {
                if (Field.IsCanSetUpFigure(_figure, _x, _y + 1))
                {
                    Field.SetUp(_figure, _y, _x, CellType.Empty);
                    _y++;
                    Field.SetUp(_figure, _y, _x, CellType.Figure);
                }
                else
                {
                    Field.SetUp(_figure, _y, _x, CellType.Border);
                    _timer.Interval = _speed;

                    PlayerScore += Field.Remove();

                    _figure = NextFigure;

                    _x = (Field.M - _figure.M) / 2;
                    _y = 1;

                    NextFigure = FigureFactory.Create();
                }

                FieldChanged?.Invoke();
            }
        }
コード例 #4
0
        public void RemoveUnique(Duration duration)
        {
            var durateditem = items.Single(item => item.Duration == duration);

            elements_start.Remove(durateditem, duration.Start);
            elements_end.Remove(durateditem, duration.End);

            items.Remove(durateditem);

            FieldChanged?.Invoke(duration);

            if (GeneralDuration.Value == duration)
            {
                GeneralDuration_recalc();
            }
            else if (duration.Contains(GeneralDuration.Value.End))
            {
                GeneralDuration_recalc_end();
            }
            else if (duration.Contains(GeneralDuration.Value.Start))
            {
                GeneralDuration_recalc_start();
            }

            ItemRemoved?.Invoke(duration, durateditem.Value);
        }
コード例 #5
0
        public void Remove(IDuratedItem <T> durateditem)
        {
            var duration         = durateditem.Duration;
            var durateditem_real =
                durateditem as DuratedItem <T> ??
                items.FirstOrDefault(item => item.Value.Equals(durateditem.Value) && item.Duration == duration);

            elements_start.Remove(durateditem_real, duration.Start);
            elements_end.Remove(durateditem_real, duration.End);

            items.Remove(durateditem_real);

            FieldChanged?.Invoke(duration);

            if (GeneralDuration.Value == duration)
            {
                GeneralDuration_recalc();
            }
            else if (duration.Contains(GeneralDuration.Value.End))
            {
                GeneralDuration_recalc_end();
            }
            else if (duration.Contains(GeneralDuration.Value.Start))
            {
                GeneralDuration_recalc_start();
            }

            ItemRemoved?.Invoke(duration, durateditem.Value);
        }
コード例 #6
0
        /// <summary>
        /// Метод замены элемента с координатами I, J
        /// c элементом с координатами newI, newJ
        /// </summary>
        private void Swap(int parI, int parJ, int parNewI, int parNewJ)
        {
            int temp = _field[parNewI, parNewJ];

            _field[parNewI, parNewJ] = _field[parI, parJ];
            _field[parI, parJ]       = temp;
            FieldChanged?.Invoke();
        }
コード例 #7
0
ファイル: Game.cs プロジェクト: JustickDM/TetrisConsole
        /// <summary>
        /// Действие пользователя на очередной итерации
        /// </summary>
        /// <param name="position">Тип действия</param>
        public void Action(ActionType action)
        {
            switch (action)
            {
            case ActionType.Down:
                _timer.Interval = DownSpeed;
                break;

            case ActionType.Left:
                if (Field.IsCanSetUpFigure(_figure, _x - 1, _y))
                {
                    Field.SetUp(_figure, _y, _x, CellType.Empty);
                    _x--;
                    Field.SetUp(_figure, _y, _x, CellType.Figure);
                }
                break;

            case ActionType.Right:
                if (Field.IsCanSetUpFigure(_figure, _x + 1, _y))
                {
                    Field.SetUp(_figure, _y, _x, CellType.Empty);
                    _x++;
                    Field.SetUp(_figure, _y, _x, CellType.Figure);
                }
                break;

            case ActionType.TurnRight:
                Field.SetUp(_figure, _y, _x, CellType.Empty);
                _figure.Turn(true);
                if (Field.IsCanSetUpFigure(_figure, _x, _y))
                {
                    Field.SetUp(_figure, _y, _x, CellType.Figure);
                }
                else
                {
                    _figure.Turn(false);
                    Field.SetUp(_figure, _y, _x, CellType.Figure);
                }
                break;

            case ActionType.TurnLeft:
                Field.SetUp(_figure, _y, _x, CellType.Empty);
                _figure.Turn(false);
                if (Field.IsCanSetUpFigure(_figure, _x, _y))
                {
                    Field.SetUp(_figure, _y, _x, CellType.Figure);
                }
                else
                {
                    _figure.Turn(true);
                    Field.SetUp(_figure, _y, _x, CellType.Figure);
                }
                break;
            }

            FieldChanged?.Invoke();
        }
コード例 #8
0
 void addRemoveButtons_AddButtonClicked(Widget source, EventArgs e)
 {
     if (currentFieldChangedCallback != null)
     {
         currentFieldChangedCallback.Invoke(objectEditor.EditInterface, currentEditingObject);
     }
     if (FieldChanged != null)
     {
         FieldChanged.Invoke(objectEditor.EditInterface, null);
     }
 }
コード例 #9
0
 void propTable_EditablePropertyValueChanged(EditableProperty var)
 {
     if (currentFieldChangedCallback != null)
     {
         currentFieldChangedCallback.Invoke(objectEditor.EditInterface, currentEditingObject);
     }
     if (FieldChanged != null)
     {
         FieldChanged.Invoke(objectEditor.EditInterface, null);
     }
 }
コード例 #10
0
ファイル: Filter.razor.cs プロジェクト: weiplanet/MudBlazor
        internal async Task FieldChangedAsync(string field)
        {
            Field = field;
            var operators = FilterOperator.GetOperatorByDataType(dataType);

            Operator = operators.FirstOrDefault();
            Value    = null;
            await OperatorChanged.InvokeAsync(Operator);

            await ValueChanged.InvokeAsync(Value);

            await FieldChanged.InvokeAsync(Field);
        }
コード例 #11
0
        /// <summary>
        /// Метод учета изменений в ячейке игрового поля
        /// </summary>
        /// <param name="Cell">Ячейка в которой произошли изменения</param>
        /// <param name="Changies">Вид изменений</param>
        private void CellChanged(Cell Cell, CellChangies Changies)
        {
            switch (Changies)
            {
            case CellChangies.OneWay:

                if (Cell.Marked)
                {
                    MarkedCells.Add(FieldMatrix[Cell.X, Cell.Z].Point(false, true));
                    FieldChanged?.Invoke(FieldMatrix, MarkedCells);
                }
                else if (Cell.Blocked)
                {
                    ChangeMatrix(FieldMatrix[Cell.X, Cell.Z].Point(true, false));
                    FieldChanged?.Invoke(FieldMatrix, null);
                }
                else
                {
                    ChangeMatrix(FieldMatrix[Cell.X, Cell.Z].Point(false, false));
                    if (MarkedCells.Contains(FieldMatrix[Cell.X, Cell.Z]))
                    {
                        MarkedCells.Remove(FieldMatrix[Cell.X, Cell.Z]);
                    }
                    FieldChanged?.Invoke(FieldMatrix, MarkedCells);
                }

                break;

            case CellChangies.TwoWays:

                if (Cell.Marked)
                {
                    MarkedCells.Add(FieldMatrix[Cell.X, Cell.Z].Point(false, true));
                    ChangeMatrix(FieldMatrix[Cell.X, Cell.Z]);

                    FieldChanged?.Invoke(FieldMatrix, MarkedCells);
                }
                else
                {
                    MarkedCells.Remove(FieldMatrix[Cell.X, Cell.Z].Point(true, false));
                    ChangeMatrix(FieldMatrix[Cell.X, Cell.Z]);

                    FieldChanged?.Invoke(FieldMatrix, MarkedCells);
                }

                break;
            }
        }
コード例 #12
0
ファイル: Game.cs プロジェクト: JustickDM/TetrisConsole
        /// <summary>
        /// Перезапуск игры
        /// </summary>
        public void Restart()
        {
            Field.Clear();

            _figure    = FigureFactory.Create();
            NextFigure = FigureFactory.Create();

            _x = (Field.M - _figure.M) / 2;
            _y = 1;

            PlayerScore = 0;

            FieldChanged?.Invoke();

            _timer.Start();
        }
コード例 #13
0
        public void StepGame(int x, int y)
        {
            int place = _tableSize - 1;

            while (place >= 0 && _tableMatrix[place, y] != 0)
            {
                --place;
            }
            if (place != -1)
            {
                _tableMatrix[place, y] = _currentPlayer;
                ++_placed;
                CheckGame(place, y);
                _currentPlayer = (_currentPlayer % 2) + 1;
                FieldChanged?.Invoke(this, new FieldChangedEventArgs(place, y));
            }
        }
コード例 #14
0
        public void Add(T item, Duration duration)
        {
            var durateditem =
                new DuratedItem <T> {
                Value    = item,
                Duration = duration
            };

            elements_start.Add(durateditem, duration.Start);
            elements_end.Add(durateditem, duration.End);
            items.Add(durateditem);

            FieldChanged?.Invoke(duration);
            GeneralDuration.Value |= duration;

            ItemAdded?.Invoke(duration, item);
        }
コード例 #15
0
 public void CheckGame(int x, int y)
 {
     if (_placed == _tableSize * _tableSize)
     {
         FieldChanged?.Invoke(this, new FieldChangedEventArgs(x, y));
         GameOver?.Invoke(this, new GameOverEventArgs(0, "", new List <Coordinate>()));
     }
     else
     {
         List <Coordinate> c;
         string            winDir = CheckFour(x, y, out c); //hor, ltop, rtop
         c.Add(new Coordinate(x, y));
         if (winDir != "")
         {
             winningCoords = c;
             FieldChanged?.Invoke(this, new FieldChangedEventArgs(x, y));
             GameOver?.Invoke(this, new GameOverEventArgs(_currentPlayer, winDir, winningCoords));
         }
     }
 }
コード例 #16
0
 /// <summary>Raises the <see cref="E:FieldChanged"/> event.</summary>
 /// <param name="e">The <see cref="IPAddressFieldChangedEventArgs"/> instance containing the event data.</param>
 protected void OnFieldChanged(IPAddressFieldChangedEventArgs e)
 {
     FieldChanged?.Invoke(this, e);
 }
コード例 #17
0
 public DrawableChangedEventArgs(object objectChanged, FieldChanged what) : base(objectChanged)
 {
     _what = what;
 }
コード例 #18
0
        public MelodyTrack(
            StorageObjectID storageobjectID,
            EditorFile file
            ) :
            base(
                storageobjectID,
                file,
                null     //TODO
                )
        {
            obj = this.Object();

            notes_field.GeneralDuration.AfterChange += GeneralDuration_AfterChange;

            next_noteID_obj = obj.GetOrMake("next_noteID");
            listener_nextnodeID_contentsset =
                next_noteID_obj.CreateListen(IOEvent.ObjectContentsSet, () => {
                if (!int.TryParse(next_noteID_obj.ReadAllString(), out next_noteID))
                {
                    next_noteID_obj.WriteAllString("0");
                }
            });

            notes_obj            = obj.GetOrMake("notes");
            listener_notes_added =
                notes_obj.CreateListen(IOEvent.ChildAdded, (key, new_note_objID) => {
                var noteID       = new NoteID(int.Parse(key));
                var new_note_obj = notes_obj.Graph[new_note_objID];
                var contents     = new_note_obj.ReadAllString().Split('\n');
                var duration     = CodeTools.ReadDuration(contents[0]);
                var tone         = new SemiTone(int.Parse(contents[1]));

                var note =
                    new Note(
                        noteID,
                        duration,
                        tone
                        );

                notes_field.Add(noteID, duration);
                notes_lookup.Add(noteID, note);
                FieldChanged?.Invoke(duration);
            });

            listener_notes_changed =
                notes_obj.CreateListen(IOEvent.ChildContentsSet, (key, changed_note_objID) => {
                var noteID       = new NoteID(int.Parse(key));
                var new_note_obj = notes_obj.Graph[changed_note_objID];
                var contents     = new_note_obj.ReadAllString().Split('\n');
                var duration     = CodeTools.ReadDuration(contents[0]);
                var tone         = new SemiTone(int.Parse(contents[1]));

                Note oldnote;
                if (notes_lookup.TryGetValue(noteID, out oldnote))
                {
                    if (oldnote.Duration != duration ||
                        oldnote.Tone != tone)
                    {
                        var newnote =
                            new Note(
                                noteID,
                                duration,
                                tone
                                );

                        var oldnoteduration =
                            oldnote.Duration;

                        notes_lookup[noteID] = newnote;
                        notes_field.Move(noteID, oldnoteduration, duration);
                        FieldChanged?.Invoke(oldnoteduration.Union(duration));
                    }
                }
            });

            listener_notes_removed =
                notes_obj.CreateListen(IOEvent.ChildRemoved, (key, old_note_objID) => {
                var noteID = new NoteID(int.Parse(key));

                var oldnote = notes_lookup[noteID];

                notes_field.Remove(noteID, oldnote.Duration);
                notes_lookup.Remove(noteID);
                FieldChanged?.Invoke(oldnote.Duration);
            });
        }
コード例 #19
0
ファイル: GuerillaControl.cs プロジェクト: MikeMatt16/Abide
 protected virtual void OnFieldChanged(EventArgs e)
 {
     nameLabel.Text = field?.Name ?? string.Empty;
     FieldChanged?.Invoke(this, e);
 }
コード例 #20
0
 private void OnFieldChanged(EventArgs e) => FieldChanged?.Invoke(this, e);
コード例 #21
0
 protected virtual void OnFieldChanged()
 {
     FieldChanged?.Invoke(this, null);
 }