/
RemoteControl.cs
51 lines (47 loc) · 1.39 KB
/
RemoteControl.cs
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace CommandPattern
{
class RemoteControl
{
command[] onCommands;
command[] offCommands;
public RemoteControl(){
onCommands= new command[7];
offCommands= new command[7];
command noCommand=new NoCommand();
for (int i = 0;i<7;i++){
onCommands[i]=noCommand;
offCommands[i] = noCommand;
}
}
public void setCommand(int slot, command onCommand,command offCommand)
{
onCommands[slot] = onCommand;
offCommands[slot] = offCommand;
}
public void onButtonWasPushed(int slot)
{
if(onCommands[slot] !=null)
onCommands[slot].execute();
}
public void offButtonWasPushed(int slot)
{
offCommands[slot].execute();
}
public String toString()
{
StringBuilder stringBuff = new StringBuilder();
stringBuff.Append("\n------ Remote Control -------\n");
for (int i = 0; i < onCommands.Length; i++)
{
stringBuff.Append("[slot" + i + "] " + onCommands[i].ToString()
+" "+offCommands[i].ToString()+"\n");
}
return stringBuff.ToString();
}
}
}