| 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; |
| 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; |
function TStoneGrid.AddScore(X, Y: integer; const NG: array of TPoint): integer; |
| 153 |
if CanSetStone(Stone, X, Y, true) = true then |
if CanSetStone(Stone, X, Y, true) = true then |
| 154 |
begin |
begin |
| 155 |
result := 0; |
result := 0; |
| 156 |
inc(result, AddScore(X, Y, [Point(1, 0), Point(6, 0), Point(0, 1), |
if FTurnIndex < 50 then |
| 157 |
Point(1, 1), Point(6, 1), Point(7, 1), Point(0, 6), Point(1, 6), |
inc(result, AddScore(X, Y, [Point(1, 0), Point(6, 0), Point(0, 1), |
| 158 |
Point(6, 6), Point(7, 6), Point(1, 7), Point(6, 7)])); |
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 |
case Stone of |
| 161 |
stBlack: |
stBlack: |
| 162 |
Stone := stWhite; |
Stone := stWhite; |
| 168 |
if CanSetStone(Stone, i, j, false) = true then |
if CanSetStone(Stone, i, j, false) = true then |
| 169 |
begin |
begin |
| 170 |
inc(result); |
inc(result); |
| 171 |
inc(result, AddScore(i, j, [Point(0, 0), Point(7, 0), Point(0, 7), |
if FTurnIndex < 50 then |
| 172 |
Point(7, 7)])); |
inc(result, AddScore(i, j, [Point(0, 0), Point(7, 0), Point(0, 7), |
| 173 |
|
Point(7, 7)])); |
| 174 |
end; |
end; |
| 175 |
end |
end |
| 176 |
else |
else |
| 357 |
inc(FTurnIndex); |
inc(FTurnIndex); |
| 358 |
inc(FTurnNumber); |
inc(FTurnNumber); |
| 359 |
FBuffer[FTurnIndex] := FStrings; |
FBuffer[FTurnIndex] := FStrings; |
| 360 |
|
if FGameOver = false then |
| 361 |
|
begin |
| 362 |
|
Form1.ChangePlayer; |
| 363 |
|
FActive:=true; |
| 364 |
|
end; |
| 365 |
end; |
end; |
| 366 |
result := true; |
result := true; |
| 367 |
end; |
end; |
| 415 |
|
|
| 416 |
procedure TStoneGrid.Restart; |
procedure TStoneGrid.Restart; |
| 417 |
begin |
begin |
| 418 |
FActive := true; |
FActive:=true; |
| 419 |
FGameOver := false; |
FGameOver := false; |
| 420 |
FTurnIndex := FTurnNumber; |
FTurnIndex := FTurnNumber; |
| 421 |
end; |
end; |
| 422 |
|
|
| 423 |
procedure TStoneGrid.SetActive(const Value: Boolean); |
procedure TStoneGrid.SetActive(const Value: Boolean); |
| 424 |
begin |
begin |
| 425 |
if FGameOver = false then |
if (FGameOver = false)or(Value = false) then |
| 426 |
FActive := Value; |
FActive := Value; |
| 427 |
end; |
end; |
| 428 |
|
|
| 445 |
|
|
| 446 |
procedure TStoneGrid.Start; |
procedure TStoneGrid.Start; |
| 447 |
begin |
begin |
|
FActive := true; |
|
| 448 |
Clear; |
Clear; |
| 449 |
|
FActive := true; |
| 450 |
FGameOver := false; |
FGameOver := false; |
| 451 |
end; |
end; |
| 452 |
|
|
| 490 |
Main; |
Main; |
| 491 |
if Execute = false then |
if Execute = false then |
| 492 |
begin |
begin |
|
StoneGrid.Pause; |
|
| 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 |
| 526 |
StoneGrid.NextStone(Index.Stone, s); |
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; |
|
|
StoneGrid.Active := true; |
|
| 529 |
end; |
end; |
| 530 |
|
|
| 531 |
procedure TForm1.GameStart; |
procedure TForm1.GameStart; |
| 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, |
StoneGrid.ImageCount(Form1.Image1.Bitmap.Width div Form1.Image3.Bitmap.Width, |
| 636 |
Form1.Image1.Bitmap.Height div Form1.Image3.Bitmap.Height); |
Form1.Image1.Bitmap.Height div Form1.Image3.Bitmap.Height); |
| 688 |
StoneGrid.Active := false; |
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; |
|
ChangePlayer; |
|
|
end; |
|
| 692 |
StoneGrid.Active := true; |
StoneGrid.Active := true; |
| 693 |
end; |
end; |
| 694 |
end; |
end; |