| 12 |
Count = 8; |
Count = 8; |
| 13 |
|
|
| 14 |
type |
type |
| 15 |
TStoneType = (stNone, stWhite, stBlack, stError); |
TStoneType = (stNone, stWhite, stBlack, stError, stEffect); |
| 16 |
|
|
| 17 |
|
TEffectData = record |
| 18 |
|
X, Y: integer; |
| 19 |
|
Left, Top: integer; |
| 20 |
|
end; |
| 21 |
|
|
| 22 |
TGridData = array [0 .. Count - 1] of array [0 .. Count - 1] of TStoneType; |
TGridData = array [0 .. Count - 1] of array [0 .. Count - 1] of TStoneType; |
| 23 |
|
|
| 24 |
TPlayer = class |
TPlayer = class(TObject) |
| 25 |
private |
private |
| 26 |
FAuto: Boolean; |
FAuto: Boolean; |
| 27 |
FStone: TStoneType; |
FStone: TStoneType; |
| 30 |
property Stone: TStoneType read FStone write FStone; |
property Stone: TStoneType read FStone write FStone; |
| 31 |
end; |
end; |
| 32 |
|
|
| 33 |
TStoneGrid = class |
TStoneGrid = class(TObject) |
| 34 |
private |
private |
| 35 |
FStrings: TGridData; |
FStrings: TGridData; |
| 36 |
FBuffer: array [0 .. Count * Count - 4] of TGridData; |
FBuffer: array [0 .. Count * Count - 4] of TGridData; |
| 37 |
FTurnNumber: integer; |
FTurnNumber: integer; |
| 38 |
FTurnIndex: integer; |
FTurnIndex: integer; |
| 39 |
FActive: Boolean; |
FActive: Boolean; |
| 40 |
|
FList: TList; |
| 41 |
|
FEffectStone: TStoneType; |
| 42 |
|
FIndex_X: integer; |
| 43 |
|
FIndex_Y: integer; |
| 44 |
|
FGameOver: Boolean; |
| 45 |
function GetStrings(X, Y: integer): TStoneType; |
function GetStrings(X, Y: integer): TStoneType; |
| 46 |
procedure SetStrings(X, Y: integer; const Value: TStoneType); |
procedure SetStrings(X, Y: integer; const Value: TStoneType); |
| 47 |
procedure SetTurnNumber(const Value: integer); |
procedure SetTurnNumber(const Value: integer); |
| 48 |
|
function GetActive: Boolean; |
| 49 |
|
procedure SetActive(const Value: Boolean); |
| 50 |
public |
public |
| 51 |
|
constructor Create; |
| 52 |
|
destructor Destroy; override; |
| 53 |
procedure Clear; |
procedure Clear; |
| 54 |
function CalScore(Stone: TStoneType; X, Y: integer): integer; |
function CalScore(Stone: TStoneType; X, Y: integer): integer; |
| 55 |
function CanSetStone(Stone: TStoneType; X, Y: integer; Reverse: Boolean; |
function CanSetStone(Stone: TStoneType; X, Y: integer; Reverse: Boolean; |
| 56 |
const Visible: Boolean = false): Boolean; |
const Visible: Boolean = false): Boolean; |
| 57 |
function NextStone(Stone: TStoneType): TPoint; |
function NextStone(Stone: TStoneType; var Pos: TPoint): Boolean; |
| 58 |
procedure Start; |
procedure Start; |
| 59 |
procedure Restart; |
procedure Restart; |
| 60 |
procedure Pause; |
procedure Pause; |
| 61 |
|
function ListExecute: Boolean; |
| 62 |
|
procedure GameOver; |
| 63 |
|
procedure Paint(Canvas: TCanvas); |
| 64 |
|
procedure ImageCount(X, Y: integer); |
| 65 |
|
function AddScore(X, Y: integer; const NG: array of TPoint): integer; |
| 66 |
property Strings[X, Y: integer]: TStoneType read GetStrings |
property Strings[X, Y: integer]: TStoneType read GetStrings |
| 67 |
write SetStrings; default; |
write SetStrings; default; |
| 68 |
property TurnNumber: integer read FTurnNumber write SetTurnNumber; |
property TurnNumber: integer read FTurnNumber write SetTurnNumber; |
| 69 |
property Active: Boolean read FActive; |
property Active: Boolean read GetActive write SetActive; |
| 70 |
end; |
end; |
| 71 |
|
|
| 72 |
TForm1 = class(TForm) |
TForm1 = class(TForm) |
| 85 |
MenuItem10: TMenuItem; |
MenuItem10: TMenuItem; |
| 86 |
MenuItem11: TMenuItem; |
MenuItem11: TMenuItem; |
| 87 |
MenuItem12: TMenuItem; |
MenuItem12: TMenuItem; |
| 88 |
|
Timer2: TTimer; |
| 89 |
|
Image1: TImage; |
| 90 |
|
Image2: TImage; |
| 91 |
|
Image3: TImage; |
| 92 |
|
Image4: TImage; |
| 93 |
|
Image5: TImage; |
| 94 |
procedure FormCreate(Sender: TObject); |
procedure FormCreate(Sender: TObject); |
| 95 |
procedure FormDestroy(Sender: TObject); |
procedure FormDestroy(Sender: TObject); |
| 96 |
procedure Timer1Timer(Sender: TObject); |
procedure Timer1Timer(Sender: TObject); |
| 106 |
procedure MenuItem8Click(Sender: TObject); |
procedure MenuItem8Click(Sender: TObject); |
| 107 |
procedure MenuItem10Click(Sender: TObject); |
procedure MenuItem10Click(Sender: TObject); |
| 108 |
procedure MenuItem11Click(Sender: TObject); |
procedure MenuItem11Click(Sender: TObject); |
| 109 |
|
procedure Timer2Timer(Sender: TObject); |
| 110 |
private |
private |
| 111 |
{ Private 宣言 } |
{ Private 宣言 } |
| 112 |
StoneGrid: TStoneGrid; |
StoneGrid: TStoneGrid; |
| 129 |
|
|
| 130 |
{$R *.fmx} |
{$R *.fmx} |
| 131 |
{$R *.Windows.fmx MSWINDOWS} |
{$R *.Windows.fmx MSWINDOWS} |
| 132 |
|
{$R *.XLgXhdpiTb.fmx ANDROID} |
| 133 |
|
|
| 134 |
{ TStoneGrid } |
{ TStoneGrid } |
| 135 |
|
|
| 136 |
|
function TStoneGrid.AddScore(X, Y: integer; const NG: array of TPoint): integer; |
| 137 |
|
var |
| 138 |
|
s: TPoint; |
| 139 |
|
begin |
| 140 |
|
result := 0; |
| 141 |
|
for s in NG do |
| 142 |
|
if (X = s.X) and (Y = s.Y) then |
| 143 |
|
begin |
| 144 |
|
result := 10; |
| 145 |
|
break; |
| 146 |
|
end; |
| 147 |
|
end; |
| 148 |
|
|
| 149 |
function TStoneGrid.CalScore(Stone: TStoneType; X, Y: integer): integer; |
function TStoneGrid.CalScore(Stone: TStoneType; X, Y: integer): integer; |
| 150 |
var |
var |
| 151 |
i, j: integer; |
i, j: integer; |
| 152 |
begin |
begin |
| 153 |
if CanSetStone(Stone, X, Y, true) = true then |
if CanSetStone(Stone, X, Y, true) = true then |
| 154 |
begin |
begin |
|
if Stone = stBlack then |
|
|
Stone := stWhite |
|
|
else |
|
|
Stone := stBlack; |
|
| 155 |
result := 0; |
result := 0; |
| 156 |
|
if FTurnIndex < 50 then |
| 157 |
|
inc(result, AddScore(X, Y, [Point(1, 0), Point(6, 0), Point(0, 1), |
| 158 |
|
Point(1, 1), Point(6, 1), Point(7, 1), Point(0, 6), Point(1, 6), |
| 159 |
|
Point(6, 6), Point(7, 6), Point(1, 7), Point(6, 7)])); |
| 160 |
|
case Stone of |
| 161 |
|
stBlack: |
| 162 |
|
Stone := stWhite; |
| 163 |
|
stWhite: |
| 164 |
|
Stone := stBlack; |
| 165 |
|
end; |
| 166 |
for i := 0 to Count - 1 do |
for i := 0 to Count - 1 do |
| 167 |
for j := 0 to Count - 1 do |
for j := 0 to Count - 1 do |
| 168 |
if CanSetStone(Stone, i, j, false) = true then |
if CanSetStone(Stone, i, j, false) = true then |
| 169 |
|
begin |
| 170 |
inc(result); |
inc(result); |
| 171 |
FStrings := FBuffer[FTurnIndex]; |
if FTurnIndex < 50 then |
| 172 |
|
inc(result, AddScore(i, j, [Point(0, 0), Point(7, 0), Point(0, 7), |
| 173 |
|
Point(7, 7)])); |
| 174 |
|
end; |
| 175 |
end |
end |
| 176 |
else |
else |
|
begin |
|
|
FStrings := FBuffer[FTurnIndex]; |
|
| 177 |
result := -1; |
result := -1; |
| 178 |
end; |
FStrings := FBuffer[FTurnIndex]; |
| 179 |
end; |
end; |
| 180 |
|
|
| 181 |
function TStoneGrid.CanSetStone(Stone: TStoneType; X, Y: integer; |
function TStoneGrid.CanSetStone(Stone: TStoneType; X, Y: integer; |
| 182 |
Reverse: Boolean; const Visible: Boolean): Boolean; |
Reverse: Boolean; const Visible: Boolean): Boolean; |
| 183 |
var |
var |
| 184 |
i, k: integer; |
i: integer; |
| 185 |
p: Boolean; |
p: Boolean; |
| 186 |
q: ^TPoint; |
q: ^TEffectData; |
|
list: TList; |
|
| 187 |
procedure Method(m, n: integer); |
procedure Method(m, n: integer); |
| 188 |
var |
var |
| 189 |
s: TStoneType; |
s: TStoneType; |
| 190 |
j: integer; |
j, k: integer; |
| 191 |
begin |
begin |
| 192 |
if p = false then |
if p = false then |
| 193 |
Exit; |
Exit; |
| 195 |
while true do |
while true do |
| 196 |
begin |
begin |
| 197 |
s := GetStrings(X + m * i, Y + n * i); |
s := GetStrings(X + m * i, Y + n * i); |
| 198 |
|
if s = stEffect then |
| 199 |
|
s := FEffectStone; |
| 200 |
if (s = stNone) or (s = stError) then |
if (s = stNone) or (s = stError) then |
| 201 |
break |
break |
| 202 |
else if s = Stone then |
else if s = Stone then |
| 203 |
if i > 1 then |
if i > 1 then |
| 204 |
begin |
begin |
| 205 |
|
if (result = false) and (Reverse = true) then |
| 206 |
|
SetStrings(X, Y, Stone); |
| 207 |
result := true; |
result := true; |
| 208 |
if Reverse = true then |
if Reverse = true then |
| 209 |
begin |
begin |
| 210 |
for j := 1 to i - 1 do |
for j := 1 to i - 1 do |
| 211 |
begin |
begin |
| 212 |
New(q); |
Form1.PaintBox1.Repaint; |
| 213 |
q^ := Point(X + m * j, Y + n * j); |
if Visible = true then |
| 214 |
list.Add(q); |
begin |
| 215 |
|
FEffectStone := Stone; |
| 216 |
|
New(q); |
| 217 |
|
q^.Left := X + m * j; |
| 218 |
|
q^.Top := Y + n * j; |
| 219 |
|
q^.X := 0; |
| 220 |
|
q^.Y := 0; |
| 221 |
|
FList.Add(q); |
| 222 |
|
SetStrings(q^.Left, q^.Top, stEffect); |
| 223 |
|
for k := 1 to 100 do |
| 224 |
|
begin |
| 225 |
|
Sleep(1); |
| 226 |
|
Application.ProcessMessages; |
| 227 |
|
end; |
| 228 |
|
end |
| 229 |
|
else |
| 230 |
|
SetStrings(X + m * j, Y + n * j, Stone); |
| 231 |
end; |
end; |
| 232 |
break; |
break; |
| 233 |
end |
end |
| 245 |
end; |
end; |
| 246 |
|
|
| 247 |
begin |
begin |
| 248 |
list := TList.Create; |
result := false; |
| 249 |
try |
p := true; |
| 250 |
result := false; |
if GetStrings(X, Y) = stNone then |
| 251 |
p := true; |
begin |
| 252 |
if GetStrings(X, Y) = stNone then |
Method(-1, -1); |
| 253 |
begin |
Method(-1, 0); |
| 254 |
Method(-1, -1); |
Method(-1, 1); |
| 255 |
Method(-1, 0); |
Method(0, -1); |
| 256 |
Method(-1, 1); |
Method(0, 1); |
| 257 |
Method(0, -1); |
Method(1, -1); |
| 258 |
Method(0, 1); |
Method(1, 0); |
| 259 |
Method(1, -1); |
Method(1, 1); |
|
Method(1, 0); |
|
|
Method(1, 1); |
|
|
end; |
|
|
if (Reverse = true) and (result = true) then |
|
|
begin |
|
|
SetStrings(X, Y, Stone); |
|
|
for i := 0 to list.Count - 1 do |
|
|
begin |
|
|
if Visible = true then |
|
|
begin |
|
|
for k := 1 to 10 do |
|
|
begin |
|
|
Sleep(10); |
|
|
Application.ProcessMessages; |
|
|
end; |
|
|
Form1.PaintBox1.Repaint; |
|
|
end; |
|
|
q := list[i]; |
|
|
SetStrings(q^.X, q^.Y, Stone); |
|
|
end; |
|
|
end; |
|
|
finally |
|
|
for i := 0 to list.Count - 1 do |
|
|
Dispose(list[i]); |
|
|
list.Free; |
|
|
end; |
|
|
if Visible = true then |
|
|
begin |
|
|
inc(FTurnIndex); |
|
|
inc(FTurnNumber); |
|
|
FBuffer[FTurnIndex] := FStrings; |
|
| 260 |
end; |
end; |
| 261 |
end; |
end; |
| 262 |
|
|
| 264 |
var |
var |
| 265 |
i, j: integer; |
i, j: integer; |
| 266 |
begin |
begin |
| 267 |
|
for i := 0 to FList.Count - 1 do |
| 268 |
|
Dispose(FList[i]); |
| 269 |
|
FList.Clear; |
| 270 |
for i := 0 to Count - 1 do |
for i := 0 to Count - 1 do |
| 271 |
for j := 0 to Count - 1 do |
for j := 0 to Count - 1 do |
| 272 |
Strings[i, j] := stNone; |
Strings[i, j] := stNone; |
| 279 |
FBuffer[0] := FStrings; |
FBuffer[0] := FStrings; |
| 280 |
end; |
end; |
| 281 |
|
|
| 282 |
|
constructor TStoneGrid.Create; |
| 283 |
|
begin |
| 284 |
|
inherited; |
| 285 |
|
FList := TList.Create; |
| 286 |
|
end; |
| 287 |
|
|
| 288 |
|
destructor TStoneGrid.Destroy; |
| 289 |
|
var |
| 290 |
|
i: integer; |
| 291 |
|
begin |
| 292 |
|
for i := 0 to FList.Count - 1 do |
| 293 |
|
Dispose(FList[i]); |
| 294 |
|
FList.Free; |
| 295 |
|
inherited; |
| 296 |
|
end; |
| 297 |
|
|
| 298 |
|
procedure TStoneGrid.GameOver; |
| 299 |
|
begin |
| 300 |
|
FGameOver := true; |
| 301 |
|
FActive := false; |
| 302 |
|
end; |
| 303 |
|
|
| 304 |
|
function TStoneGrid.GetActive: Boolean; |
| 305 |
|
begin |
| 306 |
|
if (FActive = true) and (FList.Count = 0) then |
| 307 |
|
result := true |
| 308 |
|
else |
| 309 |
|
result := false; |
| 310 |
|
end; |
| 311 |
|
|
| 312 |
function TStoneGrid.GetStrings(X, Y: integer): TStoneType; |
function TStoneGrid.GetStrings(X, Y: integer): TStoneType; |
| 313 |
begin |
begin |
| 314 |
if (X >= 0) and (X < Count) and (Y >= 0) and (Y < Count) then |
if (X >= 0) and (X < Count) and (Y >= 0) and (Y < Count) then |
| 317 |
result := stError; |
result := stError; |
| 318 |
end; |
end; |
| 319 |
|
|
| 320 |
function TStoneGrid.NextStone(Stone: TStoneType): TPoint; |
procedure TStoneGrid.ImageCount(X, Y: integer); |
| 321 |
|
begin |
| 322 |
|
FIndex_X := X; |
| 323 |
|
FIndex_Y := Y; |
| 324 |
|
end; |
| 325 |
|
|
| 326 |
|
function TStoneGrid.ListExecute: Boolean; |
| 327 |
|
var |
| 328 |
|
p: ^TEffectData; |
| 329 |
|
i: integer; |
| 330 |
|
begin |
| 331 |
|
if FList.Count = 0 then |
| 332 |
|
result := false |
| 333 |
|
else |
| 334 |
|
begin |
| 335 |
|
for i := 0 to FList.Count - 1 do |
| 336 |
|
begin |
| 337 |
|
p := FList[i]; |
| 338 |
|
if p^.X < FIndex_X - 1 then |
| 339 |
|
p^.X := p^.X + 1 |
| 340 |
|
else if p^.Y < FIndex_Y - 1 then |
| 341 |
|
begin |
| 342 |
|
p^.X := 0; |
| 343 |
|
p^.Y := p^.Y + 1; |
| 344 |
|
end |
| 345 |
|
else |
| 346 |
|
begin |
| 347 |
|
SetStrings(p^.Left, p^.Top, FEffectStone); |
| 348 |
|
Dispose(p); |
| 349 |
|
FList[i] := nil; |
| 350 |
|
end; |
| 351 |
|
end; |
| 352 |
|
for i := FList.Count - 1 downto 0 do |
| 353 |
|
if FList[i] = nil then |
| 354 |
|
FList.Delete(i); |
| 355 |
|
if FList.Count = 0 then |
| 356 |
|
begin |
| 357 |
|
inc(FTurnIndex); |
| 358 |
|
inc(FTurnNumber); |
| 359 |
|
FBuffer[FTurnIndex] := FStrings; |
| 360 |
|
if FGameOver = false then |
| 361 |
|
begin |
| 362 |
|
Form1.ChangePlayer; |
| 363 |
|
FActive:=true; |
| 364 |
|
end; |
| 365 |
|
end; |
| 366 |
|
result := true; |
| 367 |
|
end; |
| 368 |
|
end; |
| 369 |
|
|
| 370 |
|
function TStoneGrid.NextStone(Stone: TStoneType; var Pos: TPoint): Boolean; |
| 371 |
var |
var |
| 372 |
i, j, m, n: integer; |
i, j, m, n: integer; |
| 373 |
begin |
begin |
| 376 |
for j := 0 to Count - 1 do |
for j := 0 to Count - 1 do |
| 377 |
begin |
begin |
| 378 |
m := CalScore(Stone, i, j); |
m := CalScore(Stone, i, j); |
| 379 |
if (n = -1) or ((m > -1) and (n > m)) then |
if (n = -1) or ((0 < m) and (m < n)) then |
| 380 |
begin |
begin |
| 381 |
n := m; |
n := m; |
| 382 |
result := Point(i, j); |
Pos := Point(i, j); |
| 383 |
end; |
end; |
| 384 |
end; |
end; |
| 385 |
if n = -1 then |
result := not(n = -1); |
| 386 |
result := Point(-1, -1); |
end; |
| 387 |
|
|
| 388 |
|
procedure TStoneGrid.Paint(Canvas: TCanvas); |
| 389 |
|
var |
| 390 |
|
i: integer; |
| 391 |
|
k, m, n: integer; |
| 392 |
|
s: TBitmap; |
| 393 |
|
p: ^TEffectData; |
| 394 |
|
begin |
| 395 |
|
m := Form1.Image3.Bitmap.Width; |
| 396 |
|
n := Form1.Image3.Bitmap.Height; |
| 397 |
|
k := Form1.Size; |
| 398 |
|
for i := 0 to FList.Count - 1 do |
| 399 |
|
begin |
| 400 |
|
p := FList[i]; |
| 401 |
|
if FEffectStone = stBlack then |
| 402 |
|
s := Form1.Image1.Bitmap |
| 403 |
|
else |
| 404 |
|
s := Form1.Image2.Bitmap; |
| 405 |
|
Canvas.DrawBitmap(s, RectF(p^.X * m, p^.Y * n, (p^.X + 1) * m, |
| 406 |
|
(p^.Y + 1) * n), RectF(p^.Left * k, p^.Top * k, (p^.Left + 1) * k, |
| 407 |
|
(p^.Top + 1) * k), 1); |
| 408 |
|
end; |
| 409 |
end; |
end; |
| 410 |
|
|
| 411 |
procedure TStoneGrid.Pause; |
procedure TStoneGrid.Pause; |
| 415 |
|
|
| 416 |
procedure TStoneGrid.Restart; |
procedure TStoneGrid.Restart; |
| 417 |
begin |
begin |
| 418 |
FActive := true; |
FActive:=true; |
| 419 |
|
FGameOver := false; |
| 420 |
FTurnIndex := FTurnNumber; |
FTurnIndex := FTurnNumber; |
| 421 |
end; |
end; |
| 422 |
|
|
| 423 |
|
procedure TStoneGrid.SetActive(const Value: Boolean); |
| 424 |
|
begin |
| 425 |
|
if (FGameOver = false)or(Value = false) then |
| 426 |
|
FActive := Value; |
| 427 |
|
end; |
| 428 |
|
|
| 429 |
procedure TStoneGrid.SetStrings(X, Y: integer; const Value: TStoneType); |
procedure TStoneGrid.SetStrings(X, Y: integer; const Value: TStoneType); |
| 430 |
begin |
begin |
| 431 |
if (X >= 0) and (X < Count) and (Y >= 0) and (Y < Count) then |
if (X >= 0) and (X < Count) and (Y >= 0) and (Y < Count) then |
| 436 |
begin |
begin |
| 437 |
if Value > FTurnIndex then |
if Value > FTurnIndex then |
| 438 |
FTurnNumber := FTurnIndex |
FTurnNumber := FTurnIndex |
| 439 |
|
else if Value < 0 then |
| 440 |
|
FTurnNumber := 0 |
| 441 |
else |
else |
| 442 |
FTurnNumber := Value; |
FTurnNumber := Value; |
|
FActive := false; |
|
| 443 |
FStrings := FBuffer[FTurnNumber]; |
FStrings := FBuffer[FTurnNumber]; |
| 444 |
end; |
end; |
| 445 |
|
|
| 447 |
begin |
begin |
| 448 |
Clear; |
Clear; |
| 449 |
FActive := true; |
FActive := true; |
| 450 |
|
FGameOver := false; |
| 451 |
end; |
end; |
| 452 |
|
|
| 453 |
{ TForm1 } |
{ TForm1 } |
| 459 |
procedure Main; |
procedure Main; |
| 460 |
begin |
begin |
| 461 |
if Index = Player1 then |
if Index = Player1 then |
| 462 |
Index := Player2 |
begin |
| 463 |
|
Index := Player2; |
| 464 |
|
s := '白の手番です'; |
| 465 |
|
end |
| 466 |
else |
else |
| 467 |
|
begin |
| 468 |
Index := Player1; |
Index := Player1; |
| 469 |
|
s := '黒の手番です'; |
| 470 |
|
end; |
| 471 |
end; |
end; |
| 472 |
function Execute: Boolean; |
function Execute: Boolean; |
| 473 |
var |
var |
| 474 |
i, j: integer; |
i, j: integer; |
| 475 |
begin |
begin |
|
result := false; |
|
| 476 |
for i := 0 to Count - 1 do |
for i := 0 to Count - 1 do |
|
begin |
|
| 477 |
for j := 0 to Count - 1 do |
for j := 0 to Count - 1 do |
| 478 |
if StoneGrid.CanSetStone(Index.Stone, i, j, false) = true then |
if StoneGrid.CanSetStone(Index.Stone, i, j, false) = true then |
| 479 |
begin |
begin |
| 480 |
result := true; |
result := true; |
| 481 |
break; |
Exit; |
| 482 |
end; |
end; |
| 483 |
if result = true then |
result := false; |
|
break; |
|
|
end; |
|
| 484 |
end; |
end; |
| 485 |
|
|
| 486 |
begin |
begin |
| 490 |
Main; |
Main; |
| 491 |
if Execute = false then |
if Execute = false then |
| 492 |
begin |
begin |
|
StoneGrid.Pause; |
|
|
Timer1.Enabled := false; |
|
| 493 |
m := 0; |
m := 0; |
| 494 |
n := 0; |
n := 0; |
| 495 |
for i := 0 to Count - 1 do |
for i := 0 to Count - 1 do |
| 500 |
stWhite: |
stWhite: |
| 501 |
inc(n); |
inc(n); |
| 502 |
end; |
end; |
| 503 |
|
Caption := s; |
| 504 |
if m > n then |
if m > n then |
| 505 |
s := 'Player1 Win:' + #13#10 |
s := 'Player1 Win:' + #13#10 |
| 506 |
else if m < n then |
else if m < n then |
| 507 |
s := 'Player2 Win:' + #13#10 |
s := 'Player2 Win:' + #13#10 |
| 508 |
else |
else |
| 509 |
s := 'Draw:' + #13#10; |
s := 'Draw:' + #13#10; |
| 510 |
|
StoneGrid.GameOver; |
| 511 |
Showmessage(s + '(Player1) ' + IntToStr(m) + #13#10 + '(Player2) ' + |
Showmessage(s + '(Player1) ' + IntToStr(m) + #13#10 + '(Player2) ' + |
| 512 |
IntToStr(n)); |
IntToStr(n)); |
| 513 |
end; |
end |
| 514 |
end; |
else |
| 515 |
|
Caption := s; |
| 516 |
|
end |
| 517 |
|
else |
| 518 |
|
Caption := s; |
| 519 |
end; |
end; |
| 520 |
|
|
| 521 |
procedure TForm1.CompStone; |
procedure TForm1.CompStone; |
| 522 |
var |
var |
| 523 |
s: TPoint; |
s: TPoint; |
| 524 |
begin |
begin |
| 525 |
s := StoneGrid.NextStone(Index.Stone); |
StoneGrid.Active := false; |
| 526 |
|
StoneGrid.NextStone(Index.Stone, s); |
| 527 |
StoneGrid.CanSetStone(Index.Stone, s.X, s.Y, true, true); |
StoneGrid.CanSetStone(Index.Stone, s.X, s.Y, true, true); |
| 528 |
PaintBox1.Repaint; |
PaintBox1.Repaint; |
|
ChangePlayer; |
|
| 529 |
end; |
end; |
| 530 |
|
|
| 531 |
procedure TForm1.GameStart; |
procedure TForm1.GameStart; |
| 532 |
begin |
begin |
| 533 |
|
Index := Player1; |
| 534 |
StoneGrid.Start; |
StoneGrid.Start; |
| 535 |
PaintBox1.Repaint; |
PaintBox1.Repaint; |
| 536 |
Index := Player1; |
Caption := '黒から始めます'; |
|
Timer1.Enabled := true; |
|
| 537 |
end; |
end; |
| 538 |
|
|
| 539 |
procedure TForm1.MenuItem10Click(Sender: TObject); |
procedure TForm1.MenuItem10Click(Sender: TObject); |
| 540 |
begin |
begin |
| 541 |
StoneGrid.Restart; |
StoneGrid.Restart; |
|
Timer1.Enabled := true; |
|
| 542 |
end; |
end; |
| 543 |
|
|
| 544 |
procedure TForm1.MenuItem11Click(Sender: TObject); |
procedure TForm1.MenuItem11Click(Sender: TObject); |
| 545 |
|
var |
| 546 |
|
i: integer; |
| 547 |
begin |
begin |
|
Timer1.Enabled := false; |
|
| 548 |
with StoneGrid do |
with StoneGrid do |
| 549 |
|
begin |
| 550 |
|
i := TurnNumber; |
| 551 |
if Sender = MenuItem11 then |
if Sender = MenuItem11 then |
| 552 |
TurnNumber := TurnNumber + 1 |
TurnNumber := TurnNumber + 1 |
| 553 |
else |
else |
| 554 |
TurnNumber := TurnNumber - 1; |
TurnNumber := TurnNumber - 1; |
| 555 |
|
if (i = TurnNumber) then |
| 556 |
|
Exit |
| 557 |
|
else |
| 558 |
|
Pause; |
| 559 |
|
end; |
| 560 |
PaintBox1.Repaint; |
PaintBox1.Repaint; |
| 561 |
|
ChangePlayer; |
| 562 |
end; |
end; |
| 563 |
|
|
| 564 |
procedure TForm1.MenuItem2Click(Sender: TObject); |
procedure TForm1.MenuItem2Click(Sender: TObject); |
| 565 |
begin |
begin |
| 566 |
|
Timer1.Enabled := false; |
| 567 |
|
Timer2.Enabled := false; |
| 568 |
GameStart; |
GameStart; |
| 569 |
|
Timer1.Enabled := true; |
| 570 |
|
Timer2.Enabled := true; |
| 571 |
end; |
end; |
| 572 |
|
|
| 573 |
procedure TForm1.MenuItem4Click(Sender: TObject); |
procedure TForm1.MenuItem4Click(Sender: TObject); |
| 579 |
begin |
begin |
| 580 |
Player1.Auto := MenuItem6.IsChecked; |
Player1.Auto := MenuItem6.IsChecked; |
| 581 |
Player2.Auto := MenuItem7.IsChecked; |
Player2.Auto := MenuItem7.IsChecked; |
|
MenuItem10Click(Sender); |
|
| 582 |
end; |
end; |
| 583 |
|
|
| 584 |
procedure TForm1.MenuItem8Click(Sender: TObject); |
procedure TForm1.MenuItem8Click(Sender: TObject); |
| 585 |
begin |
begin |
| 586 |
StoneGrid.Pause; |
StoneGrid.Pause; |
|
Timer1.Enabled := false; |
|
| 587 |
end; |
end; |
| 588 |
|
|
| 589 |
procedure TForm1.PaintBox1Paint(Sender: TObject; Canvas: TCanvas); |
procedure TForm1.PaintBox1Paint(Sender: TObject; Canvas: TCanvas); |
| 590 |
var |
var |
| 591 |
i, j: integer; |
i, j: integer; |
| 592 |
begin |
begin |
| 593 |
Canvas.Fill.Color := TAlphaColors.White; |
if StoneGrid.Active = false then |
| 594 |
Canvas.FillRect(RectF(0, 0, Count * Size, Count * Size), 0, 0, [], 1); |
StoneGrid.Paint(Canvas); |
| 595 |
for i := 0 to Count do |
for i := 0 to Count - 1 do |
| 596 |
begin |
begin |
| 597 |
Canvas.DrawLine(PointF(i * Size, 0), PointF(i * Size, Size * Count), 1); |
for j := 0 to Count - 1 do |
|
for j := 0 to Count do |
|
| 598 |
begin |
begin |
|
Canvas.DrawLine(PointF(0, j * Size), PointF(Count * Size, j * Size), 1); |
|
| 599 |
case StoneGrid.Strings[i, j] of |
case StoneGrid.Strings[i, j] of |
| 600 |
stWhite: |
stWhite: |
| 601 |
Canvas.DrawEllipse(RectF(i * Size, j * Size, (i + 1) * Size, |
Canvas.DrawBitmap(Image4.Bitmap, RectF(0, 0, Image4.Bitmap.Width, |
| 602 |
|
Image4.Bitmap.Height), RectF(i * Size, j * Size, (i + 1) * Size, |
| 603 |
(j + 1) * Size), 1); |
(j + 1) * Size), 1); |
| 604 |
stBlack: |
stBlack: |
| 605 |
begin |
Canvas.DrawBitmap(Image3.Bitmap, RectF(0, 0, Image3.Bitmap.Width, |
| 606 |
Canvas.Fill.Color := TAlphaColors.Black; |
Image3.Bitmap.Height), RectF(i * Size, j * Size, (i + 1) * Size, |
| 607 |
Canvas.FillEllipse(RectF(i * Size, j * Size, (i + 1) * Size, |
(j + 1) * Size), 1); |
| 608 |
(j + 1) * Size), 1); |
stEffect: |
| 609 |
end; |
continue; |
| 610 |
|
else |
| 611 |
|
Canvas.DrawBitmap(Image5.Bitmap, RectF(0, 0, Image5.Bitmap.Width, |
| 612 |
|
Image5.Bitmap.Height), RectF(i * Size, j * Size, (i + 1) * Size, |
| 613 |
|
(j + 1) * Size), 1); |
| 614 |
end; |
end; |
| 615 |
|
Canvas.DrawLine(PointF(0, j * Size), PointF(Count * Size, j * Size), 1); |
| 616 |
end; |
end; |
| 617 |
|
Canvas.DrawLine(PointF(i * Size, 0), PointF(i * Size, Size * Count), 1); |
| 618 |
end; |
end; |
| 619 |
|
Canvas.DrawLine(PointF(Count * Size, 0), |
| 620 |
|
PointF(Count * Size, Count * Size), 1); |
| 621 |
|
Canvas.DrawLine(PointF(0, Count * Size), |
| 622 |
|
PointF(Count * Size, Count * Size), 1); |
| 623 |
end; |
end; |
| 624 |
|
|
| 625 |
procedure TForm1.PaintBox1Resize(Sender: TObject); |
procedure TForm1.PaintBox1Resize(Sender: TObject); |
| 629 |
|
|
| 630 |
procedure TForm1.FormCreate(Sender: TObject); |
procedure TForm1.FormCreate(Sender: TObject); |
| 631 |
begin |
begin |
| 632 |
|
ClientWidth:=20*Count; |
| 633 |
|
ClientHeight:=20*Count; |
| 634 |
StoneGrid := TStoneGrid.Create; |
StoneGrid := TStoneGrid.Create; |
| 635 |
|
StoneGrid.ImageCount(Form1.Image1.Bitmap.Width div Form1.Image3.Bitmap.Width, |
| 636 |
|
Form1.Image1.Bitmap.Height div Form1.Image3.Bitmap.Height); |
| 637 |
Player1 := TPlayer.Create; |
Player1 := TPlayer.Create; |
| 638 |
Player2 := TPlayer.Create; |
Player2 := TPlayer.Create; |
| 639 |
Player1.Stone := stBlack; |
Player1.Stone := stBlack; |
| 665 |
procedure TForm1.Timer1Timer(Sender: TObject); |
procedure TForm1.Timer1Timer(Sender: TObject); |
| 666 |
begin |
begin |
| 667 |
if (StoneGrid.Active = true) and (Index.Auto = true) then |
if (StoneGrid.Active = true) and (Index.Auto = true) then |
|
begin |
|
|
Timer1.Enabled := false; |
|
| 668 |
CompStone; |
CompStone; |
| 669 |
Timer1.Enabled := true; |
end; |
| 670 |
end; |
|
| 671 |
|
procedure TForm1.Timer2Timer(Sender: TObject); |
| 672 |
|
begin |
| 673 |
|
if (StoneGrid.Active = false) and (StoneGrid.ListExecute = true) then |
| 674 |
|
PaintBox1.Repaint; |
| 675 |
end; |
end; |
| 676 |
|
|
| 677 |
procedure TForm1.FormResize(Sender: TObject); |
procedure TForm1.FormResize(Sender: TObject); |
| 685 |
if Index.Auto = false then |
if Index.Auto = false then |
| 686 |
begin |
begin |
| 687 |
MenuItem10Click(Sender); |
MenuItem10Click(Sender); |
| 688 |
|
StoneGrid.Active := false; |
| 689 |
if StoneGrid.CanSetStone(Index.Stone, Floor(Point.X / Size), |
if StoneGrid.CanSetStone(Index.Stone, Floor(Point.X / Size), |
| 690 |
Floor(Point.Y / Size), true, true) = true then |
Floor(Point.Y / Size), true, true) = true then |
|
begin |
|
| 691 |
PaintBox1.Repaint; |
PaintBox1.Repaint; |
| 692 |
ChangePlayer; |
StoneGrid.Active := true; |
|
end; |
|
| 693 |
end; |
end; |
| 694 |
end; |
end; |
| 695 |
|
|