| 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); |
| 19 |
Left, Top: integer; |
Left, Top: integer; |
| 20 |
end; |
end; |
| 21 |
|
|
| 22 |
TGridData = array [0 .. Count - 1] of array [0 .. Count - 1] of TStoneType; |
TGridData = record |
| 23 |
|
Strings: array [0 .. bmp_count - 1] of array [0 .. bmp_count - 1] |
| 24 |
|
of TStoneType; |
| 25 |
|
Stone: TStoneType; |
| 26 |
|
end; |
| 27 |
|
|
| 28 |
TPlayer = class(TObject) |
TPlayer = class(TObject) |
| 29 |
private |
private |
| 37 |
TStoneGrid = class(TObject) |
TStoneGrid = class(TObject) |
| 38 |
private |
private |
| 39 |
FStrings: TGridData; |
FStrings: TGridData; |
| 40 |
FBuffer: array [0 .. Count * Count - 4] of TGridData; |
FBuffer: array [0 .. bmp_count * bmp_count - 4] of TGridData; |
| 41 |
FTurnNumber: integer; |
FTurnNumber: integer; |
| 42 |
FTurnIndex: integer; |
FTurnIndex: integer; |
| 43 |
FActive: Boolean; |
FActive: Boolean; |
| 44 |
FList: TList; |
FList: TList<TEffectData>; |
| 45 |
FEffectStone: TStoneType; |
FEffectStone: TStoneType; |
| 46 |
FIndex_X: integer; |
FIndex_X: integer; |
| 47 |
FIndex_Y: integer; |
FIndex_Y: integer; |
| 51 |
procedure SetTurnNumber(const Value: integer); |
procedure SetTurnNumber(const Value: integer); |
| 52 |
function GetActive: Boolean; |
function GetActive: Boolean; |
| 53 |
procedure SetActive(const Value: Boolean); |
procedure SetActive(const Value: Boolean); |
| 54 |
|
function GetStone: TStoneType; |
| 55 |
public |
public |
| 56 |
constructor Create; |
constructor Create; |
| 57 |
destructor Destroy; override; |
destructor Destroy; override; |
| 58 |
procedure Clear; |
procedure Clear; |
| 59 |
function CalScore(Stone: TStoneType; X, Y: integer): integer; |
function CalScore(Stone: TStoneType; X, Y: integer; |
| 60 |
|
out Score: integer): Boolean; |
| 61 |
function CanSetStone(Stone: TStoneType; X, Y: integer; Reverse: Boolean; |
function CanSetStone(Stone: TStoneType; X, Y: integer; Reverse: Boolean; |
| 62 |
const Visible: Boolean = false): Boolean; |
const Visible: Boolean = false): Boolean; |
| 63 |
function NextStone(Stone: TStoneType; var Pos: TPoint): Boolean; |
function NextStone(Stone: TStoneType; var Pos: TPoint): Boolean; |
| 73 |
write SetStrings; default; |
write SetStrings; default; |
| 74 |
property TurnNumber: integer read FTurnNumber write SetTurnNumber; |
property TurnNumber: integer read FTurnNumber write SetTurnNumber; |
| 75 |
property Active: Boolean read GetActive write SetActive; |
property Active: Boolean read GetActive write SetActive; |
| 76 |
|
property Stone: TStoneType read GetStone; |
| 77 |
end; |
end; |
| 78 |
|
|
| 79 |
TForm1 = class(TForm) |
TForm1 = class(TForm) |
| 96 |
Image1: TImage; |
Image1: TImage; |
| 97 |
Image2: TImage; |
Image2: TImage; |
| 98 |
Image3: TImage; |
Image3: TImage; |
| 99 |
Image4: TImage; |
MenuItem13: TMenuItem; |
| 100 |
Image5: TImage; |
MenuItem14: TMenuItem; |
| 101 |
|
MenuItem15: TMenuItem; |
| 102 |
procedure FormCreate(Sender: TObject); |
procedure FormCreate(Sender: TObject); |
| 103 |
procedure FormDestroy(Sender: TObject); |
procedure FormDestroy(Sender: TObject); |
| 104 |
procedure Timer1Timer(Sender: TObject); |
procedure Timer1Timer(Sender: TObject); |
| 123 |
procedure CompStone; |
procedure CompStone; |
| 124 |
procedure GameStart; |
procedure GameStart; |
| 125 |
procedure ChangePlayer; |
procedure ChangePlayer; |
| 126 |
|
procedure ChMain(var CapStr: string); |
| 127 |
public |
public |
| 128 |
{ Public 宣言 } |
{ Public 宣言 } |
| 129 |
end; |
end; |
| 139 |
{$R *.fmx} |
{$R *.fmx} |
| 140 |
{$R *.Windows.fmx MSWINDOWS} |
{$R *.Windows.fmx MSWINDOWS} |
| 141 |
{$R *.XLgXhdpiTb.fmx ANDROID} |
{$R *.XLgXhdpiTb.fmx ANDROID} |
|
|
|
| 142 |
{ TStoneGrid } |
{ TStoneGrid } |
| 143 |
|
|
| 144 |
function TStoneGrid.AddScore(X, Y: integer; const NG: array of TPoint): integer; |
function TStoneGrid.AddScore(X, Y: integer; const NG: array of TPoint): integer; |
| 154 |
end; |
end; |
| 155 |
end; |
end; |
| 156 |
|
|
| 157 |
function TStoneGrid.CalScore(Stone: TStoneType; X, Y: integer): integer; |
function TStoneGrid.CalScore(Stone: TStoneType; X, Y: integer; |
| 158 |
|
out Score: integer): Boolean; |
| 159 |
var |
var |
| 160 |
i, j: integer; |
loop: integer; |
| 161 |
|
const |
| 162 |
|
waste: array [1 .. 12] of TPoint = ((X: 1; Y: 0), (X: 6; Y: 0), (X: 0; Y: 1), |
| 163 |
|
(X: 1; Y: 1), (X: 6; Y: 1), (X: 7; Y: 1), (X: 0; Y: 6), (X: 1; Y: 6), (X: 6; |
| 164 |
|
Y: 6), (X: 7; Y: 6), (X: 1; Y: 7), (X: 6; Y: 7)); |
| 165 |
|
worth: array [1 .. 4] of TPoint = ((X: 0; Y: 0), (X: 7; Y: 0), (X: 0; Y: 7), |
| 166 |
|
(X: 7; Y: 7)); |
| 167 |
|
label Last; |
| 168 |
|
procedure Easy; |
| 169 |
|
var |
| 170 |
|
m, n: integer; |
| 171 |
|
begin |
| 172 |
|
for m := 0 to bmp_count - 1 do |
| 173 |
|
for n := 0 to bmp_count - 1 do |
| 174 |
|
if CanSetStone(Stone, m, n, false) = true then |
| 175 |
|
begin |
| 176 |
|
inc(Score); |
| 177 |
|
inc(Score, AddScore(m, n, worth)); |
| 178 |
|
end; |
| 179 |
|
end; |
| 180 |
|
procedure Hard; |
| 181 |
|
var |
| 182 |
|
m, n: integer; |
| 183 |
|
begin |
| 184 |
|
if loop > 1 then |
| 185 |
|
Exit; |
| 186 |
|
inc(loop); |
| 187 |
|
for m := 0 to bmp_count - 1 do |
| 188 |
|
for n := 0 to bmp_count - 1 do |
| 189 |
|
begin |
| 190 |
|
if CanSetStone(Stone, m, n, true) = true then |
| 191 |
|
begin |
| 192 |
|
if (loop mod 2) > 0 then |
| 193 |
|
inc(Score) |
| 194 |
|
else |
| 195 |
|
dec(Score); |
| 196 |
|
case Stone of |
| 197 |
|
stBlack: |
| 198 |
|
Stone := stWhite; |
| 199 |
|
stWhite: |
| 200 |
|
Stone := stBlack; |
| 201 |
|
end; |
| 202 |
|
Hard; |
| 203 |
|
if loop > 1 then |
| 204 |
|
begin |
| 205 |
|
Easy; |
| 206 |
|
FStrings := FBuffer[FTurnIndex + loop]; |
| 207 |
|
end |
| 208 |
|
else |
| 209 |
|
FBuffer[FTurnIndex + loop] := FStrings; |
| 210 |
|
end; |
| 211 |
|
end; |
| 212 |
|
dec(loop); |
| 213 |
|
end; |
| 214 |
|
|
| 215 |
begin |
begin |
| 216 |
if CanSetStone(Stone, X, Y, true) = true then |
if CanSetStone(Stone, X, Y, true) = true then |
| 217 |
begin |
begin |
| 218 |
result := 0; |
Score := 0; |
| 219 |
|
result := true; |
| 220 |
if FTurnIndex < 50 then |
if FTurnIndex < 50 then |
| 221 |
inc(result, AddScore(X, Y, [Point(1, 0), Point(6, 0), Point(0, 1), |
inc(Score, AddScore(X, Y, waste)); |
| 222 |
Point(1, 1), Point(6, 1), Point(7, 1), Point(0, 6), Point(1, 6), |
dec(Score, AddScore(X, Y, worth)); |
|
Point(6, 6), Point(7, 6), Point(1, 7), Point(6, 7)])); |
|
| 223 |
case Stone of |
case Stone of |
| 224 |
stBlack: |
stBlack: |
| 225 |
Stone := stWhite; |
Stone := stWhite; |
| 226 |
stWhite: |
stWhite: |
| 227 |
Stone := stBlack; |
Stone := stBlack; |
| 228 |
end; |
end; |
| 229 |
for i := 0 to Count - 1 do |
if (Form1.MenuItem14.IsChecked = true) and (FTurnIndex + 2 <= 60) then |
| 230 |
for j := 0 to Count - 1 do |
begin |
| 231 |
if CanSetStone(Stone, i, j, false) = true then |
loop := 0; |
| 232 |
begin |
Hard; |
| 233 |
inc(result); |
end |
| 234 |
if FTurnIndex < 50 then |
else |
| 235 |
inc(result, AddScore(i, j, [Point(0, 0), Point(7, 0), Point(0, 7), |
Easy; |
|
Point(7, 7)])); |
|
|
end; |
|
| 236 |
end |
end |
| 237 |
else |
else |
| 238 |
result := -1; |
result := false; |
| 239 |
FStrings := FBuffer[FTurnIndex]; |
FStrings := FBuffer[FTurnIndex]; |
| 240 |
end; |
end; |
| 241 |
|
|
| 244 |
var |
var |
| 245 |
i: integer; |
i: integer; |
| 246 |
p: Boolean; |
p: Boolean; |
| 247 |
q: ^TEffectData; |
q: TEffectData; |
| 248 |
procedure Method(m, n: integer); |
procedure Method(m, n: integer); |
| 249 |
var |
var |
| 250 |
s: TStoneType; |
s: TStoneType; |
| 251 |
j, k: integer; |
j: integer; |
| 252 |
|
k: integer; |
| 253 |
begin |
begin |
| 254 |
if p = false then |
if p = false then |
| 255 |
Exit; |
Exit; |
| 269 |
result := true; |
result := true; |
| 270 |
if Reverse = true then |
if Reverse = true then |
| 271 |
begin |
begin |
| 272 |
|
Form1.PaintBox1.Repaint; |
| 273 |
for j := 1 to i - 1 do |
for j := 1 to i - 1 do |
| 274 |
begin |
begin |
|
Form1.PaintBox1.Repaint; |
|
| 275 |
if Visible = true then |
if Visible = true then |
| 276 |
begin |
begin |
| 277 |
FEffectStone := Stone; |
FEffectStone := Stone; |
| 278 |
New(q); |
q.Left := X + m * j; |
| 279 |
q^.Left := X + m * j; |
q.Top := Y + n * j; |
| 280 |
q^.Top := Y + n * j; |
q.X := 0; |
| 281 |
q^.X := 0; |
q.Y := 0; |
|
q^.Y := 0; |
|
| 282 |
FList.Add(q); |
FList.Add(q); |
| 283 |
SetStrings(q^.Left, q^.Top, stEffect); |
SetStrings(q.Left, q.Top, stEffect); |
| 284 |
for k := 1 to 100 do |
for k := 1 to 10 do |
| 285 |
begin |
begin |
| 286 |
Sleep(1); |
Sleep(15); |
| 287 |
Application.ProcessMessages; |
Application.ProcessMessages; |
| 288 |
end; |
end; |
| 289 |
end |
end |
| 325 |
var |
var |
| 326 |
i, j: integer; |
i, j: integer; |
| 327 |
begin |
begin |
|
for i := 0 to FList.Count - 1 do |
|
|
Dispose(FList[i]); |
|
| 328 |
FList.Clear; |
FList.Clear; |
| 329 |
for i := 0 to Count - 1 do |
for i := 0 to bmp_count - 1 do |
| 330 |
for j := 0 to Count - 1 do |
for j := 0 to bmp_count - 1 do |
| 331 |
Strings[i, j] := stNone; |
Strings[i, j] := stNone; |
| 332 |
Strings[3, 3] := stBlack; |
Strings[3, 3] := stBlack; |
| 333 |
Strings[4, 4] := stBlack; |
Strings[4, 4] := stBlack; |
| 341 |
constructor TStoneGrid.Create; |
constructor TStoneGrid.Create; |
| 342 |
begin |
begin |
| 343 |
inherited; |
inherited; |
| 344 |
FList := TList.Create; |
FList := TList<TEffectData>.Create; |
| 345 |
end; |
end; |
| 346 |
|
|
| 347 |
destructor TStoneGrid.Destroy; |
destructor TStoneGrid.Destroy; |
|
var |
|
|
i: integer; |
|
| 348 |
begin |
begin |
|
for i := 0 to FList.Count - 1 do |
|
|
Dispose(FList[i]); |
|
| 349 |
FList.Free; |
FList.Free; |
| 350 |
inherited; |
inherited; |
| 351 |
end; |
end; |
| 364 |
result := false; |
result := false; |
| 365 |
end; |
end; |
| 366 |
|
|
| 367 |
|
function TStoneGrid.GetStone: TStoneType; |
| 368 |
|
begin |
| 369 |
|
result := FBuffer[FTurnNumber].Stone; |
| 370 |
|
end; |
| 371 |
|
|
| 372 |
function TStoneGrid.GetStrings(X, Y: integer): TStoneType; |
function TStoneGrid.GetStrings(X, Y: integer): TStoneType; |
| 373 |
begin |
begin |
| 374 |
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 |
| 375 |
result := FStrings[X, Y] |
result := FStrings.Strings[X, Y] |
| 376 |
else |
else |
| 377 |
result := stError; |
result := stError; |
| 378 |
end; |
end; |
| 385 |
|
|
| 386 |
function TStoneGrid.ListExecute: Boolean; |
function TStoneGrid.ListExecute: Boolean; |
| 387 |
var |
var |
|
p: ^TEffectData; |
|
| 388 |
i: integer; |
i: integer; |
| 389 |
|
s: TEffectData; |
| 390 |
begin |
begin |
| 391 |
if FList.Count = 0 then |
if FList.Count = 0 then |
| 392 |
result := false |
result := false |
| 393 |
else |
else |
| 394 |
begin |
begin |
| 395 |
for i := 0 to FList.Count - 1 do |
i := 0; |
| 396 |
|
while i < FList.Count do |
| 397 |
begin |
begin |
| 398 |
p := FList[i]; |
s := FList[i]; |
| 399 |
if p^.X < FIndex_X - 1 then |
if s.X < FIndex_X - 1 then |
| 400 |
p^.X := p^.X + 1 |
s.X := s.X + 1 |
| 401 |
else if p^.Y < FIndex_Y - 1 then |
else if s.Y < FIndex_Y - 1 then |
| 402 |
begin |
begin |
| 403 |
p^.X := 0; |
s.X := 0; |
| 404 |
p^.Y := p^.Y + 1; |
s.Y := s.Y + 1; |
| 405 |
end |
end |
| 406 |
else |
else |
| 407 |
begin |
begin |
| 408 |
SetStrings(p^.Left, p^.Top, FEffectStone); |
SetStrings(s.Left, s.Top, FEffectStone); |
| 409 |
Dispose(p); |
FList.Delete(i); |
| 410 |
FList[i] := nil; |
inc(i); |
| 411 |
|
continue; |
| 412 |
end; |
end; |
| 413 |
|
FList[i] := s; |
| 414 |
|
inc(i); |
| 415 |
end; |
end; |
|
for i := FList.Count - 1 downto 0 do |
|
|
if FList[i] = nil then |
|
|
FList.Delete(i); |
|
| 416 |
if FList.Count = 0 then |
if FList.Count = 0 then |
| 417 |
begin |
begin |
| 418 |
inc(FTurnIndex); |
inc(FTurnIndex); |
| 419 |
inc(FTurnNumber); |
inc(FTurnNumber); |
| 420 |
FBuffer[FTurnIndex] := FStrings; |
FBuffer[FTurnIndex] := FStrings; |
| 421 |
|
FBuffer[FTurnIndex].Stone := FEffectStone; |
| 422 |
|
Form1.PaintBox1.Repaint; |
| 423 |
|
Form1.ChangePlayer; |
| 424 |
if FGameOver = false then |
if FGameOver = false then |
| 425 |
begin |
FActive := true |
|
Form1.ChangePlayer; |
|
|
FActive:=true; |
|
|
end; |
|
| 426 |
end; |
end; |
| 427 |
result := true; |
result := true; |
| 428 |
end; |
end; |
| 432 |
var |
var |
| 433 |
i, j, m, n: integer; |
i, j, m, n: integer; |
| 434 |
begin |
begin |
| 435 |
n := -1; |
result := false; |
| 436 |
for i := 0 to Count - 1 do |
n := 0; |
| 437 |
for j := 0 to Count - 1 do |
for i := 0 to bmp_count - 1 do |
| 438 |
begin |
for j := 0 to bmp_count - 1 do |
| 439 |
m := CalScore(Stone, i, j); |
if (CalScore(Stone, i, j, m) = true) and ((result = false) or (m < n)) |
| 440 |
if (n = -1) or ((0 < m) and (m < n)) then |
then |
| 441 |
begin |
begin |
| 442 |
|
if result = false then |
| 443 |
|
result := true; |
| 444 |
n := m; |
n := m; |
| 445 |
Pos := Point(i, j); |
Pos := Point(i, j); |
| 446 |
end; |
end; |
|
end; |
|
|
result := not(n = -1); |
|
| 447 |
end; |
end; |
| 448 |
|
|
| 449 |
procedure TStoneGrid.Paint(Canvas: TCanvas); |
procedure TStoneGrid.Paint(Canvas: TCanvas); |
| 450 |
var |
var |
| 451 |
i: integer; |
k: integer; |
|
k, m, n: integer; |
|
| 452 |
s: TBitmap; |
s: TBitmap; |
| 453 |
p: ^TEffectData; |
p: TEffectData; |
| 454 |
begin |
begin |
|
m := Form1.Image3.Bitmap.Width; |
|
|
n := Form1.Image3.Bitmap.Height; |
|
| 455 |
k := Form1.Size; |
k := Form1.Size; |
| 456 |
for i := 0 to FList.Count - 1 do |
if FEffectStone = stBlack then |
| 457 |
|
s := Form1.Image1.Bitmap |
| 458 |
|
else |
| 459 |
|
s := Form1.Image2.Bitmap; |
| 460 |
|
for p in FList do |
| 461 |
begin |
begin |
| 462 |
p := FList[i]; |
Canvas.DrawBitmap(s, RectF(p.X * 50, p.Y * 50, (p.X + 1) * 50, |
| 463 |
if FEffectStone = stBlack then |
(p.Y + 1) * 50), RectF(p.Left * k, p.Top * k, (p.Left + 1) * k, |
| 464 |
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); |
|
| 465 |
end; |
end; |
| 466 |
end; |
end; |
| 467 |
|
|
| 472 |
|
|
| 473 |
procedure TStoneGrid.Restart; |
procedure TStoneGrid.Restart; |
| 474 |
begin |
begin |
| 475 |
FActive:=true; |
FActive := true; |
| 476 |
FGameOver := false; |
FGameOver := false; |
| 477 |
FTurnIndex := FTurnNumber; |
FTurnIndex := FTurnNumber; |
| 478 |
end; |
end; |
| 479 |
|
|
| 480 |
procedure TStoneGrid.SetActive(const Value: Boolean); |
procedure TStoneGrid.SetActive(const Value: Boolean); |
| 481 |
begin |
begin |
| 482 |
if (FGameOver = false)or(Value = false) then |
if (FGameOver = false) or (Value = false) then |
| 483 |
FActive := Value; |
FActive := Value; |
| 484 |
end; |
end; |
| 485 |
|
|
| 486 |
procedure TStoneGrid.SetStrings(X, Y: integer; const Value: TStoneType); |
procedure TStoneGrid.SetStrings(X, Y: integer; const Value: TStoneType); |
| 487 |
begin |
begin |
| 488 |
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 |
| 489 |
FStrings[X, Y] := Value; |
FStrings.Strings[X, Y] := Value; |
| 490 |
end; |
end; |
| 491 |
|
|
| 492 |
procedure TStoneGrid.SetTurnNumber(const Value: integer); |
procedure TStoneGrid.SetTurnNumber(const Value: integer); |
| 513 |
var |
var |
| 514 |
i, j, m, n: integer; |
i, j, m, n: integer; |
| 515 |
s: string; |
s: string; |
|
procedure Main; |
|
|
begin |
|
|
if Index = Player1 then |
|
|
begin |
|
|
Index := Player2; |
|
|
s := '白の手番です'; |
|
|
end |
|
|
else |
|
|
begin |
|
|
Index := Player1; |
|
|
s := '黒の手番です'; |
|
|
end; |
|
|
end; |
|
| 516 |
function Execute: Boolean; |
function Execute: Boolean; |
| 517 |
var |
var |
| 518 |
i, j: integer; |
i, j: integer; |
| 519 |
begin |
begin |
| 520 |
for i := 0 to Count - 1 do |
for i := 0 to bmp_count - 1 do |
| 521 |
for j := 0 to Count - 1 do |
for j := 0 to bmp_count - 1 do |
| 522 |
if StoneGrid.CanSetStone(Index.Stone, i, j, false) = true then |
if StoneGrid.CanSetStone(Index.Stone, i, j, false) = true then |
| 523 |
begin |
begin |
| 524 |
result := true; |
result := true; |
| 528 |
end; |
end; |
| 529 |
|
|
| 530 |
begin |
begin |
| 531 |
Main; |
s := ''; |
| 532 |
|
ChMain(s); |
| 533 |
if Execute = false then |
if Execute = false then |
| 534 |
begin |
begin |
| 535 |
Main; |
ChMain(s); |
| 536 |
if Execute = false then |
if Execute = false then |
| 537 |
begin |
begin |
| 538 |
m := 0; |
m := 0; |
| 539 |
n := 0; |
n := 0; |
| 540 |
for i := 0 to Count - 1 do |
for i := 0 to bmp_count - 1 do |
| 541 |
for j := 0 to Count - 1 do |
for j := 0 to bmp_count - 1 do |
| 542 |
case StoneGrid[i, j] of |
case StoneGrid[i, j] of |
| 543 |
stBlack: |
stBlack: |
| 544 |
inc(m); |
inc(m); |
| 545 |
stWhite: |
stWhite: |
| 546 |
inc(n); |
inc(n); |
| 547 |
end; |
end; |
| 548 |
Caption := s; |
ChMain(s); |
| 549 |
|
Caption := '終了しました'; |
| 550 |
if m > n then |
if m > n then |
| 551 |
s := 'Player1 Win:' + #13#10 |
s := 'Player1 Win:' + #13#10 |
| 552 |
else if m < n then |
else if m < n then |
| 554 |
else |
else |
| 555 |
s := 'Draw:' + #13#10; |
s := 'Draw:' + #13#10; |
| 556 |
StoneGrid.GameOver; |
StoneGrid.GameOver; |
| 557 |
Showmessage(s + '(Player1) ' + IntToStr(m) + #13#10 + '(Player2) ' + |
Showmessage(s + '(Player1) ' + m.ToString + #13#10 + '(Player2) ' + |
| 558 |
IntToStr(n)); |
n.ToString); |
| 559 |
end |
end |
| 560 |
else |
else |
| 561 |
Caption := s; |
Caption := s; |
| 564 |
Caption := s; |
Caption := s; |
| 565 |
end; |
end; |
| 566 |
|
|
| 567 |
|
procedure TForm1.ChMain(var CapStr: string); |
| 568 |
|
begin |
| 569 |
|
CapStr := (StoneGrid.TurnNumber + 1).ToString + '手目:'; |
| 570 |
|
if Index = Player1 then |
| 571 |
|
begin |
| 572 |
|
Index := Player2; |
| 573 |
|
CapStr := CapStr + '白の手番です'; |
| 574 |
|
end |
| 575 |
|
else |
| 576 |
|
begin |
| 577 |
|
Index := Player1; |
| 578 |
|
CapStr := CapStr + '黒の手番です'; |
| 579 |
|
end; |
| 580 |
|
end; |
| 581 |
|
|
| 582 |
procedure TForm1.CompStone; |
procedure TForm1.CompStone; |
| 583 |
var |
var |
| 584 |
s: TPoint; |
s: TPoint; |
| 585 |
begin |
begin |
| 586 |
StoneGrid.Active := false; |
StoneGrid.Active := false; |
| 587 |
StoneGrid.NextStone(Index.Stone, s); |
if StoneGrid.NextStone(Index.Stone, s) = true then |
| 588 |
StoneGrid.CanSetStone(Index.Stone, s.X, s.Y, true, true); |
begin |
| 589 |
PaintBox1.Repaint; |
StoneGrid.CanSetStone(Index.Stone, s.X, s.Y, true, true); |
| 590 |
|
PaintBox1.Repaint; |
| 591 |
|
end |
| 592 |
|
else |
| 593 |
|
ChangePlayer; |
| 594 |
end; |
end; |
| 595 |
|
|
| 596 |
procedure TForm1.GameStart; |
procedure TForm1.GameStart; |
| 598 |
Index := Player1; |
Index := Player1; |
| 599 |
StoneGrid.Start; |
StoneGrid.Start; |
| 600 |
PaintBox1.Repaint; |
PaintBox1.Repaint; |
| 601 |
Caption := '黒から始めます'; |
Caption := '1手目:黒から始めます'; |
| 602 |
end; |
end; |
| 603 |
|
|
| 604 |
procedure TForm1.MenuItem10Click(Sender: TObject); |
procedure TForm1.MenuItem10Click(Sender: TObject); |
| 609 |
procedure TForm1.MenuItem11Click(Sender: TObject); |
procedure TForm1.MenuItem11Click(Sender: TObject); |
| 610 |
var |
var |
| 611 |
i: integer; |
i: integer; |
| 612 |
|
s: string; |
| 613 |
begin |
begin |
| 614 |
with StoneGrid do |
with StoneGrid do |
| 615 |
begin |
begin |
| 622 |
Exit |
Exit |
| 623 |
else |
else |
| 624 |
Pause; |
Pause; |
| 625 |
|
PaintBox1.Repaint; |
| 626 |
|
s := ''; |
| 627 |
|
if ((TurnNumber = 0) and (Index <> Player1)) or |
| 628 |
|
(Index.Stone = FBuffer[TurnNumber].Stone) then |
| 629 |
|
begin |
| 630 |
|
if TurnNumber = 60 then |
| 631 |
|
ChangePlayer |
| 632 |
|
else |
| 633 |
|
begin |
| 634 |
|
ChMain(s); |
| 635 |
|
Caption := s; |
| 636 |
|
end; |
| 637 |
|
end |
| 638 |
|
else |
| 639 |
|
begin |
| 640 |
|
ChMain(s); |
| 641 |
|
Caption := s; |
| 642 |
|
if Index = Player1 then |
| 643 |
|
Index := Player2 |
| 644 |
|
else |
| 645 |
|
Index := Player1; |
| 646 |
|
end; |
| 647 |
end; |
end; |
|
PaintBox1.Repaint; |
|
|
ChangePlayer; |
|
| 648 |
end; |
end; |
| 649 |
|
|
| 650 |
procedure TForm1.MenuItem2Click(Sender: TObject); |
procedure TForm1.MenuItem2Click(Sender: TObject); |
| 678 |
begin |
begin |
| 679 |
if StoneGrid.Active = false then |
if StoneGrid.Active = false then |
| 680 |
StoneGrid.Paint(Canvas); |
StoneGrid.Paint(Canvas); |
| 681 |
for i := 0 to Count - 1 do |
for i := 0 to bmp_count - 1 do |
| 682 |
begin |
begin |
| 683 |
for j := 0 to Count - 1 do |
for j := 0 to bmp_count - 1 do |
| 684 |
begin |
begin |
| 685 |
case StoneGrid.Strings[i, j] of |
case StoneGrid.Strings[i, j] of |
| 686 |
stWhite: |
stWhite: |
| 687 |
Canvas.DrawBitmap(Image4.Bitmap, RectF(0, 0, Image4.Bitmap.Width, |
Canvas.DrawBitmap(Image3.Bitmap, RectF(100, 0, 150, 50), |
| 688 |
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); |
|
| 689 |
stBlack: |
stBlack: |
| 690 |
Canvas.DrawBitmap(Image3.Bitmap, RectF(0, 0, Image3.Bitmap.Width, |
Canvas.DrawBitmap(Image3.Bitmap, RectF(50, 0, 100, 50), |
| 691 |
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); |
|
| 692 |
stEffect: |
stEffect: |
| 693 |
continue; |
continue; |
| 694 |
else |
else |
| 695 |
Canvas.DrawBitmap(Image5.Bitmap, RectF(0, 0, Image5.Bitmap.Width, |
Canvas.DrawBitmap(Image3.Bitmap, RectF(0, 0, 50, 50), |
| 696 |
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); |
|
| 697 |
end; |
end; |
| 698 |
Canvas.DrawLine(PointF(0, j * Size), PointF(Count * Size, j * Size), 1); |
Canvas.DrawLine(PointF(0, j * Size), PointF(bmp_count * Size, |
| 699 |
|
j * Size), 1); |
| 700 |
end; |
end; |
| 701 |
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); |
| 702 |
end; |
end; |
| 703 |
Canvas.DrawLine(PointF(Count * Size, 0), |
Canvas.DrawLine(PointF(bmp_count * Size, 0), PointF(bmp_count * Size, |
| 704 |
PointF(Count * Size, Count * Size), 1); |
bmp_count * Size), 1); |
| 705 |
Canvas.DrawLine(PointF(0, Count * Size), |
Canvas.DrawLine(PointF(0, bmp_count * Size), PointF(bmp_count * Size, |
| 706 |
PointF(Count * Size, Count * Size), 1); |
bmp_count * Size), 1); |
| 707 |
end; |
end; |
| 708 |
|
|
| 709 |
procedure TForm1.PaintBox1Resize(Sender: TObject); |
procedure TForm1.PaintBox1Resize(Sender: TObject); |
| 710 |
begin |
begin |
| 711 |
Size := Min(ClientWidth, ClientHeight) div Count; |
Size := Min(ClientWidth, ClientHeight) div bmp_count; |
| 712 |
end; |
end; |
| 713 |
|
|
| 714 |
procedure TForm1.FormCreate(Sender: TObject); |
procedure TForm1.FormCreate(Sender: TObject); |
| 715 |
begin |
begin |
| 716 |
ClientWidth:=20*Count; |
ClientWidth := 400; |
| 717 |
ClientHeight:=20*Count; |
ClientHeight := 400; |
| 718 |
StoneGrid := TStoneGrid.Create; |
StoneGrid := TStoneGrid.Create; |
| 719 |
StoneGrid.ImageCount(Form1.Image1.Bitmap.Width div Form1.Image3.Bitmap.Width, |
StoneGrid.ImageCount(6, 5); |
|
Form1.Image1.Bitmap.Height div Form1.Image3.Bitmap.Height); |
|
| 720 |
Player1 := TPlayer.Create; |
Player1 := TPlayer.Create; |
| 721 |
Player2 := TPlayer.Create; |
Player2 := TPlayer.Create; |
| 722 |
Player1.Stone := stBlack; |
Player1.Stone := stBlack; |
| 759 |
|
|
| 760 |
procedure TForm1.FormResize(Sender: TObject); |
procedure TForm1.FormResize(Sender: TObject); |
| 761 |
begin |
begin |
| 762 |
Size := Min(ClientWidth, ClientHeight) div Count; |
Size := Min(ClientWidth, ClientHeight) div bmp_count; |
| 763 |
PaintTo(Canvas); |
PaintTo(Canvas); |
| 764 |
end; |
end; |
| 765 |
|
|
| 767 |
begin |
begin |
| 768 |
if Index.Auto = false then |
if Index.Auto = false then |
| 769 |
begin |
begin |
| 770 |
MenuItem10Click(Sender); |
StoneGrid.Restart; |
| 771 |
StoneGrid.Active := false; |
if (StoneGrid.Active = true) and |
| 772 |
if StoneGrid.CanSetStone(Index.Stone, Floor(Point.X / Size), |
(StoneGrid.CanSetStone(Index.Stone, Floor(Point.X / Size), |
| 773 |
Floor(Point.Y / Size), true, true) = true then |
Floor(Point.Y / Size), true, true) = true) then |
| 774 |
|
begin |
| 775 |
|
StoneGrid.Active := false; |
| 776 |
PaintBox1.Repaint; |
PaintBox1.Repaint; |
| 777 |
StoneGrid.Active := true; |
StoneGrid.Active := true; |
| 778 |
|
end; |
| 779 |
end; |
end; |
| 780 |
end; |
end; |
| 781 |
|
|