| 4 |
|
|
| 5 |
uses |
uses |
| 6 |
System.SysUtils, System.Types, System.UITypes, System.Classes, |
System.SysUtils, System.Types, System.UITypes, System.Classes, |
| 7 |
System.Variants, |
System.Variants, Generics.Collections, |
| 8 |
FMX.Types, FMX.Controls, FMX.Forms, FMX.Graphics, FMX.Dialogs, FMX.Menus, |
FMX.Types, FMX.Controls, FMX.Forms, FMX.Graphics, FMX.Dialogs, FMX.Menus, |
| 9 |
System.Math, FMX.Objects, FMX.StdCtrls; |
System.Math, FMX.Objects, FMX.StdCtrls; |
| 10 |
|
|
| 11 |
const |
const |
| 12 |
Count = 8; |
bmp_count = 8; |
| 13 |
|
|
| 14 |
type |
type |
| 15 |
TStoneType = (stNone, stWhite, stBlack, stError, stEffect); |
TStoneType = (stNone, stWhite, stBlack, stError, stEffect); |
| 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 .. bmp_count - 1] of array [0 .. bmp_count - 1] |
| 23 |
|
of TStoneType; |
| 24 |
|
|
| 25 |
TPlayer = class |
TPlayer = class(TObject) |
| 26 |
private |
private |
| 27 |
FAuto: Boolean; |
FAuto: Boolean; |
| 28 |
FStone: TStoneType; |
FStone: TStoneType; |
| 31 |
property Stone: TStoneType read FStone write FStone; |
property Stone: TStoneType read FStone write FStone; |
| 32 |
end; |
end; |
| 33 |
|
|
| 34 |
TStoneGrid = class |
TStoneGrid = class(TObject) |
| 35 |
private |
private |
| 36 |
FStrings: TGridData; |
FStrings: TGridData; |
| 37 |
FBuffer: array [0 .. Count * Count - 4] of TGridData; |
FBuffer: array [0 .. bmp_count * bmp_count - 4] of TGridData; |
| 38 |
FTurnNumber: integer; |
FTurnNumber: integer; |
| 39 |
FTurnIndex: integer; |
FTurnIndex: integer; |
| 40 |
FActive: Boolean; |
FActive: Boolean; |
| 41 |
List: TList; |
FList: TList<TEffectData>; |
| 42 |
FBool: Boolean; |
FEffectStone: TStoneType; |
| 43 |
FIndex_X: integer; |
FIndex_X: integer; |
| 44 |
FIndex_Y: integer; |
FIndex_Y: integer; |
| 45 |
|
FGameOver: Boolean; |
| 46 |
function GetStrings(X, Y: integer): TStoneType; |
function GetStrings(X, Y: integer): TStoneType; |
| 47 |
procedure SetStrings(X, Y: integer; const Value: TStoneType); |
procedure SetStrings(X, Y: integer; const Value: TStoneType); |
| 48 |
procedure SetTurnNumber(const Value: integer); |
procedure SetTurnNumber(const Value: integer); |
| 49 |
|
function GetActive: Boolean; |
| 50 |
|
procedure SetActive(const Value: Boolean); |
| 51 |
public |
public |
| 52 |
constructor Create; |
constructor Create; |
| 53 |
destructor Destroy; override; |
destructor Destroy; override; |
| 54 |
procedure Clear; |
procedure Clear; |
| 55 |
function CalScore(Stone: TStoneType; X, Y: integer): integer; |
function CalScore(Stone: TStoneType; X, Y: integer; |
| 56 |
|
out Score: integer): Boolean; |
| 57 |
function CanSetStone(Stone: TStoneType; X, Y: integer; Reverse: Boolean; |
function CanSetStone(Stone: TStoneType; X, Y: integer; Reverse: Boolean; |
| 58 |
const Visible: Boolean = false): Boolean; |
const Visible: Boolean = false): Boolean; |
| 59 |
function NextStone(Stone: TStoneType): TPoint; |
function NextStone(Stone: TStoneType; var Pos: TPoint): Boolean; |
| 60 |
procedure Start; |
procedure Start; |
| 61 |
procedure Restart; |
procedure Restart; |
| 62 |
procedure Pause; |
procedure Pause; |
| 63 |
function ListExecute: Boolean; |
function ListExecute: Boolean; |
| 64 |
|
procedure GameOver; |
| 65 |
procedure Paint(Canvas: TCanvas); |
procedure Paint(Canvas: TCanvas); |
| 66 |
procedure ImageCount(X, Y: integer); |
procedure ImageCount(X, Y: integer); |
| 67 |
|
function AddScore(X, Y: integer; const NG: array of TPoint): integer; |
| 68 |
property Strings[X, Y: integer]: TStoneType read GetStrings |
property Strings[X, Y: integer]: TStoneType read GetStrings |
| 69 |
write SetStrings; default; |
write SetStrings; default; |
| 70 |
property TurnNumber: integer read FTurnNumber write SetTurnNumber; |
property TurnNumber: integer read FTurnNumber write SetTurnNumber; |
| 71 |
property Active: Boolean read FActive; |
property Active: Boolean read GetActive write SetActive; |
| 72 |
end; |
end; |
| 73 |
|
|
| 74 |
TForm1 = class(TForm) |
TForm1 = class(TForm) |
| 91 |
Image1: TImage; |
Image1: TImage; |
| 92 |
Image2: TImage; |
Image2: TImage; |
| 93 |
Image3: TImage; |
Image3: TImage; |
| 94 |
Image4: TImage; |
MenuItem13: TMenuItem; |
| 95 |
Image5: TImage; |
MenuItem14: TMenuItem; |
| 96 |
|
MenuItem15: TMenuItem; |
| 97 |
procedure FormCreate(Sender: TObject); |
procedure FormCreate(Sender: TObject); |
| 98 |
procedure FormDestroy(Sender: TObject); |
procedure FormDestroy(Sender: TObject); |
| 99 |
procedure Timer1Timer(Sender: TObject); |
procedure Timer1Timer(Sender: TObject); |
| 132 |
|
|
| 133 |
{$R *.fmx} |
{$R *.fmx} |
| 134 |
{$R *.Windows.fmx MSWINDOWS} |
{$R *.Windows.fmx MSWINDOWS} |
| 135 |
|
{$R *.XLgXhdpiTb.fmx ANDROID} |
| 136 |
{ TStoneGrid } |
{ TStoneGrid } |
| 137 |
|
|
| 138 |
function TStoneGrid.CalScore(Stone: TStoneType; X, Y: integer): integer; |
function TStoneGrid.AddScore(X, Y: integer; const NG: array of TPoint): integer; |
| 139 |
|
var |
| 140 |
|
s: TPoint; |
| 141 |
|
begin |
| 142 |
|
result := 0; |
| 143 |
|
for s in NG do |
| 144 |
|
if (X = s.X) and (Y = s.Y) then |
| 145 |
|
begin |
| 146 |
|
result := 10; |
| 147 |
|
break; |
| 148 |
|
end; |
| 149 |
|
end; |
| 150 |
|
|
| 151 |
|
function TStoneGrid.CalScore(Stone: TStoneType; X, Y: integer; |
| 152 |
|
out Score: integer): Boolean; |
| 153 |
var |
var |
| 154 |
i, j: integer; |
i, j: integer; |
| 155 |
|
loop: integer; |
| 156 |
|
const |
| 157 |
|
waste: array [1 .. 12] of TPoint = ((X: 1; Y: 0), (X: 6; Y: 0), (X: 0; Y: 1), |
| 158 |
|
(X: 1; Y: 1), (X: 6; Y: 1), (X: 7; Y: 1), (X: 0; Y: 6), (X: 1; Y: 6), (X: 6; |
| 159 |
|
Y: 6), (X: 7; Y: 6), (X: 1; Y: 7), (X: 6; Y: 7)); |
| 160 |
|
worth: array [1 .. 4] of TPoint = ((X: 0; Y: 0), (X: 7; Y: 0), (X: 0; Y: 7), |
| 161 |
|
(X: 7; Y: 7)); |
| 162 |
|
label Last; |
| 163 |
|
procedure Easy; |
| 164 |
|
var |
| 165 |
|
m, n: integer; |
| 166 |
|
begin |
| 167 |
|
for m := 0 to bmp_count - 1 do |
| 168 |
|
for n := 0 to bmp_count - 1 do |
| 169 |
|
if CanSetStone(Stone, m, n, false) = true then |
| 170 |
|
begin |
| 171 |
|
inc(Score); |
| 172 |
|
inc(Score, AddScore(m, n, worth)); |
| 173 |
|
end; |
| 174 |
|
end; |
| 175 |
|
procedure Hard; |
| 176 |
|
var |
| 177 |
|
m, n: integer; |
| 178 |
|
begin |
| 179 |
|
if loop > 2 then |
| 180 |
|
Exit; |
| 181 |
|
inc(loop); |
| 182 |
|
for m := 0 to bmp_count - 1 do |
| 183 |
|
for n := 0 to bmp_count - 1 do |
| 184 |
|
begin |
| 185 |
|
if CanSetStone(Stone, m, n, true) = true then |
| 186 |
|
begin |
| 187 |
|
inc(Score, AddScore(m, n, worth)); |
| 188 |
|
if FTurnIndex + 1 < 50 then |
| 189 |
|
dec(Score, AddScore(m, n, waste)); |
| 190 |
|
case Stone of |
| 191 |
|
stBlack: |
| 192 |
|
Stone := stWhite; |
| 193 |
|
stWhite: |
| 194 |
|
Stone := stBlack; |
| 195 |
|
end; |
| 196 |
|
Hard; |
| 197 |
|
Easy; |
| 198 |
|
end; |
| 199 |
|
FStrings := FBuffer[FTurnIndex + loop]; |
| 200 |
|
end; |
| 201 |
|
end; |
| 202 |
|
|
| 203 |
begin |
begin |
| 204 |
if CanSetStone(Stone, X, Y, true) = true then |
if CanSetStone(Stone, X, Y, true) = true then |
| 205 |
begin |
begin |
| 206 |
if Stone = stBlack then |
Score := 0; |
| 207 |
Stone := stWhite |
result := true; |
| 208 |
else |
if FTurnIndex < 50 then |
| 209 |
Stone := stBlack; |
inc(Score, AddScore(X, Y, waste)); |
| 210 |
result := 0; |
dec(Score, AddScore(X, Y, worth)); |
| 211 |
for i := 0 to Count - 1 do |
case Stone of |
| 212 |
for j := 0 to Count - 1 do |
stBlack: |
| 213 |
if CanSetStone(Stone, i, j, false) = true then |
Stone := stWhite; |
| 214 |
inc(result); |
stWhite: |
| 215 |
FStrings := FBuffer[FTurnIndex]; |
Stone := stBlack; |
| 216 |
|
end; |
| 217 |
|
if (Form1.MenuItem14.IsChecked = true) and (FTurnIndex + 1 <= 60) then |
| 218 |
|
begin |
| 219 |
|
FBuffer[FTurnIndex + 1] := FStrings; |
| 220 |
|
loop := 0; |
| 221 |
|
Hard; |
| 222 |
|
end; |
| 223 |
|
Easy; |
| 224 |
end |
end |
| 225 |
else |
else |
| 226 |
begin |
result := false; |
| 227 |
FStrings := FBuffer[FTurnIndex]; |
FStrings := FBuffer[FTurnIndex]; |
|
result := -1; |
|
|
end; |
|
| 228 |
end; |
end; |
| 229 |
|
|
| 230 |
function TStoneGrid.CanSetStone(Stone: TStoneType; X, Y: integer; |
function TStoneGrid.CanSetStone(Stone: TStoneType; X, Y: integer; |
| 232 |
var |
var |
| 233 |
i: integer; |
i: integer; |
| 234 |
p: Boolean; |
p: Boolean; |
| 235 |
q: ^TEffectData; |
q: TEffectData; |
| 236 |
procedure Method(m, n: integer); |
procedure Method(m, n: integer); |
| 237 |
var |
var |
| 238 |
s: TStoneType; |
s: TStoneType; |
| 239 |
j, k: integer; |
j: integer; |
| 240 |
|
k: integer; |
| 241 |
begin |
begin |
| 242 |
if p = false then |
if p = false then |
| 243 |
Exit; |
Exit; |
| 245 |
while true do |
while true do |
| 246 |
begin |
begin |
| 247 |
s := GetStrings(X + m * i, Y + n * i); |
s := GetStrings(X + m * i, Y + n * i); |
| 248 |
|
if s = stEffect then |
| 249 |
|
s := FEffectStone; |
| 250 |
if (s = stNone) or (s = stError) then |
if (s = stNone) or (s = stError) then |
| 251 |
break |
break |
| 252 |
else if s = Stone then |
else if s = Stone then |
| 257 |
result := true; |
result := true; |
| 258 |
if Reverse = true then |
if Reverse = true then |
| 259 |
begin |
begin |
| 260 |
|
Form1.PaintBox1.Repaint; |
| 261 |
for j := 1 to i - 1 do |
for j := 1 to i - 1 do |
| 262 |
begin |
begin |
|
Form1.PaintBox1.Repaint; |
|
| 263 |
if Visible = true then |
if Visible = true then |
| 264 |
begin |
begin |
| 265 |
New(q); |
FEffectStone := Stone; |
| 266 |
q^.Left := X + m * j; |
q.Left := X + m * j; |
| 267 |
q^.Top := Y + n * j; |
q.Top := Y + n * j; |
| 268 |
q^.Stone := Stone; |
q.X := 0; |
| 269 |
q^.X := 0; |
q.Y := 0; |
| 270 |
q^.Y := 0; |
FList.Add(q); |
| 271 |
List.Add(q); |
SetStrings(q.Left, q.Top, stEffect); |
|
SetStrings(q^.Left, q^.Top, stEffect); |
|
| 272 |
for k := 1 to 10 do |
for k := 1 to 10 do |
| 273 |
begin |
begin |
| 274 |
Sleep(10); |
Sleep(15); |
| 275 |
Application.ProcessMessages; |
Application.ProcessMessages; |
| 276 |
end; |
end; |
| 277 |
end |
end |
| 295 |
|
|
| 296 |
begin |
begin |
| 297 |
result := false; |
result := false; |
|
if Visible = true then |
|
|
begin |
|
|
FBool := FActive; |
|
|
FActive := false; |
|
|
end; |
|
| 298 |
p := true; |
p := true; |
| 299 |
if GetStrings(X, Y) = stNone then |
if GetStrings(X, Y) = stNone then |
| 300 |
begin |
begin |
| 313 |
var |
var |
| 314 |
i, j: integer; |
i, j: integer; |
| 315 |
begin |
begin |
| 316 |
for i := 0 to Count - 1 do |
FList.Clear; |
| 317 |
for j := 0 to Count - 1 do |
for i := 0 to bmp_count - 1 do |
| 318 |
|
for j := 0 to bmp_count - 1 do |
| 319 |
Strings[i, j] := stNone; |
Strings[i, j] := stNone; |
| 320 |
Strings[3, 3] := stBlack; |
Strings[3, 3] := stBlack; |
| 321 |
Strings[4, 4] := stBlack; |
Strings[4, 4] := stBlack; |
| 329 |
constructor TStoneGrid.Create; |
constructor TStoneGrid.Create; |
| 330 |
begin |
begin |
| 331 |
inherited; |
inherited; |
| 332 |
List := TList.Create; |
FList := TList<TEffectData>.Create; |
| 333 |
end; |
end; |
| 334 |
|
|
| 335 |
destructor TStoneGrid.Destroy; |
destructor TStoneGrid.Destroy; |
|
var |
|
|
i: integer; |
|
| 336 |
begin |
begin |
| 337 |
for i := 0 to List.Count - 1 do |
FList.Free; |
|
Dispose(List[i]); |
|
|
List.Free; |
|
| 338 |
inherited; |
inherited; |
| 339 |
end; |
end; |
| 340 |
|
|
| 341 |
|
procedure TStoneGrid.GameOver; |
| 342 |
|
begin |
| 343 |
|
FGameOver := true; |
| 344 |
|
FActive := false; |
| 345 |
|
end; |
| 346 |
|
|
| 347 |
|
function TStoneGrid.GetActive: Boolean; |
| 348 |
|
begin |
| 349 |
|
if (FActive = true) and (FList.Count = 0) then |
| 350 |
|
result := true |
| 351 |
|
else |
| 352 |
|
result := false; |
| 353 |
|
end; |
| 354 |
|
|
| 355 |
function TStoneGrid.GetStrings(X, Y: integer): TStoneType; |
function TStoneGrid.GetStrings(X, Y: integer): TStoneType; |
| 356 |
begin |
begin |
| 357 |
if (X >= 0) and (X < Count) and (Y >= 0) and (Y < Count) then |
if (X >= 0) and (X < bmp_count) and (Y >= 0) and (Y < bmp_count) then |
| 358 |
result := FStrings[X, Y] |
result := FStrings[X, Y] |
| 359 |
else |
else |
| 360 |
result := stError; |
result := stError; |
| 368 |
|
|
| 369 |
function TStoneGrid.ListExecute: Boolean; |
function TStoneGrid.ListExecute: Boolean; |
| 370 |
var |
var |
|
p: ^TEffectData; |
|
| 371 |
i: integer; |
i: integer; |
| 372 |
|
s: TEffectData; |
| 373 |
begin |
begin |
| 374 |
if List.Count = 0 then |
if FList.Count = 0 then |
| 375 |
result := false |
result := false |
| 376 |
else |
else |
| 377 |
begin |
begin |
| 378 |
for i := 0 to List.Count - 1 do |
i := 0; |
| 379 |
|
while i < FList.Count do |
| 380 |
begin |
begin |
| 381 |
p := List.List[i]; |
s := FList[i]; |
| 382 |
if p^.X < FIndex_X - 1 then |
if s.X < FIndex_X - 1 then |
| 383 |
p^.X := p^.X + 1 |
s.X := s.X + 1 |
| 384 |
else if p^.Y < FIndex_Y - 1 then |
else if s.Y < FIndex_Y - 1 then |
| 385 |
begin |
begin |
| 386 |
p^.X := 0; |
s.X := 0; |
| 387 |
p^.Y := p^.Y + 1; |
s.Y := s.Y + 1; |
| 388 |
end |
end |
| 389 |
else |
else |
| 390 |
begin |
begin |
| 391 |
SetStrings(p^.Left, p^.Top, p^.Stone); |
SetStrings(s.Left, s.Top, FEffectStone); |
| 392 |
Dispose(p); |
FList.Delete(i); |
| 393 |
List[i] := nil; |
inc(i); |
| 394 |
|
continue; |
| 395 |
end; |
end; |
| 396 |
|
FList[i] := s; |
| 397 |
|
inc(i); |
| 398 |
end; |
end; |
| 399 |
for i := List.Count - 1 downto 0 do |
if FList.Count = 0 then |
|
if List[i] = nil then |
|
|
List.Delete(i); |
|
|
if List.Count = 0 then |
|
| 400 |
begin |
begin |
|
FActive := FBool; |
|
| 401 |
inc(FTurnIndex); |
inc(FTurnIndex); |
| 402 |
inc(FTurnNumber); |
inc(FTurnNumber); |
| 403 |
FBuffer[FTurnIndex] := FStrings; |
FBuffer[FTurnIndex] := FStrings; |
| 404 |
|
Form1.PaintBox1.Repaint; |
| 405 |
|
Form1.ChangePlayer; |
| 406 |
|
if FGameOver = false then |
| 407 |
|
FActive := true |
| 408 |
end; |
end; |
| 409 |
result := true; |
result := true; |
| 410 |
end; |
end; |
| 411 |
end; |
end; |
| 412 |
|
|
| 413 |
function TStoneGrid.NextStone(Stone: TStoneType): TPoint; |
function TStoneGrid.NextStone(Stone: TStoneType; var Pos: TPoint): Boolean; |
| 414 |
var |
var |
| 415 |
i, j, m, n: integer; |
i, j, m, n: integer; |
| 416 |
begin |
begin |
| 417 |
n := -1; |
result := false; |
| 418 |
for i := 0 to Count - 1 do |
n := 0; |
| 419 |
for j := 0 to Count - 1 do |
for i := 0 to bmp_count - 1 do |
| 420 |
begin |
for j := 0 to bmp_count - 1 do |
| 421 |
m := CalScore(Stone, i, j); |
if (CalScore(Stone, i, j, m) = true) and ((result = false) or (m < n)) |
| 422 |
if (n = -1) or ((m > -1) and (n > m)) then |
then |
| 423 |
begin |
begin |
| 424 |
|
if result = false then |
| 425 |
|
result := true; |
| 426 |
n := m; |
n := m; |
| 427 |
result := Point(i, j); |
Pos := Point(i, j); |
| 428 |
end; |
end; |
|
end; |
|
|
if n = -1 then |
|
|
result := Point(-1, -1); |
|
| 429 |
end; |
end; |
| 430 |
|
|
| 431 |
procedure TStoneGrid.Paint(Canvas: TCanvas); |
procedure TStoneGrid.Paint(Canvas: TCanvas); |
| 432 |
var |
var |
| 433 |
i: integer; |
k: integer; |
|
k, m, n: integer; |
|
| 434 |
s: TBitmap; |
s: TBitmap; |
| 435 |
p: ^TEffectData; |
p: TEffectData; |
| 436 |
begin |
begin |
|
m := Form1.Image3.Bitmap.Width; |
|
|
n := Form1.Image3.Bitmap.Height; |
|
| 437 |
k := Form1.Size; |
k := Form1.Size; |
| 438 |
for i := 0 to List.Count - 1 do |
if FEffectStone = stBlack then |
| 439 |
|
s := Form1.Image1.Bitmap |
| 440 |
|
else |
| 441 |
|
s := Form1.Image2.Bitmap; |
| 442 |
|
for p in FList do |
| 443 |
begin |
begin |
| 444 |
p := List[i]; |
Canvas.DrawBitmap(s, RectF(p.X * 50, p.Y * 50, (p.X + 1) * 50, |
| 445 |
if p^.Stone = stBlack then |
(p.Y + 1) * 50), RectF(p.Left * k, p.Top * k, (p.Left + 1) * k, |
| 446 |
s := Form1.Image1.Bitmap |
(p.Top + 1) * k), 1); |
|
else |
|
|
s := Form1.Image2.Bitmap; |
|
|
Canvas.DrawBitmap(s, RectF(p^.X * m, p^.Y * n, (p^.X + 1) * m, |
|
|
(p^.Y + 1) * n), RectF(p^.Left * k, p^.Top * k, (p^.Left + 1) * k, |
|
|
(p^.Top + 1) * k), 1); |
|
| 447 |
end; |
end; |
| 448 |
end; |
end; |
| 449 |
|
|
| 450 |
procedure TStoneGrid.Pause; |
procedure TStoneGrid.Pause; |
| 451 |
begin |
begin |
|
FBool := false; |
|
| 452 |
FActive := false; |
FActive := false; |
| 453 |
end; |
end; |
| 454 |
|
|
| 455 |
procedure TStoneGrid.Restart; |
procedure TStoneGrid.Restart; |
| 456 |
begin |
begin |
| 457 |
FActive := true; |
FActive := true; |
| 458 |
|
FGameOver := false; |
| 459 |
FTurnIndex := FTurnNumber; |
FTurnIndex := FTurnNumber; |
| 460 |
end; |
end; |
| 461 |
|
|
| 462 |
|
procedure TStoneGrid.SetActive(const Value: Boolean); |
| 463 |
|
begin |
| 464 |
|
if (FGameOver = false) or (Value = false) then |
| 465 |
|
FActive := Value; |
| 466 |
|
end; |
| 467 |
|
|
| 468 |
procedure TStoneGrid.SetStrings(X, Y: integer; const Value: TStoneType); |
procedure TStoneGrid.SetStrings(X, Y: integer; const Value: TStoneType); |
| 469 |
begin |
begin |
| 470 |
if (X >= 0) and (X < Count) and (Y >= 0) and (Y < Count) then |
if (X >= 0) and (X < bmp_count) and (Y >= 0) and (Y < bmp_count) then |
| 471 |
FStrings[X, Y] := Value; |
FStrings[X, Y] := Value; |
| 472 |
end; |
end; |
| 473 |
|
|
| 479 |
FTurnNumber := 0 |
FTurnNumber := 0 |
| 480 |
else |
else |
| 481 |
FTurnNumber := Value; |
FTurnNumber := Value; |
|
FActive := false; |
|
| 482 |
FStrings := FBuffer[FTurnNumber]; |
FStrings := FBuffer[FTurnNumber]; |
| 483 |
end; |
end; |
| 484 |
|
|
| 486 |
begin |
begin |
| 487 |
Clear; |
Clear; |
| 488 |
FActive := true; |
FActive := true; |
| 489 |
|
FGameOver := false; |
| 490 |
end; |
end; |
| 491 |
|
|
| 492 |
{ TForm1 } |
{ TForm1 } |
| 511 |
function Execute: Boolean; |
function Execute: Boolean; |
| 512 |
var |
var |
| 513 |
i, j: integer; |
i, j: integer; |
|
m: integer; |
|
|
n: integer; |
|
| 514 |
begin |
begin |
| 515 |
|
for i := 0 to bmp_count - 1 do |
| 516 |
|
for j := 0 to bmp_count - 1 do |
| 517 |
|
if StoneGrid.CanSetStone(Index.Stone, i, j, false) = true then |
| 518 |
|
begin |
| 519 |
|
result := true; |
| 520 |
|
Exit; |
| 521 |
|
end; |
| 522 |
result := false; |
result := false; |
|
with StoneGrid do |
|
|
for i := 0 to Count - 1 do |
|
|
for j := 0 to Count - 1 do |
|
|
if CanSetStone(Index.Stone, i, j, false) = true then |
|
|
begin |
|
|
for m := 0 to Count - 1 do |
|
|
for n := 0 to Count - 1 do |
|
|
if GetStrings(m, n) <> Index.Stone then |
|
|
begin |
|
|
result := true; |
|
|
Exit; |
|
|
end; |
|
|
result := false; |
|
|
end; |
|
| 523 |
end; |
end; |
| 524 |
|
|
| 525 |
begin |
begin |
| 529 |
Main; |
Main; |
| 530 |
if Execute = false then |
if Execute = false then |
| 531 |
begin |
begin |
|
Timer1.Enabled := false; |
|
|
StoneGrid.Pause; |
|
| 532 |
m := 0; |
m := 0; |
| 533 |
n := 0; |
n := 0; |
| 534 |
for i := 0 to Count - 1 do |
for i := 0 to bmp_count - 1 do |
| 535 |
for j := 0 to Count - 1 do |
for j := 0 to bmp_count - 1 do |
| 536 |
case StoneGrid[i, j] of |
case StoneGrid[i, j] of |
| 537 |
stBlack: |
stBlack: |
| 538 |
inc(m); |
inc(m); |
| 546 |
s := 'Player2 Win:' + #13#10 |
s := 'Player2 Win:' + #13#10 |
| 547 |
else |
else |
| 548 |
s := 'Draw:' + #13#10; |
s := 'Draw:' + #13#10; |
| 549 |
Showmessage(s + '(Player1) ' + IntToStr(m) + #13#10 + '(Player2) ' + |
StoneGrid.GameOver; |
| 550 |
IntToStr(n)); |
Showmessage(s + '(Player1) ' + m.ToString + #13#10 + '(Player2) ' + |
| 551 |
|
n.ToString); |
| 552 |
end |
end |
| 553 |
else |
else |
| 554 |
Caption := s; |
Caption := s; |
| 561 |
var |
var |
| 562 |
s: TPoint; |
s: TPoint; |
| 563 |
begin |
begin |
| 564 |
s := StoneGrid.NextStone(Index.Stone); |
StoneGrid.Active := false; |
| 565 |
StoneGrid.CanSetStone(Index.Stone, s.X, s.Y, true, true); |
if StoneGrid.NextStone(Index.Stone, s) = true then |
| 566 |
PaintBox1.Repaint; |
begin |
| 567 |
ChangePlayer; |
StoneGrid.CanSetStone(Index.Stone, s.X, s.Y, true, true); |
| 568 |
|
PaintBox1.Repaint; |
| 569 |
|
end |
| 570 |
|
else |
| 571 |
|
ChangePlayer; |
| 572 |
end; |
end; |
| 573 |
|
|
| 574 |
procedure TForm1.GameStart; |
procedure TForm1.GameStart; |
| 575 |
begin |
begin |
| 576 |
|
Index := Player1; |
| 577 |
StoneGrid.Start; |
StoneGrid.Start; |
| 578 |
PaintBox1.Repaint; |
PaintBox1.Repaint; |
|
Index := Player1; |
|
| 579 |
Caption := '黒から始めます'; |
Caption := '黒から始めます'; |
|
Timer1.Enabled := true; |
|
| 580 |
end; |
end; |
| 581 |
|
|
| 582 |
procedure TForm1.MenuItem10Click(Sender: TObject); |
procedure TForm1.MenuItem10Click(Sender: TObject); |
| 583 |
begin |
begin |
| 584 |
StoneGrid.Restart; |
StoneGrid.Restart; |
|
Timer1.Enabled := true; |
|
| 585 |
end; |
end; |
| 586 |
|
|
| 587 |
procedure TForm1.MenuItem11Click(Sender: TObject); |
procedure TForm1.MenuItem11Click(Sender: TObject); |
| 606 |
|
|
| 607 |
procedure TForm1.MenuItem2Click(Sender: TObject); |
procedure TForm1.MenuItem2Click(Sender: TObject); |
| 608 |
begin |
begin |
| 609 |
|
Timer1.Enabled := false; |
| 610 |
|
Timer2.Enabled := false; |
| 611 |
GameStart; |
GameStart; |
| 612 |
|
Timer1.Enabled := true; |
| 613 |
|
Timer2.Enabled := true; |
| 614 |
end; |
end; |
| 615 |
|
|
| 616 |
procedure TForm1.MenuItem4Click(Sender: TObject); |
procedure TForm1.MenuItem4Click(Sender: TObject); |
| 622 |
begin |
begin |
| 623 |
Player1.Auto := MenuItem6.IsChecked; |
Player1.Auto := MenuItem6.IsChecked; |
| 624 |
Player2.Auto := MenuItem7.IsChecked; |
Player2.Auto := MenuItem7.IsChecked; |
|
MenuItem10Click(Sender); |
|
| 625 |
end; |
end; |
| 626 |
|
|
| 627 |
procedure TForm1.MenuItem8Click(Sender: TObject); |
procedure TForm1.MenuItem8Click(Sender: TObject); |
| 633 |
var |
var |
| 634 |
i, j: integer; |
i, j: integer; |
| 635 |
begin |
begin |
| 636 |
for i := 0 to Count - 1 do |
if StoneGrid.Active = false then |
| 637 |
|
StoneGrid.Paint(Canvas); |
| 638 |
|
for i := 0 to bmp_count - 1 do |
| 639 |
begin |
begin |
| 640 |
for j := 0 to Count - 1 do |
for j := 0 to bmp_count - 1 do |
| 641 |
begin |
begin |
| 642 |
case StoneGrid.Strings[i, j] of |
case StoneGrid.Strings[i, j] of |
| 643 |
stWhite: |
stWhite: |
| 644 |
Canvas.DrawBitmap(Image4.Bitmap, RectF(0, 0, Image4.Bitmap.Width, |
Canvas.DrawBitmap(Image3.Bitmap, RectF(100, 0, 150, 50), |
| 645 |
Image4.Bitmap.Height), RectF(i * Size, j * Size, (i + 1) * Size, |
RectF(i * Size, j * Size, (i + 1) * Size, (j + 1) * Size), 1); |
|
(j + 1) * Size), 1); |
|
| 646 |
stBlack: |
stBlack: |
| 647 |
Canvas.DrawBitmap(Image3.Bitmap, RectF(0, 0, Image3.Bitmap.Width, |
Canvas.DrawBitmap(Image3.Bitmap, RectF(50, 0, 100, 50), |
| 648 |
Image3.Bitmap.Height), RectF(i * Size, j * Size, (i + 1) * Size, |
RectF(i * Size, j * Size, (i + 1) * Size, (j + 1) * Size), 1); |
|
(j + 1) * Size), 1); |
|
| 649 |
stEffect: |
stEffect: |
| 650 |
continue; |
continue; |
| 651 |
else |
else |
| 652 |
Canvas.DrawBitmap(Image5.Bitmap, RectF(0, 0, Image5.Bitmap.Width, |
Canvas.DrawBitmap(Image3.Bitmap, RectF(0, 0, 50, 50), |
| 653 |
Image5.Bitmap.Height), RectF(i * Size, j * Size, (i + 1) * Size, |
RectF(i * Size, j * Size, (i + 1) * Size, (j + 1) * Size), 1); |
|
(j + 1) * Size), 1); |
|
| 654 |
end; |
end; |
| 655 |
Canvas.DrawLine(PointF(0, j * Size), PointF(Count * Size, j * Size), 1); |
Canvas.DrawLine(PointF(0, j * Size), PointF(bmp_count * Size, |
| 656 |
|
j * Size), 1); |
| 657 |
end; |
end; |
| 658 |
Canvas.DrawLine(PointF(i * Size, 0), PointF(i * Size, Size * Count), 1); |
Canvas.DrawLine(PointF(i * Size, 0), PointF(i * Size, Size * bmp_count), 1); |
| 659 |
end; |
end; |
| 660 |
Canvas.DrawLine(PointF(Count * Size, 0), |
Canvas.DrawLine(PointF(bmp_count * Size, 0), PointF(bmp_count * Size, |
| 661 |
PointF(Count * Size, Count * Size), 1); |
bmp_count * Size), 1); |
| 662 |
Canvas.DrawLine(PointF(0, Count * Size), |
Canvas.DrawLine(PointF(0, bmp_count * Size), PointF(bmp_count * Size, |
| 663 |
PointF(Count * Size, Count * Size), 1); |
bmp_count * Size), 1); |
|
if StoneGrid.Active = false then |
|
|
StoneGrid.Paint(Canvas); |
|
| 664 |
end; |
end; |
| 665 |
|
|
| 666 |
procedure TForm1.PaintBox1Resize(Sender: TObject); |
procedure TForm1.PaintBox1Resize(Sender: TObject); |
| 667 |
begin |
begin |
| 668 |
Size := Min(ClientWidth, ClientHeight) div Count; |
Size := Min(ClientWidth, ClientHeight) div bmp_count; |
| 669 |
end; |
end; |
| 670 |
|
|
| 671 |
procedure TForm1.FormCreate(Sender: TObject); |
procedure TForm1.FormCreate(Sender: TObject); |
| 672 |
begin |
begin |
| 673 |
|
ClientWidth := 400; |
| 674 |
|
ClientHeight := 400; |
| 675 |
StoneGrid := TStoneGrid.Create; |
StoneGrid := TStoneGrid.Create; |
| 676 |
StoneGrid.ImageCount(Form1.Image1.Bitmap.Width div Form1.Image3.Bitmap.Width, |
StoneGrid.ImageCount(6, 5); |
|
Form1.Image1.Bitmap.Height div Form1.Image3.Bitmap.Height); |
|
| 677 |
Player1 := TPlayer.Create; |
Player1 := TPlayer.Create; |
| 678 |
Player2 := TPlayer.Create; |
Player2 := TPlayer.Create; |
| 679 |
Player1.Stone := stBlack; |
Player1.Stone := stBlack; |
| 705 |
procedure TForm1.Timer1Timer(Sender: TObject); |
procedure TForm1.Timer1Timer(Sender: TObject); |
| 706 |
begin |
begin |
| 707 |
if (StoneGrid.Active = true) and (Index.Auto = true) then |
if (StoneGrid.Active = true) and (Index.Auto = true) then |
|
begin |
|
|
Timer1.Enabled := false; |
|
| 708 |
CompStone; |
CompStone; |
|
Timer1.Enabled := true; |
|
|
end; |
|
| 709 |
end; |
end; |
| 710 |
|
|
| 711 |
procedure TForm1.Timer2Timer(Sender: TObject); |
procedure TForm1.Timer2Timer(Sender: TObject); |
| 712 |
begin |
begin |
| 713 |
if StoneGrid.ListExecute = true then |
if (StoneGrid.Active = false) and (StoneGrid.ListExecute = true) then |
| 714 |
PaintBox1.Repaint; |
PaintBox1.Repaint; |
| 715 |
end; |
end; |
| 716 |
|
|
| 717 |
procedure TForm1.FormResize(Sender: TObject); |
procedure TForm1.FormResize(Sender: TObject); |
| 718 |
begin |
begin |
| 719 |
Size := Min(ClientWidth, ClientHeight) div Count; |
Size := Min(ClientWidth, ClientHeight) div bmp_count; |
| 720 |
PaintTo(Canvas); |
PaintTo(Canvas); |
| 721 |
end; |
end; |
| 722 |
|
|
| 725 |
if Index.Auto = false then |
if Index.Auto = false then |
| 726 |
begin |
begin |
| 727 |
MenuItem10Click(Sender); |
MenuItem10Click(Sender); |
| 728 |
|
StoneGrid.Active := false; |
| 729 |
if StoneGrid.CanSetStone(Index.Stone, Floor(Point.X / Size), |
if StoneGrid.CanSetStone(Index.Stone, Floor(Point.X / Size), |
| 730 |
Floor(Point.Y / Size), true, true) = true then |
Floor(Point.Y / Size), true, true) = true then |
|
begin |
|
| 731 |
PaintBox1.Repaint; |
PaintBox1.Repaint; |
| 732 |
ChangePlayer; |
StoneGrid.Active := true; |
|
end; |
|
| 733 |
end; |
end; |
| 734 |
end; |
end; |
| 735 |
|
|