Skip to content

Commit

Permalink
Добавьте файлы проекта.
Browse files Browse the repository at this point in the history
  • Loading branch information
yudinikita committed Jul 10, 2019
1 parent fd6e840 commit 25731b0
Show file tree
Hide file tree
Showing 62 changed files with 17,800 additions and 0 deletions.
112 changes: 112 additions & 0 deletions Tetris-OOP/Data/Engine/Commands/Command.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
using GameTetris;
using Tetris.Data.GUI;

namespace Engine.Commands
{
/// <summary>Класс Команды объявляет метод для выполнения команд.</summary>
public abstract class Command
{
protected readonly PlayField _playField;
protected readonly Game _game;

protected Command(PlayField playField)
{
_playField = playField;
}

protected Command(Game game)
{
_game = game;
}

public abstract void Execute();
}

/// <summary>Класс инициализатор команд, отправляет запрос на команду.</summary>
public class Invoker
{
private Command _command;
/// <summary>Команда поступившая на выполнение.</summary>
public Command Command
{
set => _command = value;
}

/// <summary>Запуск команды.</summary>
public void Run()
{
_command?.Execute(); // если команда не пустая, то выполняется
_command = null; // после выполнения обнуляем команду
}
}

#region Команды движения и пауза
public class MoveLeft : Command
{
public MoveLeft(PlayField playField) : base(playField){ }

public override void Execute()
{
_playField.MoveLeft();
}
}

public class MoveRight : Command
{
public MoveRight(PlayField playField) : base(playField) { }

public override void Execute()
{
_playField.MoveRight();
}
}

public class MoveDown : Command
{
public MoveDown(PlayField playField) : base(playField) { }

public override void Execute()
{
_playField.MoveDown();
}
}

public class MoveDrop : Command
{
public MoveDrop(PlayField playField) : base(playField) { }

public override void Execute()
{
_playField.Drop();
}
}

public class MoveRotate : Command
{
public MoveRotate(PlayField playField) : base(playField) { }

public override void Execute()
{
_playField.RotateFigure();
}
}

public class MovePause : Command
{
public MovePause(Game game) : base(game) { }

public override void Execute()
{
// меняем значение на противоположное
_game.Paused = !_game.Paused;

// открываем форму с паузой
MenuPauseForm menu = new MenuPauseForm();
menu.ShowDialog();

// после закрытия меню - игра продолжается
_game.Paused = !_game.Paused;
}
}
#endregion
}
Loading

0 comments on commit 25731b0

Please sign in to comment.