| 1 |
unit Unit1; |
| 2 |
|
| 3 |
interface |
| 4 |
|
| 5 |
uses |
| 6 |
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, |
| 7 |
System.Classes, Vcl.Graphics, |
| 8 |
Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.ExtCtrls, Vcl.AppEvnts, Vcl.Menus; |
| 9 |
|
| 10 |
const |
| 11 |
Count = 4; |
| 12 |
Size = 16; |
| 13 |
Wid = 10; |
| 14 |
Hei = 15; |
| 15 |
|
| 16 |
pos_X = Wid div 2; |
| 17 |
pos_Y = 0; |
| 18 |
|
| 19 |
type |
| 20 |
TBall = class(TObject) |
| 21 |
public |
| 22 |
X, Y: integer; |
| 23 |
Color: TColor; |
| 24 |
Index: integer; |
| 25 |
constructor Craete; |
| 26 |
end; |
| 27 |
|
| 28 |
TItem = class(TObject) |
| 29 |
private |
| 30 |
function GetColors(X: integer): TBall; |
| 31 |
procedure SetColors(X: integer; const Value: TBall); |
| 32 |
procedure SetLeft(const Value: integer); |
| 33 |
procedure SetTop(const Value: integer); |
| 34 |
function GetLeft: integer; |
| 35 |
protected |
| 36 |
FColors: array [0 .. Count - 1] of TBall; |
| 37 |
public |
| 38 |
Horizontal: Boolean; |
| 39 |
Visible: Boolean; |
| 40 |
constructor Create; |
| 41 |
destructor Destroy; override; |
| 42 |
procedure Clean; |
| 43 |
procedure Assign(Source: TItem); |
| 44 |
property Colors[X: integer]: TBall read GetColors write SetColors; |
| 45 |
property Left: integer read GetLeft write SetLeft; |
| 46 |
property Top: integer write SetTop; |
| 47 |
end; |
| 48 |
|
| 49 |
TGround = class(TObject) |
| 50 |
private |
| 51 |
function GetStrings(X, Y: integer): TBall; |
| 52 |
procedure SetStrings(X, Y: integer; const Value: TBall); |
| 53 |
protected |
| 54 |
FStrings: array [0 .. Wid - 1, 0 .. Hei - 1] of TBall; |
| 55 |
public |
| 56 |
Left, Top: integer; |
| 57 |
constructor Create; |
| 58 |
destructor Destroy; override; |
| 59 |
procedure Clean; |
| 60 |
procedure Assign(Source: TGround); |
| 61 |
property Strings[X, Y: integer]: TBall read GetStrings |
| 62 |
write SetStrings; default; |
| 63 |
end; |
| 64 |
|
| 65 |
TState = (Down, Shoot, Sys, Stop, Ojama, Effect); |
| 66 |
|
| 67 |
TDirector = (Under, Left, Right); |
| 68 |
|
| 69 |
TOjamaEvent = procedure(Sender: TObject; Count: integer; const Text: string) |
| 70 |
of object; |
| 71 |
|
| 72 |
TGameParam = record |
| 73 |
Rensa: integer; |
| 74 |
Kazu: integer; |
| 75 |
Group: integer; |
| 76 |
end; |
| 77 |
|
| 78 |
TScoreEvent = procedure(Sender: TObject; const GameParam: TGameParam; |
| 79 |
var Score: integer) of object; |
| 80 |
|
| 81 |
TPlayer = class(TObject) |
| 82 |
private |
| 83 |
Test: TItem; |
| 84 |
FOnCreateOjama: TOjamaEvent; |
| 85 |
BackGround: Boolean; |
| 86 |
FOnScoreEvent: TScoreEvent; |
| 87 |
FOnTextMessage: TNotifyEvent; |
| 88 |
function Check(aItem: TItem): Boolean; |
| 89 |
public |
| 90 |
Temp: TItem; |
| 91 |
Item: TItem; |
| 92 |
Ground: TGround; |
| 93 |
State: TState; |
| 94 |
Com: Boolean; |
| 95 |
Score: integer; |
| 96 |
OjamaList: TList; |
| 97 |
OjamaColor: TColor; |
| 98 |
EffectCount: integer; |
| 99 |
GameParam: TGameParam; |
| 100 |
TextColor: TColor; |
| 101 |
Name: string; |
| 102 |
constructor Create; |
| 103 |
destructor Destroy; override; |
| 104 |
procedure Start(const Resume: Boolean = false); |
| 105 |
procedure Execute; |
| 106 |
procedure Think; |
| 107 |
procedure Make(aCount: integer); |
| 108 |
procedure OjamaClean; |
| 109 |
function Remove: Boolean; |
| 110 |
function Move(Dir: TDirector): Boolean; |
| 111 |
function Turn(const Right: Boolean = true): Boolean; |
| 112 |
function Drop: Boolean; |
| 113 |
function Zenkesi: Boolean; |
| 114 |
property OnCreateOjama: TOjamaEvent read FOnCreateOjama |
| 115 |
write FOnCreateOjama; |
| 116 |
property OnScore: TScoreEvent read FOnScoreEvent write FOnScoreEvent; |
| 117 |
end; |
| 118 |
|
| 119 |
TForm1 = class(TForm) |
| 120 |
ApplicationEvents1: TApplicationEvents; |
| 121 |
MainMenu1: TMainMenu; |
| 122 |
Game1: TMenuItem; |
| 123 |
Start1: TMenuItem; |
| 124 |
N1: TMenuItem; |
| 125 |
Close1: TMenuItem; |
| 126 |
Com1: TMenuItem; |
| 127 |
Player11: TMenuItem; |
| 128 |
Player21: TMenuItem; |
| 129 |
procedure FormCreate(Sender: TObject); |
| 130 |
procedure FormDestroy(Sender: TObject); |
| 131 |
procedure FormPaint(Sender: TObject); |
| 132 |
procedure FormKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState); |
| 133 |
procedure ApplicationEvents1Idle(Sender: TObject; var Done: Boolean); |
| 134 |
procedure Player11Click(Sender: TObject); |
| 135 |
procedure Start1Click(Sender: TObject); |
| 136 |
procedure Close1Click(Sender: TObject); |
| 137 |
private |
| 138 |
{ Private ���� } |
| 139 |
Buffer: TBitmap; |
| 140 |
TextMessage: string; |
| 141 |
Limit: TTime; |
| 142 |
public |
| 143 |
{ Public ���� } |
| 144 |
Player1, Player2: TPlayer; |
| 145 |
Rensa: TThread; |
| 146 |
procedure CreateOjama(Sender: TObject; aCount: integer; const Text: string); |
| 147 |
procedure PlayerScore(Sender: TObject; const GameParam: TGameParam; |
| 148 |
var Score: integer); |
| 149 |
end; |
| 150 |
|
| 151 |
var |
| 152 |
Form1: TForm1; |
| 153 |
|
| 154 |
implementation |
| 155 |
|
| 156 |
{$R *.dfm} |
| 157 |
|
| 158 |
uses Unit2; |
| 159 |
|
| 160 |
{ TBall } |
| 161 |
|
| 162 |
constructor TBall.Craete; |
| 163 |
begin |
| 164 |
inherited; |
| 165 |
Color := clWhite; |
| 166 |
end; |
| 167 |
|
| 168 |
{ TItem } |
| 169 |
|
| 170 |
procedure TItem.Assign(Source: TItem); |
| 171 |
var |
| 172 |
i: integer; |
| 173 |
begin |
| 174 |
Horizontal := Source.Horizontal; |
| 175 |
for i := 0 to Count - 1 do |
| 176 |
begin |
| 177 |
FColors[i].Color := Source.Colors[i].Color; |
| 178 |
FColors[i].X := Source.Colors[i].X; |
| 179 |
FColors[i].Y := Source.Colors[i].Y; |
| 180 |
end; |
| 181 |
end; |
| 182 |
|
| 183 |
procedure TItem.Clean; |
| 184 |
var |
| 185 |
i, j: integer; |
| 186 |
begin |
| 187 |
Horizontal := false; |
| 188 |
Randomize; |
| 189 |
for i := 0 to Count - 1 do |
| 190 |
begin |
| 191 |
FColors[i].X := pos_X; |
| 192 |
FColors[i].Y := pos_Y + i; |
| 193 |
j := Random(5); |
| 194 |
case j of |
| 195 |
0: |
| 196 |
FColors[i].Color := clRed; |
| 197 |
1: |
| 198 |
FColors[i].Color := clBlue; |
| 199 |
2: |
| 200 |
FColors[i].Color := clYellow; |
| 201 |
3: |
| 202 |
FColors[i].Color := clGreen; |
| 203 |
4: |
| 204 |
FColors[i].Color := clPurple; |
| 205 |
end; |
| 206 |
end; |
| 207 |
end; |
| 208 |
|
| 209 |
constructor TItem.Create; |
| 210 |
var |
| 211 |
i: integer; |
| 212 |
begin |
| 213 |
inherited; |
| 214 |
for i := 0 to Count - 1 do |
| 215 |
FColors[i] := TBall.Craete; |
| 216 |
Clean; |
| 217 |
end; |
| 218 |
|
| 219 |
destructor TItem.Destroy; |
| 220 |
var |
| 221 |
i: integer; |
| 222 |
begin |
| 223 |
for i := 0 to Count - 1 do |
| 224 |
FColors[i].Free; |
| 225 |
inherited; |
| 226 |
end; |
| 227 |
|
| 228 |
function TItem.GetColors(X: integer): TBall; |
| 229 |
begin |
| 230 |
result := FColors[X]; |
| 231 |
end; |
| 232 |
|
| 233 |
function TItem.GetLeft: integer; |
| 234 |
begin |
| 235 |
if Horizontal = true then |
| 236 |
result := Colors[0].X |
| 237 |
else |
| 238 |
result := Colors[Count - 1].X; |
| 239 |
end; |
| 240 |
|
| 241 |
procedure TItem.SetColors(X: integer; const Value: TBall); |
| 242 |
begin |
| 243 |
FColors[X] := Value; |
| 244 |
end; |
| 245 |
|
| 246 |
procedure TItem.SetLeft(const Value: integer); |
| 247 |
var |
| 248 |
i: integer; |
| 249 |
j: integer; |
| 250 |
begin |
| 251 |
j := Value - Colors[0].X; |
| 252 |
for i := 0 to Count - 1 do |
| 253 |
Colors[i].X := Colors[i].X + j; |
| 254 |
end; |
| 255 |
|
| 256 |
procedure TItem.SetTop(const Value: integer); |
| 257 |
var |
| 258 |
i: integer; |
| 259 |
j: integer; |
| 260 |
begin |
| 261 |
j := Value - Colors[0].Y; |
| 262 |
for i := 0 to Count - 1 do |
| 263 |
Colors[i].Y := Colors[i].Y + j; |
| 264 |
end; |
| 265 |
|
| 266 |
{ TGround } |
| 267 |
|
| 268 |
procedure TGround.Assign(Source: TGround); |
| 269 |
var |
| 270 |
i: integer; |
| 271 |
j: integer; |
| 272 |
begin |
| 273 |
for i := 0 to Wid - 1 do |
| 274 |
for j := 0 to Hei - 1 do |
| 275 |
begin |
| 276 |
Strings[i, j].Color := Source[i, j].Color; |
| 277 |
Strings[i, j].Index := Source[i, j].Index; |
| 278 |
end; |
| 279 |
end; |
| 280 |
|
| 281 |
procedure TGround.Clean; |
| 282 |
var |
| 283 |
i: integer; |
| 284 |
j: integer; |
| 285 |
begin |
| 286 |
for i := 0 to Wid - 1 do |
| 287 |
for j := 0 to Hei - 1 do |
| 288 |
FStrings[i, j].Color := clWhite; |
| 289 |
end; |
| 290 |
|
| 291 |
constructor TGround.Create; |
| 292 |
var |
| 293 |
i: integer; |
| 294 |
j: integer; |
| 295 |
begin |
| 296 |
inherited; |
| 297 |
for i := 0 to Wid - 1 do |
| 298 |
for j := 0 to Hei - 1 do |
| 299 |
FStrings[i, j] := TBall.Craete; |
| 300 |
Clean; |
| 301 |
end; |
| 302 |
|
| 303 |
destructor TGround.Destroy; |
| 304 |
var |
| 305 |
i: integer; |
| 306 |
j: integer; |
| 307 |
begin |
| 308 |
for i := 0 to Wid - 1 do |
| 309 |
for j := 0 to Hei - 1 do |
| 310 |
FStrings[i, j].Free; |
| 311 |
inherited; |
| 312 |
end; |
| 313 |
|
| 314 |
function TGround.GetStrings(X, Y: integer): TBall; |
| 315 |
begin |
| 316 |
if (X < 0) or (Wid - 1 < X) or (Y < 0) or (Hei - 1 < Y) then |
| 317 |
result := nil |
| 318 |
else |
| 319 |
result := FStrings[X, Y]; |
| 320 |
end; |
| 321 |
|
| 322 |
procedure TGround.SetStrings(X, Y: integer; const Value: TBall); |
| 323 |
begin |
| 324 |
FStrings[X, Y] := Value; |
| 325 |
end; |
| 326 |
|
| 327 |
procedure TForm1.ApplicationEvents1Idle(Sender: TObject; var Done: Boolean); |
| 328 |
begin |
| 329 |
if Player1.State <> Stop then |
| 330 |
begin |
| 331 |
if Player2.State = Stop then |
| 332 |
begin |
| 333 |
TextMessage := 'Player1 WIN !!'; |
| 334 |
Player1.State := Stop; |
| 335 |
end; |
| 336 |
Player1.Execute; |
| 337 |
FormPaint(Player1); |
| 338 |
Done := false; |
| 339 |
end |
| 340 |
else if Player2.State <> Stop then |
| 341 |
begin |
| 342 |
TextMessage := 'Player2 WIN !!'; |
| 343 |
Player2.State := Stop; |
| 344 |
end; |
| 345 |
end; |
| 346 |
|
| 347 |
procedure TForm1.Close1Click(Sender: TObject); |
| 348 |
begin |
| 349 |
Close; |
| 350 |
end; |
| 351 |
|
| 352 |
procedure TForm1.CreateOjama(Sender: TObject; aCount: integer; |
| 353 |
const Text: string); |
| 354 |
begin |
| 355 |
if Sender = Player1 then |
| 356 |
if aCount = 0 then |
| 357 |
TextMessage := 'Player2 WIN !!' |
| 358 |
else |
| 359 |
Player2.Make(aCount) |
| 360 |
else if aCount = 0 then |
| 361 |
TextMessage := 'Player1 WIN !!' |
| 362 |
else |
| 363 |
Player1.Make(aCount); |
| 364 |
if aCount > 0 then |
| 365 |
TextMessage := Text; |
| 366 |
Buffer.Canvas.Font.Color := (Sender as TPlayer).TextColor; |
| 367 |
Limit := Time + 1 / (24 * 60 * 60); |
| 368 |
Paint; |
| 369 |
end; |
| 370 |
|
| 371 |
procedure TForm1.FormCreate(Sender: TObject); |
| 372 |
begin |
| 373 |
Buffer := TBitmap.Create; |
| 374 |
Player1 := TPlayer.Create; |
| 375 |
Player2 := TPlayer.Create; |
| 376 |
Player2.Ground.Left := Player1.Ground.Left + (Size + 2) * Wid; |
| 377 |
Player1.OnCreateOjama := CreateOjama; |
| 378 |
Player2.OnCreateOjama := CreateOjama; |
| 379 |
Player1.OnScore := PlayerScore; |
| 380 |
Player2.OnScore := PlayerScore; |
| 381 |
Player1.Name := 'Player1'; |
| 382 |
Player2.Name := 'Player2'; |
| 383 |
Rensa := TRensa.Create; |
| 384 |
Player1.Com := true; { ComPlay } |
| 385 |
Player11.Checked := Player1.Com; |
| 386 |
Player1.Start; |
| 387 |
Buffer.Width := Player2.Ground.Left + Size * Wid; |
| 388 |
Buffer.Height := Hei * Size; |
| 389 |
Buffer.Canvas.Brush.Color := Color; |
| 390 |
Buffer.Canvas.FillRect(Rect(0, 0, Buffer.Width, Buffer.Height)); |
| 391 |
Buffer.Canvas.Font.Style := [fsBold]; |
| 392 |
end; |
| 393 |
|
| 394 |
procedure TForm1.FormDestroy(Sender: TObject); |
| 395 |
begin |
| 396 |
Rensa.Terminate; |
| 397 |
Rensa.WaitFor; |
| 398 |
Rensa.Free; |
| 399 |
Buffer.Free; |
| 400 |
Player1.Free; |
| 401 |
Player2.Free; |
| 402 |
end; |
| 403 |
|
| 404 |
procedure TForm1.FormKeyDown(Sender: TObject; var Key: Word; |
| 405 |
Shift: TShiftState); |
| 406 |
begin |
| 407 |
if Key = VK_ESCAPE then |
| 408 |
Close; |
| 409 |
if (Player1.State = Stop) and (Player2.State = Stop) then |
| 410 |
begin |
| 411 |
Player1.Start(true); |
| 412 |
Player2.Start(true); |
| 413 |
Buffer.Canvas.Brush.Color := Color; |
| 414 |
Buffer.Canvas.FillRect(Rect(0, 0, Buffer.Width, Buffer.Height)); |
| 415 |
Limit := 0; |
| 416 |
Exit; |
| 417 |
end; |
| 418 |
if (Player1.Com = false) and (Player1.State = Down) then |
| 419 |
begin |
| 420 |
case Key of |
| 421 |
VK_DOWN: |
| 422 |
Player1.State := Shoot; |
| 423 |
VK_UP: |
| 424 |
Player1.Turn; |
| 425 |
VK_LEFT: |
| 426 |
Player1.Move(TDirector.Left); |
| 427 |
VK_RIGHT: |
| 428 |
Player1.Move(Right); |
| 429 |
end; |
| 430 |
Paint; |
| 431 |
end; |
| 432 |
end; |
| 433 |
|
| 434 |
procedure TForm1.FormPaint(Sender: TObject); |
| 435 |
var |
| 436 |
i: integer; |
| 437 |
s: TGround; |
| 438 |
t: TPlayer; |
| 439 |
|
| 440 |
procedure GroundDraw; |
| 441 |
var |
| 442 |
i: integer; |
| 443 |
j: integer; |
| 444 |
procedure Small(X, Y: integer); |
| 445 |
const |
| 446 |
a = Size div 8; |
| 447 |
begin |
| 448 |
Buffer.Canvas.Ellipse(X - a, Y - a, X + a, Y + a); |
| 449 |
end; |
| 450 |
|
| 451 |
begin |
| 452 |
for i := 0 to Wid - 1 do |
| 453 |
for j := 0 to Hei - 1 do |
| 454 |
if s[i, j].Color <> clWhite then |
| 455 |
begin |
| 456 |
Buffer.Canvas.Brush.Color := s[i, j].Color; |
| 457 |
if s[i, j].Index = -1 then |
| 458 |
begin |
| 459 |
Small(s.Left + i * Size, s.Top + j * Size); |
| 460 |
Small(s.Left + (i + 1) * Size, s.Top + j * Size); |
| 461 |
Small(s.Left + i * Size, s.Top + (j + 1) * Size); |
| 462 |
Small(s.Left + (i + 1) * Size, s.Top + (j + 1) * Size); |
| 463 |
Small(s.Left + i * Size + (Size div 2), |
| 464 |
s.Top + j * Size + (Size div 2)); |
| 465 |
end |
| 466 |
else |
| 467 |
Buffer.Canvas.Ellipse(s.Left + i * Size, s.Top + j * Size, |
| 468 |
s.Left + (i + 1) * Size, s.Top + (j + 1) * Size); |
| 469 |
end; |
| 470 |
end; |
| 471 |
|
| 472 |
procedure OjamaDraw(aPlayer: TPlayer); |
| 473 |
var |
| 474 |
i: integer; |
| 475 |
t: TBall; |
| 476 |
begin |
| 477 |
if aPlayer.State <> Ojama then |
| 478 |
Exit; |
| 479 |
Buffer.Canvas.Brush.Color := clGray; |
| 480 |
for i := 0 to aPlayer.OjamaList.Count - 1 do |
| 481 |
begin |
| 482 |
t := aPlayer.OjamaList[i]; |
| 483 |
Buffer.Canvas.Ellipse(s.Left + t.X * Size, s.Top + t.Y * Size, |
| 484 |
s.Left + (t.X + 1) * Size, s.Top + (t.Y + 1) * Size); |
| 485 |
end; |
| 486 |
end; |
| 487 |
|
| 488 |
procedure ItemDraw(aItem: TItem); |
| 489 |
var |
| 490 |
k: integer; |
| 491 |
begin |
| 492 |
with aItem do |
| 493 |
begin |
| 494 |
if Visible = false then |
| 495 |
Exit; |
| 496 |
for k := 0 to Count - 1 do |
| 497 |
begin |
| 498 |
Buffer.Canvas.Brush.Color := Colors[k].Color; |
| 499 |
Buffer.Canvas.Ellipse(s.Left + Colors[k].X * Size, |
| 500 |
s.Top + Colors[k].Y * Size, s.Left + (Colors[k].X + 1) * Size, |
| 501 |
s.Top + (Colors[k].Y + 1) * Size); |
| 502 |
end; |
| 503 |
end; |
| 504 |
end; |
| 505 |
|
| 506 |
procedure Main; |
| 507 |
begin |
| 508 |
Buffer.Canvas.FillRect(Rect(s.Left, s.Top, s.Left + Wid * Size, |
| 509 |
s.Top + Hei * Size)); |
| 510 |
GroundDraw; |
| 511 |
end; |
| 512 |
|
| 513 |
begin |
| 514 |
Buffer.Canvas.Brush.Color := Color; |
| 515 |
Buffer.Canvas.FillRect(Rect(Player1.Ground.Left + Wid * Size, 0, |
| 516 |
Player2.Ground.Left, Hei * Size)); |
| 517 |
Buffer.Canvas.Brush.Color := clWhite; |
| 518 |
if Sender is TPlayer then |
| 519 |
begin |
| 520 |
t:=Sender as TPlayer; |
| 521 |
s := t.Ground; |
| 522 |
Main; |
| 523 |
ItemDraw(t.Item); |
| 524 |
OjamaDraw(t); |
| 525 |
end |
| 526 |
else |
| 527 |
begin |
| 528 |
s := Player1.Ground; |
| 529 |
Main; |
| 530 |
ItemDraw(Player1.Item); |
| 531 |
OjamaDraw(Player1); |
| 532 |
Buffer.Canvas.Brush.Color := clWhite; |
| 533 |
s := Player2.Ground; |
| 534 |
Main; |
| 535 |
ItemDraw(Player2.Item); |
| 536 |
OjamaDraw(Player2); |
| 537 |
end; |
| 538 |
if Limit > 0 then |
| 539 |
begin |
| 540 |
i := (Buffer.Width - Buffer.Canvas.TextWidth(TextMessage)) div 2; |
| 541 |
Buffer.Canvas.Brush.Color := Color; |
| 542 |
Buffer.Canvas.TextOut(i, 0, TextMessage); |
| 543 |
if Time > Limit then |
| 544 |
begin |
| 545 |
Limit := 0; |
| 546 |
Paint; |
| 547 |
end; |
| 548 |
end; |
| 549 |
Canvas.Draw(100, 50, Buffer); |
| 550 |
end; |
| 551 |
|
| 552 |
procedure TForm1.Player11Click(Sender: TObject); |
| 553 |
begin |
| 554 |
Player11.Checked := not Player11.Checked; |
| 555 |
Player1.Com := Player11.Checked; |
| 556 |
Start1Click(Sender); |
| 557 |
end; |
| 558 |
|
| 559 |
procedure TForm1.PlayerScore(Sender: TObject; const GameParam: TGameParam; |
| 560 |
var Score: integer); |
| 561 |
begin |
| 562 |
with GameParam do |
| 563 |
Score := Rensa * Rensa * 10 + Group * Group * 15; |
| 564 |
end; |
| 565 |
|
| 566 |
procedure TForm1.Start1Click(Sender: TObject); |
| 567 |
begin |
| 568 |
Rensa.Terminate; |
| 569 |
Rensa.WaitFor; |
| 570 |
Rensa.Free; |
| 571 |
Rensa := TRensa.Create; |
| 572 |
Player1.Start(true); |
| 573 |
end; |
| 574 |
|
| 575 |
{ TPlayer } |
| 576 |
|
| 577 |
constructor TPlayer.Create; |
| 578 |
begin |
| 579 |
State := TState.Stop; |
| 580 |
Item := TItem.Create; |
| 581 |
Temp := TItem.Create; |
| 582 |
Test := TItem.Create; |
| 583 |
Ground := TGround.Create; |
| 584 |
OjamaList := TList.Create; |
| 585 |
end; |
| 586 |
|
| 587 |
destructor TPlayer.Destroy; |
| 588 |
begin |
| 589 |
Item.Free; |
| 590 |
Temp.Free; |
| 591 |
Test.Free; |
| 592 |
Ground.Free; |
| 593 |
OjamaClean; |
| 594 |
OjamaList.Free; |
| 595 |
inherited; |
| 596 |
end; |
| 597 |
|
| 598 |
procedure TPlayer.Make(aCount: integer); |
| 599 |
var |
| 600 |
i: integer; |
| 601 |
s: TBall; |
| 602 |
j, k, m: integer; |
| 603 |
t: TStringList; |
| 604 |
function Full: Boolean; |
| 605 |
var |
| 606 |
n: integer; |
| 607 |
p: integer; |
| 608 |
begin |
| 609 |
p := 0; |
| 610 |
for n := 0 to OjamaList.Count - 1 do |
| 611 |
begin |
| 612 |
s := OjamaList[n]; |
| 613 |
if s.Y = m then |
| 614 |
inc(p); |
| 615 |
end; |
| 616 |
result := p = Wid; |
| 617 |
end; |
| 618 |
|
| 619 |
begin |
| 620 |
if aCount = 0 then |
| 621 |
Exit; |
| 622 |
for i := OjamaList.Count - 1 downto 0 do |
| 623 |
begin |
| 624 |
s := OjamaList[i]; |
| 625 |
if (s.Y < 0) and (aCount > 0) then |
| 626 |
begin |
| 627 |
s.Free; |
| 628 |
OjamaList.Delete(i); |
| 629 |
dec(aCount); |
| 630 |
end |
| 631 |
else |
| 632 |
begin |
| 633 |
m := s.Y - 1; |
| 634 |
break; |
| 635 |
end; |
| 636 |
end; |
| 637 |
j := 0; |
| 638 |
while aCount >= Wid do |
| 639 |
begin |
| 640 |
for i := 0 to Wid - 1 do |
| 641 |
begin |
| 642 |
s := TBall.Craete; |
| 643 |
s.X := i; |
| 644 |
s.Y := j; |
| 645 |
s.Color := clGray; |
| 646 |
OjamaList.Add(s); |
| 647 |
end; |
| 648 |
dec(aCount, Wid); |
| 649 |
dec(j); |
| 650 |
end; |
| 651 |
t := TStringList.Create; |
| 652 |
try |
| 653 |
for i := 0 to Wid - 1 do |
| 654 |
t.Add(IntToStr(i)); |
| 655 |
Randomize; |
| 656 |
for i := 1 to aCount do |
| 657 |
begin |
| 658 |
k := Random(t.Count); |
| 659 |
s := TBall.Create; |
| 660 |
s.X := StrToInt(t[k]); |
| 661 |
s.Y := j; |
| 662 |
s.Color := clGray; |
| 663 |
t.Delete(k); |
| 664 |
OjamaList.Add(s); |
| 665 |
if Full = true then |
| 666 |
dec(j); |
| 667 |
end; |
| 668 |
finally |
| 669 |
t.Free; |
| 670 |
end; |
| 671 |
end; |
| 672 |
|
| 673 |
function TPlayer.Move(Dir: TDirector): Boolean; |
| 674 |
var |
| 675 |
i: integer; |
| 676 |
s: TItem; |
| 677 |
begin |
| 678 |
result := true; |
| 679 |
s := TItem.Create; |
| 680 |
try |
| 681 |
s.Assign(Item); |
| 682 |
case Dir of |
| 683 |
Under: |
| 684 |
begin |
| 685 |
for i := 0 to Count - 1 do |
| 686 |
s.Colors[i].Y := s.Colors[i].Y + 1; |
| 687 |
if Check(s) = true then |
| 688 |
Item.Assign(s) |
| 689 |
else |
| 690 |
begin |
| 691 |
State := Sys; |
| 692 |
GameParam.Rensa := 0; |
| 693 |
Item.Visible := false; |
| 694 |
for i := 0 to Count - 1 do |
| 695 |
Ground[Item.Colors[i].X, Item.Colors[i].Y].Color := |
| 696 |
Item.Colors[i].Color; |
| 697 |
result := false; |
| 698 |
end; |
| 699 |
end; |
| 700 |
Left: |
| 701 |
begin |
| 702 |
for i := 0 to Count - 1 do |
| 703 |
s.Colors[i].X := s.Colors[i].X - 1; |
| 704 |
if Check(s) = true then |
| 705 |
Item.Assign(s) |
| 706 |
else |
| 707 |
result := false; |
| 708 |
end; |
| 709 |
Right: |
| 710 |
begin |
| 711 |
for i := 0 to Count - 1 do |
| 712 |
s.Colors[i].X := s.Colors[i].X + 1; |
| 713 |
if Check(s) = true then |
| 714 |
Item.Assign(s) |
| 715 |
else |
| 716 |
result := false; |
| 717 |
end; |
| 718 |
end; |
| 719 |
finally |
| 720 |
s.Free; |
| 721 |
end; |
| 722 |
end; |
| 723 |
|
| 724 |
procedure TPlayer.OjamaClean; |
| 725 |
var |
| 726 |
i: integer; |
| 727 |
s: TBall; |
| 728 |
begin |
| 729 |
for i := 0 to OjamaList.Count - 1 do |
| 730 |
begin |
| 731 |
s := OjamaList[i]; |
| 732 |
s.Free; |
| 733 |
end; |
| 734 |
OjamaList.Clear; |
| 735 |
end; |
| 736 |
|
| 737 |
function TPlayer.Remove: Boolean; |
| 738 |
var |
| 739 |
Index: integer; |
| 740 |
s: TColor; |
| 741 |
i: integer; |
| 742 |
j: integer; |
| 743 |
function MapIndex(X, Y: integer): Boolean; |
| 744 |
var |
| 745 |
p: TBall; |
| 746 |
begin |
| 747 |
result := true; |
| 748 |
if (Ground[X, Y] = nil) or (Ground[X, Y].Color = clGray) then |
| 749 |
begin |
| 750 |
result := false; |
| 751 |
Exit; |
| 752 |
end; |
| 753 |
if Ground[X, Y].Color = s then |
| 754 |
begin |
| 755 |
p := Ground[X, Y]; |
| 756 |
if (p.Index = 0) and (p.Color = s) then |
| 757 |
begin |
| 758 |
Ground[X, Y].Index := Index; |
| 759 |
MapIndex(X - 1, Y - 1); |
| 760 |
MapIndex(X, Y - 1); |
| 761 |
MapIndex(X + 1, Y - 1); |
| 762 |
MapIndex(X - 1, Y); |
| 763 |
MapIndex(X + 1, Y); |
| 764 |
MapIndex(X - 1, Y + 1); |
| 765 |
MapIndex(X, Y + 1); |
| 766 |
MapIndex(X + 1, Y + 1); |
| 767 |
end |
| 768 |
else |
| 769 |
result := false; |
| 770 |
end; |
| 771 |
end; |
| 772 |
function CheckIndex(X: integer): integer; |
| 773 |
var |
| 774 |
m, n: integer; |
| 775 |
begin |
| 776 |
result := 0; |
| 777 |
for m := 0 to Wid - 1 do |
| 778 |
for n := 0 to Hei - 1 do |
| 779 |
if Ground[m, n].Index = X then |
| 780 |
inc(result); |
| 781 |
end; |
| 782 |
procedure DeleteOjama(const Ojama: array of TBall); |
| 783 |
var |
| 784 |
m: integer; |
| 785 |
begin |
| 786 |
for m := Low(Ojama) to High(Ojama) do |
| 787 |
if (Ojama[m] <> nil) and (Ojama[m].Color = clGray) then |
| 788 |
Ojama[m].Color := clWhite; |
| 789 |
end; |
| 790 |
procedure Delete(X: integer); |
| 791 |
var |
| 792 |
m, n: integer; |
| 793 |
begin |
| 794 |
for m := 0 to Wid - 1 do |
| 795 |
for n := 0 to Hei - 1 do |
| 796 |
if Ground[m, n].Index = X then |
| 797 |
begin |
| 798 |
if BackGround = true then |
| 799 |
Ground[m, n].Color := clWhite |
| 800 |
else |
| 801 |
Ground[m, n].Index := -1; |
| 802 |
DeleteOjama([Ground[m - 1, n], Ground[m + 1, n], Ground[m, n - 1], |
| 803 |
Ground[m, n + 1]]); |
| 804 |
end; |
| 805 |
end; |
| 806 |
|
| 807 |
begin |
| 808 |
for i := 0 to Wid - 1 do |
| 809 |
for j := 0 to Hei - 1 do |
| 810 |
Ground[i, j].Index := 0; |
| 811 |
Index := 1; |
| 812 |
for i := 0 to Wid - 1 do |
| 813 |
for j := 0 to Hei - 1 do |
| 814 |
begin |
| 815 |
s := Ground[i, j].Color; |
| 816 |
if (s <> clWhite) and (s <> OjamaColor) then |
| 817 |
if MapIndex(i, j) = true then |
| 818 |
inc(Index); |
| 819 |
end; |
| 820 |
GameParam.Kazu := 0; |
| 821 |
Score := 0; |
| 822 |
result := false; |
| 823 |
for i := 1 to Index do |
| 824 |
begin |
| 825 |
j := CheckIndex(i); |
| 826 |
if j = 3 then |
| 827 |
inc(GameParam.Group); |
| 828 |
if j >= 4 then |
| 829 |
begin |
| 830 |
inc(GameParam.Kazu, j); |
| 831 |
inc(GameParam.Rensa); |
| 832 |
inc(Score, 5 * j); |
| 833 |
Delete(i); |
| 834 |
result := true; |
| 835 |
end; |
| 836 |
inc(Score, GameParam.Rensa * 10); |
| 837 |
if Assigned(FOnScoreEvent) = true then |
| 838 |
FOnScoreEvent(Self, GameParam, Score); |
| 839 |
end; |
| 840 |
end; |
| 841 |
|
| 842 |
function TPlayer.Drop: Boolean; |
| 843 |
var |
| 844 |
i: integer; |
| 845 |
j: integer; |
| 846 |
k: integer; |
| 847 |
begin |
| 848 |
result := false; |
| 849 |
for i := 0 to Wid - 1 do |
| 850 |
for j := Hei - 1 downto 1 do |
| 851 |
if Ground[i, j].Color = clWhite then |
| 852 |
begin |
| 853 |
for k := j downto 1 do |
| 854 |
begin |
| 855 |
Ground[i, k].Color := Ground[i, k - 1].Color; |
| 856 |
Ground[i, k].Index := Ground[i, k - 1].Index; |
| 857 |
if Ground[i, k].Color <> clWhite then |
| 858 |
result := true; |
| 859 |
end; |
| 860 |
Ground[i, 0].Color := clWhite; |
| 861 |
Ground[i, 0].Index := 0; |
| 862 |
end; |
| 863 |
end; |
| 864 |
|
| 865 |
procedure TPlayer.Execute; |
| 866 |
function Same: Boolean; |
| 867 |
var |
| 868 |
k: integer; |
| 869 |
begin |
| 870 |
result := true; |
| 871 |
for k := 0 to Count - 1 do |
| 872 |
if Item.Colors[k].Color <> Test.Colors[k].Color then |
| 873 |
begin |
| 874 |
result := false; |
| 875 |
break; |
| 876 |
end; |
| 877 |
end; |
| 878 |
|
| 879 |
var |
| 880 |
i, j: integer; |
| 881 |
s: TBall; |
| 882 |
|
| 883 |
begin |
| 884 |
case State of |
| 885 |
Down: |
| 886 |
if Com = true then |
| 887 |
begin |
| 888 |
if (Item.Horizontal <> Test.Horizontal) or (Same = false) then |
| 889 |
Turn |
| 890 |
else if Item.Left = Test.Left then |
| 891 |
State := Shoot |
| 892 |
else if Item.Left < Test.Left then |
| 893 |
Item.Left := Item.Left + 1 |
| 894 |
else |
| 895 |
Item.Left := Item.Left - 1; |
| 896 |
Sleep(100); |
| 897 |
end |
| 898 |
else |
| 899 |
begin |
| 900 |
Move(Under); |
| 901 |
for i := 1 to 100 do |
| 902 |
begin |
| 903 |
Sleep(3); |
| 904 |
Application.ProcessMessages; |
| 905 |
if State <> Down then |
| 906 |
break; |
| 907 |
end; |
| 908 |
end; |
| 909 |
Shoot: |
| 910 |
begin |
| 911 |
Move(Under); |
| 912 |
Sleep(100); |
| 913 |
end; |
| 914 |
Sys: |
| 915 |
if Drop = true then |
| 916 |
Sleep(100) |
| 917 |
else if Remove = true then |
| 918 |
begin |
| 919 |
State := Effect; |
| 920 |
EffectCount := 1; |
| 921 |
end |
| 922 |
else |
| 923 |
begin |
| 924 |
State := Ojama; |
| 925 |
if Assigned(FOnCreateOjama) = true then |
| 926 |
if Zenkesi = true then |
| 927 |
FOnCreateOjama(Self, 2 * Wid, '**�S����**') |
| 928 |
else if GameParam.Rensa > 1 then |
| 929 |
FOnCreateOjama(Self, GameParam.Rensa - 1, |
| 930 |
Name + Format(' %d �A��', [GameParam.Rensa])); |
| 931 |
end; |
| 932 |
Effect: |
| 933 |
begin |
| 934 |
case EffectCount of |
| 935 |
0: |
| 936 |
State := Sys; |
| 937 |
1: |
| 938 |
for i := 0 to Wid - 1 do |
| 939 |
for j := 0 to Hei - 1 do |
| 940 |
if Ground[i, j].Index = -1 then |
| 941 |
begin |
| 942 |
Ground[i, j].Color := clWhite; |
| 943 |
Ground[i, j].Index := 0; |
| 944 |
end; |
| 945 |
end; |
| 946 |
Sleep(100); |
| 947 |
dec(EffectCount); |
| 948 |
end; |
| 949 |
Ojama: |
| 950 |
if OjamaList.Count = 0 then |
| 951 |
Start |
| 952 |
else |
| 953 |
begin |
| 954 |
for i := 0 to OjamaList.Count - 1 do |
| 955 |
begin |
| 956 |
s := OjamaList[i]; |
| 957 |
if (s.Y < Hei - 1) and |
| 958 |
((s.Y < 0) or (Ground[s.X, s.Y + 1].Color = clWhite)) then |
| 959 |
s.Y := s.Y + 1 |
| 960 |
else if (s.Y = 0) and (Ground[s.X, 0].Color <> clWhite) then |
| 961 |
begin |
| 962 |
State := Stop; |
| 963 |
Exit; |
| 964 |
end |
| 965 |
else |
| 966 |
begin |
| 967 |
Ground[s.X, s.Y].Color := clGray; |
| 968 |
s.Color := clWhite; |
| 969 |
end; |
| 970 |
end; |
| 971 |
for i := OjamaList.Count - 1 downto 0 do |
| 972 |
begin |
| 973 |
s := OjamaList[i]; |
| 974 |
if s.Color = clWhite then |
| 975 |
begin |
| 976 |
s.Free; |
| 977 |
OjamaList.Delete(i); |
| 978 |
end; |
| 979 |
end; |
| 980 |
Sleep(100); |
| 981 |
end; |
| 982 |
end; |
| 983 |
end; |
| 984 |
|
| 985 |
procedure TPlayer.Start(const Resume: Boolean); |
| 986 |
begin |
| 987 |
OjamaClean; |
| 988 |
if Resume = true then |
| 989 |
begin |
| 990 |
Temp.Clean; |
| 991 |
Item.Visible := false; |
| 992 |
Ground.Clean; |
| 993 |
end; |
| 994 |
Item.Assign(Temp); |
| 995 |
Item.Visible := true; |
| 996 |
if Check(Item) = false then |
| 997 |
begin |
| 998 |
State := TState.Stop; |
| 999 |
if Assigned(FOnCreateOjama) = true then |
| 1000 |
FOnCreateOjama(Self, 0, 'Game Over'); |
| 1001 |
end |
| 1002 |
else |
| 1003 |
begin |
| 1004 |
if Com = true then |
| 1005 |
Think; |
| 1006 |
State := Down; |
| 1007 |
end; |
| 1008 |
Temp.Clean; |
| 1009 |
end; |
| 1010 |
|
| 1011 |
function TPlayer.Check(aItem: TItem): Boolean; |
| 1012 |
var |
| 1013 |
i: integer; |
| 1014 |
s: TBall; |
| 1015 |
begin |
| 1016 |
result := true; |
| 1017 |
for i := 0 to Count - 1 do |
| 1018 |
begin |
| 1019 |
s := Ground[aItem.Colors[i].X, aItem.Colors[i].Y]; |
| 1020 |
if (s = nil) or (s.Color <> clWhite) then |
| 1021 |
begin |
| 1022 |
result := false; |
| 1023 |
break; |
| 1024 |
end; |
| 1025 |
end; |
| 1026 |
end; |
| 1027 |
|
| 1028 |
procedure TPlayer.Think; |
| 1029 |
const |
| 1030 |
Hei = 100; |
| 1031 |
var |
| 1032 |
s: TGround; |
| 1033 |
i: integer; |
| 1034 |
k, m: integer; |
| 1035 |
procedure Sub; |
| 1036 |
var |
| 1037 |
j: integer; |
| 1038 |
begin |
| 1039 |
k := -1; |
| 1040 |
for j := 0 to Wid - 1 do |
| 1041 |
begin |
| 1042 |
Item.Left := j; |
| 1043 |
Item.Top := 0; |
| 1044 |
if Check(Item) = false then |
| 1045 |
continue; |
| 1046 |
while true do |
| 1047 |
if Move(Under) = false then |
| 1048 |
break; |
| 1049 |
m := 0; |
| 1050 |
while true do |
| 1051 |
if Drop = false then |
| 1052 |
begin |
| 1053 |
if Remove = false then |
| 1054 |
break; |
| 1055 |
inc(m, Score); |
| 1056 |
end; |
| 1057 |
Ground.Assign(s); |
| 1058 |
if m > k then |
| 1059 |
begin |
| 1060 |
k := m; |
| 1061 |
Test.Assign(Item); |
| 1062 |
end; |
| 1063 |
if k >= Hei then |
| 1064 |
break; |
| 1065 |
end; |
| 1066 |
end; |
| 1067 |
|
| 1068 |
begin |
| 1069 |
BackGround := true; |
| 1070 |
s := TGround.Create; |
| 1071 |
try |
| 1072 |
s.Assign(Ground); |
| 1073 |
for i := 1 to 3 do |
| 1074 |
begin |
| 1075 |
Sub; |
| 1076 |
if k >= Hei then |
| 1077 |
break; |
| 1078 |
Turn; |
| 1079 |
end; |
| 1080 |
Item.Left := pos_X; |
| 1081 |
Item.Top := 0; |
| 1082 |
Item.Visible := true; |
| 1083 |
finally |
| 1084 |
BackGround := false; |
| 1085 |
s.Free; |
| 1086 |
end; |
| 1087 |
Item.Assign(Temp); |
| 1088 |
end; |
| 1089 |
|
| 1090 |
function TPlayer.Turn(const Right: Boolean): Boolean; |
| 1091 |
var |
| 1092 |
i: integer; |
| 1093 |
s: TItem; |
| 1094 |
procedure return(var aItem: TItem); |
| 1095 |
var |
| 1096 |
p: array [0 .. Count - 1] of TColor; |
| 1097 |
j: integer; |
| 1098 |
begin |
| 1099 |
for j := 0 to Count - 1 do |
| 1100 |
p[j] := aItem.Colors[Count - j - 1].Color; |
| 1101 |
for j := 0 to Count - 1 do |
| 1102 |
aItem.Colors[j].Color := p[j]; |
| 1103 |
end; |
| 1104 |
|
| 1105 |
begin |
| 1106 |
s := TItem.Create; |
| 1107 |
try |
| 1108 |
s.Assign(Item); |
| 1109 |
s.Horizontal := not s.Horizontal; |
| 1110 |
if ((not s.Horizontal = true) and (Right = true)) or |
| 1111 |
((not s.Horizontal = false) and (Right = false)) then |
| 1112 |
return(s); |
| 1113 |
for i := 0 to Count - 1 do |
| 1114 |
begin |
| 1115 |
if s.Horizontal = true then |
| 1116 |
begin |
| 1117 |
s.Colors[i].X := s.Colors[i].X + s.Colors[0].Y - s.Colors[i].Y; |
| 1118 |
s.Colors[i].Y := s.Colors[0].Y; |
| 1119 |
end |
| 1120 |
else |
| 1121 |
begin |
| 1122 |
s.Colors[i].Y := s.Colors[i].Y + s.Colors[0].X - s.Colors[i].X; |
| 1123 |
s.Colors[i].X := s.Colors[0].X; |
| 1124 |
end; |
| 1125 |
end; |
| 1126 |
result := Check(s); |
| 1127 |
if result = true then |
| 1128 |
Item.Assign(s) |
| 1129 |
else |
| 1130 |
begin |
| 1131 |
for i := 0 to Count - 1 do |
| 1132 |
s.Colors[i].X := s.Colors[i].X + 1; |
| 1133 |
if Check(s) = true then |
| 1134 |
begin |
| 1135 |
Item.Assign(s); |
| 1136 |
result := true; |
| 1137 |
end |
| 1138 |
else |
| 1139 |
begin |
| 1140 |
for i := 0 to Count - 1 do |
| 1141 |
s.Colors[i].X := s.Colors[i].X - 2; |
| 1142 |
if Check(s) = true then |
| 1143 |
begin |
| 1144 |
Item.Assign(s); |
| 1145 |
result := true; |
| 1146 |
end |
| 1147 |
else |
| 1148 |
result := false; |
| 1149 |
end; |
| 1150 |
end; |
| 1151 |
finally |
| 1152 |
s.Free; |
| 1153 |
end; |
| 1154 |
end; |
| 1155 |
|
| 1156 |
function TPlayer.Zenkesi: Boolean; |
| 1157 |
var |
| 1158 |
i: integer; |
| 1159 |
j: integer; |
| 1160 |
begin |
| 1161 |
for i := 0 to Wid - 1 do |
| 1162 |
for j := 0 to Hei - 1 do |
| 1163 |
if (Ground[i, j].Color <> clWhite) and (Ground[i, j].Color <> clGray) then |
| 1164 |
begin |
| 1165 |
result := false; |
| 1166 |
Exit; |
| 1167 |
end; |
| 1168 |
result := true; |
| 1169 |
end; |
| 1170 |
|
| 1171 |
end. |