| 17 |
TEffectData = record |
TEffectData = record |
| 18 |
X, Y: integer; |
X, Y: integer; |
| 19 |
Left, Top: integer; |
Left, Top: integer; |
|
Stone: TStoneType; |
|
| 20 |
end; |
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; |
| 37 |
FTurnNumber: integer; |
FTurnNumber: integer; |
| 38 |
FTurnIndex: integer; |
FTurnIndex: integer; |
| 39 |
FActive: Boolean; |
FActive: Boolean; |
| 40 |
List: TList; |
FList: TList; |
| 41 |
FEffectStone: TStoneType; |
FEffectStone: TStoneType; |
|
FBool: Boolean; |
|
|
FTerminated: Boolean; |
|
| 42 |
FIndex_X: integer; |
FIndex_X: integer; |
| 43 |
FIndex_Y: integer; |
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; |
constructor Create; |
| 52 |
destructor Destroy; override; |
destructor Destroy; override; |
| 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; |
function ListExecute: Boolean; |
| 62 |
|
procedure GameOver; |
| 63 |
procedure Paint(Canvas: TCanvas); |
procedure Paint(Canvas: TCanvas); |
| 64 |
procedure ImageCount(X, Y: integer); |
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) |
| 131 |
{$R *.Windows.fmx MSWINDOWS} |
{$R *.Windows.fmx MSWINDOWS} |
| 132 |
{ TStoneGrid } |
{ TStoneGrid } |
| 133 |
|
|
| 134 |
|
function TStoneGrid.AddScore(X, Y: integer; const NG: array of TPoint): integer; |
| 135 |
|
var |
| 136 |
|
s: TPoint; |
| 137 |
|
begin |
| 138 |
|
result := 0; |
| 139 |
|
for s in NG do |
| 140 |
|
if (X = s.X) and (Y = s.Y) then |
| 141 |
|
begin |
| 142 |
|
result := 10; |
| 143 |
|
break; |
| 144 |
|
end; |
| 145 |
|
end; |
| 146 |
|
|
| 147 |
function TStoneGrid.CalScore(Stone: TStoneType; X, Y: integer): integer; |
function TStoneGrid.CalScore(Stone: TStoneType; X, Y: integer): integer; |
| 148 |
var |
var |
| 149 |
i, j: integer; |
i, j: integer; |
| 150 |
begin |
begin |
| 151 |
if CanSetStone(Stone, X, Y, true) = true then |
if CanSetStone(Stone, X, Y, true) = true then |
| 152 |
begin |
begin |
| 153 |
|
result := 0; |
| 154 |
|
inc(result, AddScore(X, Y, [Point(1, 0), Point(6, 0), Point(0, 1), |
| 155 |
|
Point(1, 1), Point(6, 1), Point(7, 1), Point(0, 6), Point(1, 6), |
| 156 |
|
Point(6, 6), Point(7, 6), Point(1, 7), Point(6, 7)])); |
| 157 |
case Stone of |
case Stone of |
| 158 |
stBlack: |
stBlack: |
| 159 |
Stone := stWhite; |
Stone := stWhite; |
| 160 |
stWhite: |
stWhite: |
| 161 |
Stone := stBlack; |
Stone := stBlack; |
|
stEffect: |
|
|
Stone := FEffectStone; |
|
| 162 |
end; |
end; |
|
result := 0; |
|
| 163 |
for i := 0 to Count - 1 do |
for i := 0 to Count - 1 do |
| 164 |
for j := 0 to Count - 1 do |
for j := 0 to Count - 1 do |
| 165 |
if CanSetStone(Stone, i, j, false) = true then |
if CanSetStone(Stone, i, j, false) = true then |
| 166 |
|
begin |
| 167 |
inc(result); |
inc(result); |
| 168 |
FStrings := FBuffer[FTurnIndex]; |
inc(result, AddScore(i, j, [Point(0, 0), Point(7, 0), Point(0, 7), |
| 169 |
|
Point(7, 7)])); |
| 170 |
|
end; |
| 171 |
end |
end |
| 172 |
else |
else |
|
begin |
|
|
FStrings := FBuffer[FTurnIndex]; |
|
| 173 |
result := -1; |
result := -1; |
| 174 |
end; |
FStrings := FBuffer[FTurnIndex]; |
| 175 |
end; |
end; |
| 176 |
|
|
| 177 |
function TStoneGrid.CanSetStone(Stone: TStoneType; X, Y: integer; |
function TStoneGrid.CanSetStone(Stone: TStoneType; X, Y: integer; |
| 192 |
begin |
begin |
| 193 |
s := GetStrings(X + m * i, Y + n * i); |
s := GetStrings(X + m * i, Y + n * i); |
| 194 |
if s = stEffect then |
if s = stEffect then |
| 195 |
s:=FEffectStone; |
s := FEffectStone; |
| 196 |
if (s = stNone) or (s = stError) then |
if (s = stNone) or (s = stError) then |
| 197 |
break |
break |
| 198 |
else if s = Stone then |
else if s = Stone then |
| 208 |
Form1.PaintBox1.Repaint; |
Form1.PaintBox1.Repaint; |
| 209 |
if Visible = true then |
if Visible = true then |
| 210 |
begin |
begin |
| 211 |
FEffectStone:=Stone; |
FEffectStone := Stone; |
| 212 |
New(q); |
New(q); |
| 213 |
q^.Left := X + m * j; |
q^.Left := X + m * j; |
| 214 |
q^.Top := Y + n * j; |
q^.Top := Y + n * j; |
|
q^.Stone := Stone; |
|
| 215 |
q^.X := 0; |
q^.X := 0; |
| 216 |
q^.Y := 0; |
q^.Y := 0; |
| 217 |
List.Add(q); |
FList.Add(q); |
| 218 |
SetStrings(q^.Left, q^.Top, stEffect); |
SetStrings(q^.Left, q^.Top, stEffect); |
| 219 |
for k := 1 to 100 do |
for k := 1 to 100 do |
| 220 |
begin |
begin |
| 242 |
|
|
| 243 |
begin |
begin |
| 244 |
result := false; |
result := false; |
|
if Visible = true then |
|
|
begin |
|
|
FBool := FActive; |
|
|
FActive := false; |
|
|
end; |
|
| 245 |
p := true; |
p := true; |
| 246 |
if GetStrings(X, Y) = stNone then |
if GetStrings(X, Y) = stNone then |
| 247 |
begin |
begin |
| 260 |
var |
var |
| 261 |
i, j: integer; |
i, j: integer; |
| 262 |
begin |
begin |
| 263 |
|
for i := 0 to FList.Count - 1 do |
| 264 |
|
Dispose(FList[i]); |
| 265 |
|
FList.Clear; |
| 266 |
for i := 0 to Count - 1 do |
for i := 0 to Count - 1 do |
| 267 |
for j := 0 to Count - 1 do |
for j := 0 to Count - 1 do |
| 268 |
Strings[i, j] := stNone; |
Strings[i, j] := stNone; |
| 278 |
constructor TStoneGrid.Create; |
constructor TStoneGrid.Create; |
| 279 |
begin |
begin |
| 280 |
inherited; |
inherited; |
| 281 |
List := TList.Create; |
FList := TList.Create; |
| 282 |
end; |
end; |
| 283 |
|
|
| 284 |
destructor TStoneGrid.Destroy; |
destructor TStoneGrid.Destroy; |
| 285 |
var |
var |
| 286 |
i: integer; |
i: integer; |
| 287 |
begin |
begin |
| 288 |
for i := 0 to List.Count - 1 do |
for i := 0 to FList.Count - 1 do |
| 289 |
Dispose(List[i]); |
Dispose(FList[i]); |
| 290 |
List.Free; |
FList.Free; |
| 291 |
inherited; |
inherited; |
| 292 |
end; |
end; |
| 293 |
|
|
| 294 |
|
procedure TStoneGrid.GameOver; |
| 295 |
|
begin |
| 296 |
|
FGameOver := true; |
| 297 |
|
FActive := false; |
| 298 |
|
end; |
| 299 |
|
|
| 300 |
|
function TStoneGrid.GetActive: Boolean; |
| 301 |
|
begin |
| 302 |
|
if (FActive = true) and (FList.Count = 0) then |
| 303 |
|
result := true |
| 304 |
|
else |
| 305 |
|
result := false; |
| 306 |
|
end; |
| 307 |
|
|
| 308 |
function TStoneGrid.GetStrings(X, Y: integer): TStoneType; |
function TStoneGrid.GetStrings(X, Y: integer): TStoneType; |
| 309 |
begin |
begin |
| 310 |
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 |
| 324 |
p: ^TEffectData; |
p: ^TEffectData; |
| 325 |
i: integer; |
i: integer; |
| 326 |
begin |
begin |
| 327 |
if List.Count = 0 then |
if FList.Count = 0 then |
| 328 |
result := false |
result := false |
| 329 |
else |
else |
| 330 |
begin |
begin |
| 331 |
for i := 0 to List.Count - 1 do |
for i := 0 to FList.Count - 1 do |
| 332 |
begin |
begin |
| 333 |
p := List.List[i]; |
p := FList[i]; |
| 334 |
if p^.X < FIndex_X - 1 then |
if p^.X < FIndex_X - 1 then |
| 335 |
p^.X := p^.X + 1 |
p^.X := p^.X + 1 |
| 336 |
else if p^.Y < FIndex_Y - 1 then |
else if p^.Y < FIndex_Y - 1 then |
| 340 |
end |
end |
| 341 |
else |
else |
| 342 |
begin |
begin |
| 343 |
SetStrings(p^.Left, p^.Top, p^.Stone); |
SetStrings(p^.Left, p^.Top, FEffectStone); |
| 344 |
Dispose(p); |
Dispose(p); |
| 345 |
List[i] := nil; |
FList[i] := nil; |
| 346 |
end; |
end; |
| 347 |
end; |
end; |
| 348 |
for i := List.Count - 1 downto 0 do |
for i := FList.Count - 1 downto 0 do |
| 349 |
if List[i] = nil then |
if FList[i] = nil then |
| 350 |
List.Delete(i); |
FList.Delete(i); |
| 351 |
if List.Count = 0 then |
if FList.Count = 0 then |
| 352 |
begin |
begin |
|
if FTerminated = true then |
|
|
FActive:=false |
|
|
else |
|
|
FActive := FBool; |
|
| 353 |
inc(FTurnIndex); |
inc(FTurnIndex); |
| 354 |
inc(FTurnNumber); |
inc(FTurnNumber); |
| 355 |
FBuffer[FTurnIndex] := FStrings; |
FBuffer[FTurnIndex] := FStrings; |
| 358 |
end; |
end; |
| 359 |
end; |
end; |
| 360 |
|
|
| 361 |
function TStoneGrid.NextStone(Stone: TStoneType): TPoint; |
function TStoneGrid.NextStone(Stone: TStoneType; var Pos: TPoint): Boolean; |
| 362 |
var |
var |
| 363 |
i, j, m, n: integer; |
i, j, m, n: integer; |
| 364 |
begin |
begin |
| 367 |
for j := 0 to Count - 1 do |
for j := 0 to Count - 1 do |
| 368 |
begin |
begin |
| 369 |
m := CalScore(Stone, i, j); |
m := CalScore(Stone, i, j); |
| 370 |
if (n = -1) or ((m > -1) and (n > m)) then |
if (n = -1) or ((0 < m) and (m < n)) then |
| 371 |
begin |
begin |
| 372 |
n := m; |
n := m; |
| 373 |
result := Point(i, j); |
Pos := Point(i, j); |
| 374 |
end; |
end; |
| 375 |
end; |
end; |
| 376 |
if n = -1 then |
result := not(n = -1); |
|
result := Point(-1, -1); |
|
| 377 |
end; |
end; |
| 378 |
|
|
| 379 |
procedure TStoneGrid.Paint(Canvas: TCanvas); |
procedure TStoneGrid.Paint(Canvas: TCanvas); |
| 386 |
m := Form1.Image3.Bitmap.Width; |
m := Form1.Image3.Bitmap.Width; |
| 387 |
n := Form1.Image3.Bitmap.Height; |
n := Form1.Image3.Bitmap.Height; |
| 388 |
k := Form1.Size; |
k := Form1.Size; |
| 389 |
for i := 0 to List.Count - 1 do |
for i := 0 to FList.Count - 1 do |
| 390 |
begin |
begin |
| 391 |
p := List[i]; |
p := FList[i]; |
| 392 |
if p^.Stone = stBlack then |
if FEffectStone = stBlack then |
| 393 |
s := Form1.Image1.Bitmap |
s := Form1.Image1.Bitmap |
| 394 |
else |
else |
| 395 |
s := Form1.Image2.Bitmap; |
s := Form1.Image2.Bitmap; |
| 401 |
|
|
| 402 |
procedure TStoneGrid.Pause; |
procedure TStoneGrid.Pause; |
| 403 |
begin |
begin |
| 404 |
FTerminated:=true; |
FActive := false; |
| 405 |
end; |
end; |
| 406 |
|
|
| 407 |
procedure TStoneGrid.Restart; |
procedure TStoneGrid.Restart; |
| 408 |
begin |
begin |
| 409 |
if FTerminated = true then |
FActive := true; |
| 410 |
begin |
FGameOver := false; |
| 411 |
FActive := true; |
FTurnIndex := FTurnNumber; |
| 412 |
FTurnIndex := FTurnNumber; |
end; |
| 413 |
FTerminated:=false; |
|
| 414 |
end; |
procedure TStoneGrid.SetActive(const Value: Boolean); |
| 415 |
|
begin |
| 416 |
|
if FGameOver = false then |
| 417 |
|
FActive := Value; |
| 418 |
end; |
end; |
| 419 |
|
|
| 420 |
procedure TStoneGrid.SetStrings(X, Y: integer; const Value: TStoneType); |
procedure TStoneGrid.SetStrings(X, Y: integer; const Value: TStoneType); |
| 436 |
|
|
| 437 |
procedure TStoneGrid.Start; |
procedure TStoneGrid.Start; |
| 438 |
begin |
begin |
|
Clear; |
|
|
FTerminated:=false; |
|
| 439 |
FActive := true; |
FActive := true; |
| 440 |
|
Clear; |
| 441 |
|
FGameOver := false; |
| 442 |
end; |
end; |
| 443 |
|
|
| 444 |
{ TForm1 } |
{ TForm1 } |
| 463 |
function Execute: Boolean; |
function Execute: Boolean; |
| 464 |
var |
var |
| 465 |
i, j: integer; |
i, j: integer; |
|
m: integer; |
|
|
n: integer; |
|
| 466 |
begin |
begin |
| 467 |
for i := 0 to Count - 1 do |
for i := 0 to Count - 1 do |
| 468 |
for j := 0 to Count - 1 do |
for j := 0 to Count - 1 do |
| 499 |
s := 'Player2 Win:' + #13#10 |
s := 'Player2 Win:' + #13#10 |
| 500 |
else |
else |
| 501 |
s := 'Draw:' + #13#10; |
s := 'Draw:' + #13#10; |
| 502 |
|
StoneGrid.GameOver; |
| 503 |
Showmessage(s + '(Player1) ' + IntToStr(m) + #13#10 + '(Player2) ' + |
Showmessage(s + '(Player1) ' + IntToStr(m) + #13#10 + '(Player2) ' + |
| 504 |
IntToStr(n)); |
IntToStr(n)); |
| 505 |
end |
end |
| 514 |
var |
var |
| 515 |
s: TPoint; |
s: TPoint; |
| 516 |
begin |
begin |
| 517 |
s := StoneGrid.NextStone(Index.Stone); |
StoneGrid.Active := false; |
| 518 |
|
StoneGrid.NextStone(Index.Stone, s); |
| 519 |
StoneGrid.CanSetStone(Index.Stone, s.X, s.Y, true, true); |
StoneGrid.CanSetStone(Index.Stone, s.X, s.Y, true, true); |
| 520 |
PaintBox1.Repaint; |
PaintBox1.Repaint; |
| 521 |
ChangePlayer; |
ChangePlayer; |
| 522 |
|
StoneGrid.Active := true; |
| 523 |
end; |
end; |
| 524 |
|
|
| 525 |
procedure TForm1.GameStart; |
procedure TForm1.GameStart; |
| 557 |
|
|
| 558 |
procedure TForm1.MenuItem2Click(Sender: TObject); |
procedure TForm1.MenuItem2Click(Sender: TObject); |
| 559 |
begin |
begin |
| 560 |
|
Timer1.Enabled := false; |
| 561 |
|
Timer2.Enabled := false; |
| 562 |
GameStart; |
GameStart; |
| 563 |
|
Timer1.Enabled := true; |
| 564 |
|
Timer2.Enabled := true; |
| 565 |
end; |
end; |
| 566 |
|
|
| 567 |
procedure TForm1.MenuItem4Click(Sender: TObject); |
procedure TForm1.MenuItem4Click(Sender: TObject); |
| 662 |
|
|
| 663 |
procedure TForm1.Timer2Timer(Sender: TObject); |
procedure TForm1.Timer2Timer(Sender: TObject); |
| 664 |
begin |
begin |
| 665 |
if (StoneGrid.Active = false)and(StoneGrid.ListExecute = true) then |
if (StoneGrid.Active = false) and (StoneGrid.ListExecute = true) then |
| 666 |
PaintBox1.Repaint; |
PaintBox1.Repaint; |
| 667 |
end; |
end; |
| 668 |
|
|
| 677 |
if Index.Auto = false then |
if Index.Auto = false then |
| 678 |
begin |
begin |
| 679 |
MenuItem10Click(Sender); |
MenuItem10Click(Sender); |
| 680 |
|
StoneGrid.Active := false; |
| 681 |
if StoneGrid.CanSetStone(Index.Stone, Floor(Point.X / Size), |
if StoneGrid.CanSetStone(Index.Stone, Floor(Point.X / Size), |
| 682 |
Floor(Point.Y / Size), true, true) = true then |
Floor(Point.Y / Size), true, true) = true then |
| 683 |
begin |
begin |
| 684 |
PaintBox1.Repaint; |
PaintBox1.Repaint; |
| 685 |
ChangePlayer; |
ChangePlayer; |
| 686 |
end; |
end; |
| 687 |
|
StoneGrid.Active := true; |
| 688 |
end; |
end; |
| 689 |
end; |
end; |
| 690 |
|
|