-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathDrawer.cs
More file actions
171 lines (160 loc) · 5.24 KB
/
Drawer.cs
File metadata and controls
171 lines (160 loc) · 5.24 KB
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace CodePainterApp
{
public enum DIRECTION { DOWN = 1 , RIGHT , UP , LEFT };
public partial class Drawer : UserControl
{
public Panel Arena { set; get; }
private Graphics Graphics = null;
private DrawedPointsTable DrawedPointsTable = null;
private int ArenaBoxWidth { set; get; }
private int ArenaBoxHeight { set; get; }
private int ArenaWidth { set; get; }
private int ArenaHeight { set; get; }
private DIRECTION Direction { set; get; }
private int X { set; get; }
private int Y { set; get; }
private bool Draw { set; get; } = true;
private Color Color = Color.White;
const int WIDTH = 20;
const int HEIGHT = 5;
const int HIGH_LOCATION = 15;
const int LOW_LOCATION = 0;
private void HideAllDirectionPCts()
{
pctDown.Hide();
pctUp.Hide();
pctRight.Hide();
pctLeft.Hide();
}
public void TurnRight()
{
HideAllDirectionPCts();
pctRight.Show();
Direction = DIRECTION.RIGHT;
}
public void TurnDown()
{
HideAllDirectionPCts();
pctDown.Show();
Direction = DIRECTION.DOWN;
}
public void TurnLeft()
{
HideAllDirectionPCts();
pctLeft.Show();
Direction = DIRECTION.LEFT;
}
public void TurnUp()
{
HideAllDirectionPCts();
pctUp.Show();
Direction = DIRECTION.UP;
}
public void MoveDrawer()
{
DrawedPoint dp = null;
switch (Direction)
{
case DIRECTION.DOWN:
int newTopDown = this.Top + 20;
if ((newTopDown + 20) <= ArenaHeight)
{
dp = CreateDrawedPoint();
if (this.Draw)
{
DrawedPointsTable[this.X, this.Y] = dp;
}
this.Top = newTopDown;
this.Y++;
}
break;
case DIRECTION.RIGHT:
int newLeftRight = this.Left + 20;
if ((newLeftRight + ArenaBoxWidth) <= ArenaWidth)
{
dp = CreateDrawedPoint();
if (this.Draw)
{
DrawedPointsTable[this.X, this.Y] = dp;
}
this.Left = newLeftRight;
this.X++;
}
break;
case DIRECTION.UP:
int newTopUp = this.Top - 20;
if (newTopUp >= 0)
{
dp = CreateDrawedPoint();
if (this.Draw)
{
DrawedPointsTable[this.X, this.Y] = dp;
}
this.Top = newTopUp;
this.Y--;
}
break;
case DIRECTION.LEFT:
int newLeftLeft = this.Left - 20;
if (newLeftLeft >= 0)
{
dp = CreateDrawedPoint();
if (this.Draw)
{
DrawedPointsTable[this.X, this.Y] = dp;
}
this.Left = newLeftLeft;
this.X--;
}
break;
}
if (dp != null)
{
if (this.Draw)
{
dp.Draw(Graphics);
Application.DoEvents();
}
}
}
public void EnableDrawing()
{
Draw = true;
}
public void DisableDrawing()
{
Draw = false;
}
public void ChangeColor(Color color)
{
this.Color = color;
}
private DrawedPoint CreateDrawedPoint()
{
return new DrawedPoint(new Point(this.Left +1, this.Top+1), this.Color, new Size(this.ArenaBoxWidth-1, this.ArenaBoxHeight-1));
}
public Drawer()
{
InitializeComponent();
Direction = DIRECTION.DOWN;
}
public void InitializeDrawer(Panel arena , DrawedPointsTable drawedPointsTable, int arenaBoxWidth, int arenaBoxHeight, int arenaWidth,int arenaHeight)
{
Arena = arena;
Graphics = arena.CreateGraphics();
DrawedPointsTable = drawedPointsTable;
ArenaBoxWidth = arenaBoxWidth;
ArenaBoxHeight= arenaBoxHeight;
ArenaWidth = arenaWidth;
ArenaHeight = arenaHeight;
}
}
}