| 39 |
FTurnIndex: integer; |
FTurnIndex: integer; |
| 40 |
FActive: Boolean; |
FActive: Boolean; |
| 41 |
List: TList; |
List: TList; |
| 42 |
|
FEffectStone: TStoneType; |
| 43 |
FBool: Boolean; |
FBool: Boolean; |
| 44 |
|
FTerminated: Boolean; |
| 45 |
FIndex_X: integer; |
FIndex_X: integer; |
| 46 |
FIndex_Y: integer; |
FIndex_Y: integer; |
| 47 |
function GetStrings(X, Y: integer): TStoneType; |
function GetStrings(X, Y: integer): TStoneType; |
| 135 |
begin |
begin |
| 136 |
if CanSetStone(Stone, X, Y, true) = true then |
if CanSetStone(Stone, X, Y, true) = true then |
| 137 |
begin |
begin |
| 138 |
if Stone = stBlack then |
case Stone of |
| 139 |
Stone := stWhite |
stBlack: |
| 140 |
else |
Stone := stWhite; |
| 141 |
|
stWhite: |
| 142 |
Stone := stBlack; |
Stone := stBlack; |
| 143 |
|
stEffect: |
| 144 |
|
Stone := FEffectStone; |
| 145 |
|
end; |
| 146 |
result := 0; |
result := 0; |
| 147 |
for i := 0 to Count - 1 do |
for i := 0 to Count - 1 do |
| 148 |
for j := 0 to Count - 1 do |
for j := 0 to Count - 1 do |
| 174 |
while true do |
while true do |
| 175 |
begin |
begin |
| 176 |
s := GetStrings(X + m * i, Y + n * i); |
s := GetStrings(X + m * i, Y + n * i); |
| 177 |
|
if s = stEffect then |
| 178 |
|
s:=FEffectStone; |
| 179 |
if (s = stNone) or (s = stError) then |
if (s = stNone) or (s = stError) then |
| 180 |
break |
break |
| 181 |
else if s = Stone then |
else if s = Stone then |
| 191 |
Form1.PaintBox1.Repaint; |
Form1.PaintBox1.Repaint; |
| 192 |
if Visible = true then |
if Visible = true then |
| 193 |
begin |
begin |
| 194 |
|
FEffectStone:=Stone; |
| 195 |
New(q); |
New(q); |
| 196 |
q^.Left := X + m * j; |
q^.Left := X + m * j; |
| 197 |
q^.Top := Y + n * j; |
q^.Top := Y + n * j; |
| 200 |
q^.Y := 0; |
q^.Y := 0; |
| 201 |
List.Add(q); |
List.Add(q); |
| 202 |
SetStrings(q^.Left, q^.Top, stEffect); |
SetStrings(q^.Left, q^.Top, stEffect); |
| 203 |
for k := 1 to 10 do |
for k := 1 to 100 do |
| 204 |
begin |
begin |
| 205 |
Sleep(10); |
Sleep(1); |
| 206 |
Application.ProcessMessages; |
Application.ProcessMessages; |
| 207 |
end; |
end; |
| 208 |
end |
end |
| 225 |
end; |
end; |
| 226 |
|
|
| 227 |
begin |
begin |
| 228 |
|
result := false; |
| 229 |
if Visible = true then |
if Visible = true then |
| 230 |
begin |
begin |
| 231 |
FBool := FActive; |
FBool := FActive; |
| 232 |
FActive := false; |
FActive := false; |
| 233 |
end; |
end; |
|
result := false; |
|
| 234 |
p := true; |
p := true; |
| 235 |
if GetStrings(X, Y) = stNone then |
if GetStrings(X, Y) = stNone then |
| 236 |
begin |
begin |
| 322 |
List.Delete(i); |
List.Delete(i); |
| 323 |
if List.Count = 0 then |
if List.Count = 0 then |
| 324 |
begin |
begin |
| 325 |
FActive := FBool; |
if FTerminated = true then |
| 326 |
|
FActive:=false |
| 327 |
|
else |
| 328 |
|
FActive := FBool; |
| 329 |
inc(FTurnIndex); |
inc(FTurnIndex); |
| 330 |
inc(FTurnNumber); |
inc(FTurnNumber); |
| 331 |
FBuffer[FTurnIndex] := FStrings; |
FBuffer[FTurnIndex] := FStrings; |
| 378 |
|
|
| 379 |
procedure TStoneGrid.Pause; |
procedure TStoneGrid.Pause; |
| 380 |
begin |
begin |
| 381 |
FBool := false; |
FTerminated:=true; |
|
FActive := false; |
|
| 382 |
end; |
end; |
| 383 |
|
|
| 384 |
procedure TStoneGrid.Restart; |
procedure TStoneGrid.Restart; |
| 385 |
begin |
begin |
| 386 |
FActive := true; |
if FTerminated = true then |
| 387 |
FTurnIndex := FTurnNumber; |
begin |
| 388 |
|
FActive := true; |
| 389 |
|
FTurnIndex := FTurnNumber; |
| 390 |
|
FTerminated:=false; |
| 391 |
|
end; |
| 392 |
end; |
end; |
| 393 |
|
|
| 394 |
procedure TStoneGrid.SetStrings(X, Y: integer; const Value: TStoneType); |
procedure TStoneGrid.SetStrings(X, Y: integer; const Value: TStoneType); |
| 405 |
FTurnNumber := 0 |
FTurnNumber := 0 |
| 406 |
else |
else |
| 407 |
FTurnNumber := Value; |
FTurnNumber := Value; |
|
FActive := false; |
|
| 408 |
FStrings := FBuffer[FTurnNumber]; |
FStrings := FBuffer[FTurnNumber]; |
| 409 |
end; |
end; |
| 410 |
|
|
| 411 |
procedure TStoneGrid.Start; |
procedure TStoneGrid.Start; |
| 412 |
begin |
begin |
| 413 |
|
FActive:=false; |
| 414 |
Clear; |
Clear; |
| 415 |
|
FTerminated:=false; |
| 416 |
FActive := true; |
FActive := true; |
| 417 |
end; |
end; |
| 418 |
|
|
| 425 |
procedure Main; |
procedure Main; |
| 426 |
begin |
begin |
| 427 |
if Index = Player1 then |
if Index = Player1 then |
| 428 |
Index := Player2 |
begin |
| 429 |
|
Index := Player2; |
| 430 |
|
s := '白の手番です'; |
| 431 |
|
end |
| 432 |
else |
else |
| 433 |
|
begin |
| 434 |
Index := Player1; |
Index := Player1; |
| 435 |
|
s := '黒の手番です'; |
| 436 |
|
end; |
| 437 |
end; |
end; |
| 438 |
function Execute: Boolean; |
function Execute: Boolean; |
| 439 |
var |
var |
| 440 |
i, j: integer; |
i, j: integer; |
| 441 |
|
m: integer; |
| 442 |
|
n: integer; |
| 443 |
begin |
begin |
|
result := false; |
|
| 444 |
for i := 0 to Count - 1 do |
for i := 0 to Count - 1 do |
| 445 |
for j := 0 to Count - 1 do |
for j := 0 to Count - 1 do |
| 446 |
if StoneGrid.CanSetStone(Index.Stone, i, j, false) = true then |
if StoneGrid.CanSetStone(Index.Stone, i, j, false) = true then |
| 448 |
result := true; |
result := true; |
| 449 |
Exit; |
Exit; |
| 450 |
end; |
end; |
| 451 |
|
result := false; |
| 452 |
end; |
end; |
| 453 |
|
|
| 454 |
begin |
begin |
| 459 |
if Execute = false then |
if Execute = false then |
| 460 |
begin |
begin |
| 461 |
StoneGrid.Pause; |
StoneGrid.Pause; |
|
Timer1.Enabled := false; |
|
| 462 |
m := 0; |
m := 0; |
| 463 |
n := 0; |
n := 0; |
| 464 |
for i := 0 to Count - 1 do |
for i := 0 to Count - 1 do |
| 469 |
stWhite: |
stWhite: |
| 470 |
inc(n); |
inc(n); |
| 471 |
end; |
end; |
| 472 |
|
Caption := s; |
| 473 |
if m > n then |
if m > n then |
| 474 |
s := 'Player1 Win:' + #13#10 |
s := 'Player1 Win:' + #13#10 |
| 475 |
else if m < n then |
else if m < n then |
| 478 |
s := 'Draw:' + #13#10; |
s := 'Draw:' + #13#10; |
| 479 |
Showmessage(s + '(Player1) ' + IntToStr(m) + #13#10 + '(Player2) ' + |
Showmessage(s + '(Player1) ' + IntToStr(m) + #13#10 + '(Player2) ' + |
| 480 |
IntToStr(n)); |
IntToStr(n)); |
| 481 |
end; |
end |
| 482 |
end; |
else |
| 483 |
|
Caption := s; |
| 484 |
|
end |
| 485 |
|
else |
| 486 |
|
Caption := s; |
| 487 |
end; |
end; |
| 488 |
|
|
| 489 |
procedure TForm1.CompStone; |
procedure TForm1.CompStone; |
| 498 |
|
|
| 499 |
procedure TForm1.GameStart; |
procedure TForm1.GameStart; |
| 500 |
begin |
begin |
| 501 |
|
Index := Player1; |
| 502 |
StoneGrid.Start; |
StoneGrid.Start; |
| 503 |
PaintBox1.Repaint; |
PaintBox1.Repaint; |
| 504 |
Index := Player1; |
Caption := '黒から始めます'; |
|
Timer1.Enabled := true; |
|
| 505 |
end; |
end; |
| 506 |
|
|
| 507 |
procedure TForm1.MenuItem10Click(Sender: TObject); |
procedure TForm1.MenuItem10Click(Sender: TObject); |
| 508 |
begin |
begin |
| 509 |
StoneGrid.Restart; |
StoneGrid.Restart; |
|
Timer1.Enabled := true; |
|
| 510 |
end; |
end; |
| 511 |
|
|
| 512 |
procedure TForm1.MenuItem11Click(Sender: TObject); |
procedure TForm1.MenuItem11Click(Sender: TObject); |
| 513 |
|
var |
| 514 |
|
i: integer; |
| 515 |
begin |
begin |
|
Timer1.Enabled := false; |
|
| 516 |
with StoneGrid do |
with StoneGrid do |
| 517 |
|
begin |
| 518 |
|
i := TurnNumber; |
| 519 |
if Sender = MenuItem11 then |
if Sender = MenuItem11 then |
| 520 |
TurnNumber := TurnNumber + 1 |
TurnNumber := TurnNumber + 1 |
| 521 |
else |
else |
| 522 |
TurnNumber := TurnNumber - 1; |
TurnNumber := TurnNumber - 1; |
| 523 |
|
if (i = TurnNumber) then |
| 524 |
|
Exit |
| 525 |
|
else |
| 526 |
|
Pause; |
| 527 |
|
end; |
| 528 |
PaintBox1.Repaint; |
PaintBox1.Repaint; |
| 529 |
ChangePlayer; |
ChangePlayer; |
| 530 |
end; |
end; |
| 543 |
begin |
begin |
| 544 |
Player1.Auto := MenuItem6.IsChecked; |
Player1.Auto := MenuItem6.IsChecked; |
| 545 |
Player2.Auto := MenuItem7.IsChecked; |
Player2.Auto := MenuItem7.IsChecked; |
|
MenuItem10Click(Sender); |
|
| 546 |
end; |
end; |
| 547 |
|
|
| 548 |
procedure TForm1.MenuItem8Click(Sender: TObject); |
procedure TForm1.MenuItem8Click(Sender: TObject); |
| 549 |
begin |
begin |
| 550 |
StoneGrid.Pause; |
StoneGrid.Pause; |
|
Timer1.Enabled := false; |
|
| 551 |
end; |
end; |
| 552 |
|
|
| 553 |
procedure TForm1.PaintBox1Paint(Sender: TObject; Canvas: TCanvas); |
procedure TForm1.PaintBox1Paint(Sender: TObject; Canvas: TCanvas); |
| 554 |
var |
var |
| 555 |
i, j: integer; |
i, j: integer; |
| 556 |
begin |
begin |
| 557 |
for i := 0 to Count-1 do |
if StoneGrid.Active = false then |
| 558 |
|
StoneGrid.Paint(Canvas); |
| 559 |
|
for i := 0 to Count - 1 do |
| 560 |
begin |
begin |
| 561 |
for j := 0 to Count-1 do |
for j := 0 to Count - 1 do |
| 562 |
begin |
begin |
| 563 |
case StoneGrid.Strings[i, j] of |
case StoneGrid.Strings[i, j] of |
| 564 |
stWhite: |
stWhite: |
| 580 |
end; |
end; |
| 581 |
Canvas.DrawLine(PointF(i * Size, 0), PointF(i * Size, Size * Count), 1); |
Canvas.DrawLine(PointF(i * Size, 0), PointF(i * Size, Size * Count), 1); |
| 582 |
end; |
end; |
| 583 |
if StoneGrid.Active = false then |
Canvas.DrawLine(PointF(Count * Size, 0), |
| 584 |
StoneGrid.Paint(Canvas); |
PointF(Count * Size, Count * Size), 1); |
| 585 |
|
Canvas.DrawLine(PointF(0, Count * Size), |
| 586 |
|
PointF(Count * Size, Count * Size), 1); |
| 587 |
end; |
end; |
| 588 |
|
|
| 589 |
procedure TForm1.PaintBox1Resize(Sender: TObject); |
procedure TForm1.PaintBox1Resize(Sender: TObject); |
| 627 |
procedure TForm1.Timer1Timer(Sender: TObject); |
procedure TForm1.Timer1Timer(Sender: TObject); |
| 628 |
begin |
begin |
| 629 |
if (StoneGrid.Active = true) and (Index.Auto = true) then |
if (StoneGrid.Active = true) and (Index.Auto = true) then |
|
begin |
|
|
Timer1.Enabled := false; |
|
| 630 |
CompStone; |
CompStone; |
|
Timer1.Enabled := true; |
|
|
end; |
|
| 631 |
end; |
end; |
| 632 |
|
|
| 633 |
procedure TForm1.Timer2Timer(Sender: TObject); |
procedure TForm1.Timer2Timer(Sender: TObject); |
| 634 |
begin |
begin |
| 635 |
if StoneGrid.ListExecute = true then |
if (StoneGrid.Active = false)and(StoneGrid.ListExecute = true) then |
| 636 |
PaintBox1.Repaint; |
PaintBox1.Repaint; |
| 637 |
end; |
end; |
| 638 |
|
|