-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBallPoint.cs
More file actions
142 lines (125 loc) · 4.17 KB
/
BallPoint.cs
File metadata and controls
142 lines (125 loc) · 4.17 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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Drawing;
using System.IO;
namespace pentago
{
public class BallPoint : Control
{
private Guid _SectorId;
private static readonly int Radius = 35;
private static readonly int Gap = 63;
private static readonly int Edge = 14;
public enum BallColor { red, green, blue, cyan, magenta, yellow, black, white, brown };
public bool IsColored;
public Point Coord { get; set; }
public Guid Id { get; private set; }
public BallColor PointColor;
static public Dictionary<Guid, BallPoint> Items = new Dictionary<Guid, BallPoint>();
public Point OpenCoord
{
get
{
return new Point((Sector.Coord.X - 1) * 3 + Coord.X, (Sector.Coord.Y - 1) * 3 + Coord.Y);
}
}
public Sector Sector
{
get { return Sector.Items[_SectorId]; }
set { _SectorId = value.Id; }
}
public Player Player
{
get
{
foreach (var player in Player.Items.Values)
if (player.PlayerColor == this.PointColor)
return player;
return null;
}
}
public static BallPoint GetByCoord(Point p)
{
foreach (var ball in Items.Values)
if (ball.Coord == p)
return ball;
return null;
}
public static BallPoint GetByOpenCoord(Point p)
{
foreach (var ball in Items.Values)
if (ball.OpenCoord == p)
return ball;
return null;
}
public static BallPoint GetById(Guid id)
{
foreach (var ball in Items.Values)
if (ball.Id == id)
return ball;
return null;
}
public BallPoint(Sector sec, Point p) : this(sec, p, BallColor.white, false) { }
public BallPoint(Sector sec, Point p, BallColor ballcolor, bool isColored)
{
Sector = sec;
IsColored = isColored;
Coord = p;
PointColor = ballcolor;
Id = Guid.NewGuid();
Size = new Size(Radius, Radius);
BackColor = Color.FromArgb(247, 235, 200);
DrawBallPoint();
BackgroundImageLayout = ImageLayout.Zoom;
BallPoint b = this;
Items.Add(Id, b);
}
public void DrawBallPoint()
{
int LocX = (Coord.X - 1) * Gap + Edge;
int LocY = (Coord.Y - 1) * Gap + Edge;
Location = new Point(LocY, LocX);
string imgFileName = "";
switch (PointColor)
{
case BallColor.red:
imgFileName = "ball_red.gif";
break;
case BallColor.green:
imgFileName = "ball_green.gif";
break;
case BallColor.blue:
imgFileName = "ball_blue.gif";
break;
case BallColor.cyan:
imgFileName = "ball_cyan.gif";
break;
case BallColor.magenta:
imgFileName = "ball_magenta.gif";
break;
case BallColor.yellow:
imgFileName = "ball_yellow.gif";
break;
case BallColor.black:
imgFileName = "ball_black.gif";
break;
case BallColor.brown:
imgFileName = "ball_brown.gif";
break;
default: //white
imgFileName = "ball_white.gif";
break;
}
SetImage(imgFileName);
}
public void SetImage(string imgFileName)
{
string basePath = AppDomain.CurrentDomain.BaseDirectory;
string s = Path.Combine(basePath, "img", imgFileName);
BackgroundImage = Image.FromFile(s);
}
}
}