Develop and Download Open Source Software

Browse Subversion Repository

Annotation of /Unit1.pas

Parent Directory Parent Directory | Revision Log Revision Log


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

Back to OSDN">Back to OSDN
ViewVC Help
Powered by ViewVC 1.1.26