-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathInputHandler.cs
More file actions
36 lines (31 loc) · 974 Bytes
/
InputHandler.cs
File metadata and controls
36 lines (31 loc) · 974 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
using Command.Commands;
using System;
using System.Collections.Generic;
namespace Command
{
public class InputHandler
{
private Stack<ICommand> _commandHistory = new Stack<ICommand>();
public void ExecuteCommand(ICommand command)
{
if (command == null)
{
Console.WriteLine("Ошибка: команда не может быть null");
return;
}
command.Execute();
_commandHistory.Push(command);
}
public void UndoLastCommand()
{
if (_commandHistory.Count == 0)
{
Console.WriteLine("\n> НЕЧЕГО ОТМЕНЯТЬ");
return;
}
Console.WriteLine("\n> ОТМЕНА последнего действия");
var command = _commandHistory.Pop();
command.Undo();
}
}
}