-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSector.cs
More file actions
144 lines (128 loc) · 4.13 KB
/
Sector.cs
File metadata and controls
144 lines (128 loc) · 4.13 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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Drawing;
using System.Windows.Forms;
using System.IO;
namespace pentago
{
public class Sector : Control
{
public static readonly int StartTop = 20;
public static readonly int StartLeft = StartTop + GameField.MenuWidth;
public static readonly int Gap = 199;
public static readonly int Side = 189;
public static readonly int SectorWidth = 3;
private int BackgroundIndex;
private Guid _GameId;
public Game Game
{
get { return Game.Items[_GameId]; }
set { _GameId = value.Id; }
}
public Guid Id { get; private set; }
public Point Coord { get; private set; }
static public Dictionary<Guid, Sector> Items = new Dictionary<Guid, Sector>();
public Sector(Game game, Point p)
{
Id = Guid.NewGuid();
Coord = p;
Game = game;
Size = new Size(Side, Side);
SetImage("sector_up.gif");
BackgroundImageLayout = ImageLayout.Zoom;
DrawSector();
BackgroundIndex = 0;
Items.Add(Id, this);
}
public void DrawSector()
{
int LocX = StartTop + (Coord.X - 1) * Gap;
int LocY = StartLeft + (Coord.Y - 1) * Gap;
Location = new Point(LocY, LocX);
}
public static Point[,] BallMatrix
{
get
{
var ball = new Point[SectorWidth, SectorWidth];
for (int i = 0; i < SectorWidth; i++)
for (int j = 0; j < SectorWidth; j++)
ball[i, j] = new Point(i + 1, j + 1);
return ball;
}
}
public List<BallPoint> BallPoints
{
get
{
var res = new List<BallPoint>();
foreach (var ballpoint in BallPoint.Items.Values)
if (ballpoint.Sector == this)
res.Add(ballpoint);
return res;
}
}
public static Sector GetByCoord(Point p)
{
foreach (var sector in Items.Values)
if (sector.Coord == p)
return sector;
return null;
}
public static Sector GetById(Guid id)
{
foreach (var sector in Items.Values)
if (sector.Id == id)
return sector;
return null;
}
public void TurnLeft()
{
foreach (BallPoint ball in this.BallPoints)
{
ball.Coord = new Point(SectorWidth - ball.Coord.Y + 1, ball.Coord.X);
ball.DrawBallPoint();
}
BackgroundIndex = BackgroundIndex == 0 ? 3 : BackgroundIndex - 1;
RotateBackground();
}
public void TurnRight()
{
foreach (BallPoint ball in this.BallPoints)
{
ball.Coord = new Point(ball.Coord.Y, SectorWidth - ball.Coord.X + 1);
ball.DrawBallPoint();
}
BackgroundIndex = BackgroundIndex == 3 ? 0 : BackgroundIndex + 1;
RotateBackground();
}
private void RotateBackground()
{
string imgFileName ="";
switch (BackgroundIndex)
{
case 0:
imgFileName = "sector_up.gif";
break;
case 1:
imgFileName = "sector_right.gif";
break;
case 2:
imgFileName = "sector_down.gif";
break;
case 3:
imgFileName = "sector_left.gif";
break;
}
SetImage(imgFileName);
}
private void SetImage(string imgFileName)
{
string basePath = AppDomain.CurrentDomain.BaseDirectory;
string s = Path.Combine(basePath, "img", imgFileName);
BackgroundImage = Image.FromFile(s);
}
}
}