1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47: 48: 49: 50: 51: 52: 53: 54: 55: 56: 57: 58: 59: 60: 61: 62: 63: 64: 65: 66: 67: 68: 69: 70: 71: 72: 73: 74: 75: 76: 77: 78: 79: 80: 81: 82: 83: 84: 85: 86: 87: 88: 89: 90: 91: 92: 93: 94: 95: 96: 97: 98: 99: 100: 101: 102: 103: 104: 105: 106: 107: 108: 109: 110: 111: 112: 113: 114: 115: 116: 117: 118: 119: 120: 121: 122: 123: 124: 125: 126: 127: 128: 129: 130: 131: 132: 133: 134: 135: 136: 137: 138: 139: 140: 141: 142: 143: 144: 145: 146: 147: 148: 149: 150: 151: 152: 153: 154: 155: 156: 157: 158: 159: 160: 161: 162: 163: 164: 165: 166: 167: 168: 169: 170: 171: 172: 173: 174: 175: 176: 177: 178: 179: 180: 181: 182: 183: 184: 185: 186: 187: 188: 189: 190: 191: 192: 193: 194: 195: 196: 197: 198: 199: 200: 201: 202: 203: 204: 205: 206: 207: 208: 209: 210: 211: 212: 213: 214: 215: 216: 217: 218: 219: 220: 221: 222: 223: 224: 225: 226: 227: 228: 229: 230: 231: 232: 233: 234: 235: 236: 237: 238: 239: 240: 241: 242: 243: 244: 245: 246: 247: 248: 249: 250: 251: 252: 253: 254: 255: 256: 257: 258: 259: 260: 261: 262: 263: 264: 265: 266: 267: 268: 269: 270: 271: 272: 273: 274: 275: 276: 277: 278: 279: 280: 281: 282: 283: 284: 285: 286: 287: 288: 289: 290: 291: 292: 293: 294: 295: 296: 297: 298: 299: 300: 301: 302: 303: 304: 305: 306: 307: 308: 309: 310: 311: 312: 313: 314: 315: 316: 317: 318: 319: 320: 321: 322: 323: 324: 325: 326: 327: 328: 329: 330: 331: 332: 333: 334: 335: 336: 337: 338: 339: 340: 341: 342:
| unit Main;
interface
uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, ExtCtrls, StdCtrls, Creep_Unit, Hintergrund_unit, Tower_Unit;
type TForm1 = class(TForm) Bild: TImage; Button1: TButton; Timer1: TTimer; Edit1: TEdit; Edit2: TEdit; Edit3: TEdit; Label1: TLabel; Label2: TLabel; Label3: TLabel; Edit4: TEdit; Label4: TLabel; Edit5: TEdit; ColorBox1: TColorBox; Panel1: TPanel; Label5: TLabel; Panel2: TPanel; creep_number_label: TLabel; HP_Label: TLabel; POS_Label: TLabel; Button2: TButton; procedure FormCreate(Sender: TObject); procedure Button1Click(Sender: TObject); procedure Timer1Timer(Sender: TObject); procedure BildMouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer); procedure BildMouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer); procedure Button2Click(Sender: TObject);
private public hintergrund : THintergrund; buffer : TBitmap ; creep_liste : TList ; tower_liste : TList ; t_ja : Boolean ; Maus : TPoint ; selected_c : Integer ; selected_t : Integer ; x_creep : Integer ; y_creep : Integer ; v_creep : Integer ; x_tower : Integer ; y_tower : Integer ; t_damage : Integer ; t_range : Integer ; t_frequency : Integer ; breite_Creep : Integer ; hoehe_Creep : Integer ; creep_anzahl : Integer ; creep_farbe : TColor ; strassen_farbe : TColor ; refresh_creepI : Boolean ; refresh_creep : Boolean ; procedure creeps_bewegen ; procedure Init ; procedure Bild_Aktualisieren ; procedure Show_Creep_Info ; procedure Show_Game_Info ; procedure Angreifen ; end;
var Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.Init; begin
breite_creep := StrToInt(Edit1.Text); hoehe_creep := StrToInt(Edit2.Text); v_creep := StrToInt(Edit3.Text); x_creep := 80-(breite_creep div 2) ; y_creep := 500; creep_farbe := ColorBox1.Selected; strassen_farbe := clGray; refresh_creepI := false ; refresh_creep := false ; t_ja := false ; x_tower := 0; y_tower := 1000; t_damage := 10 ; t_range := 300 ; t_frequency := 10; end;
procedure TForm1.Bild_Aktualisieren; begin buffer.Canvas.Draw(0,0,hintergrund); Bild.Canvas.Draw(0,0,buffer) ; hintergrund.Refresh ; end;
procedure TForm1.creeps_bewegen; var i,n,m,o : integer;
begin for i :=0 to creep_liste.Count - 1 do begin m := 0; if (TCreep(creep_liste.Items[i]).x_Creep < 100) and (TCreep(creep_liste.Items[i]).x_Creep > 60) then begin If TCreep(creep_liste.Items[i]).y_Creep > 90-(hoehe_creep div 2) then TCreep(creep_liste.Items[i]).y_Creep := TCreep(creep_liste.Items[i]).y_Creep - TCreep(creep_liste.Items[i]).delta_weg else TCreep(creep_liste.Items[i]).x_Creep := TCreep(creep_liste.Items[i]).x_Creep + TCreep(creep_liste.Items[i]).delta_weg; end;
if (TCreep(creep_liste.Items[i]).x_Creep < 380) and (TCreep(creep_liste.Items[i]).x_Creep >= 100) and (TCreep(creep_liste.Items[i]).y_Creep < 280-(hoehe_creep div 2)) then begin If TCreep(creep_liste.Items[i]).x_Creep < 380-(breite_creep div 2) then TCreep(creep_liste.Items[i]).x_Creep := TCreep(creep_liste.Items[i]).x_Creep + TCreep(creep_liste.Items[i]).delta_weg else TCreep(creep_liste.Items[i]).y_Creep := TCreep(creep_liste.Items[i]).y_Creep + TCreep(creep_liste.Items[i]).delta_weg; end;
if (TCreep(creep_liste.Items[i]).y_Creep <= 300) and (TCreep(creep_liste.Items[i]).y_Creep >= 280-(hoehe_creep div 2)) then begin If (TCreep(creep_liste.Items[i]).x_Creep >= 380-(hoehe_creep div 2)) and (TCreep(creep_liste.Items[i]).x_Creep <= Bild.Width+50) then TCreep(creep_liste.Items[i]).x_Creep := TCreep(creep_liste.Items[i]).x_Creep + TCreep(creep_liste.Items[i]).delta_weg; end;
if (TCreep(creep_liste.Items[i]).Noch_Im_Spielfeld(TCreep(creep_liste.Items[i]).x_Creep,TCreep(creep_liste.Items[i]).tot) = 0) and (TCreep(creep_liste.Items[i]).nicht_zaehlen = false) then begin Dec(creep_anzahl); TCreep(creep_liste.Items[i]).nicht_zaehlen := true; Edit5.Text := IntToStr(creep_anzahl); end;
if creep_anzahl <= 0 then begin for o := 0 to creep_liste.Count - 1 do begin creep_liste.Items[o] := nil; end; refresh_creep := false; refresh_creepI := false; Bild_Aktualisieren; creep_liste.Pack ; exit; end;
for n := 0 to creep_liste.Count - 1 do begin if TCreep(creep_liste.Items[n]).Noch_Im_Spielfeld(TCreep(creep_liste.Items[n]).x_Creep,false) = 0 then Inc(m); if m >= creep_liste.Count then begin for o := 0 to creep_liste.Count - 1 do begin creep_liste.Items[o] := nil; end; creep_anzahl := 0; Edit5.Text := IntToStr(creep_anzahl); refresh_creep := false; refresh_creepI := false; Bild_Aktualisieren; creep_liste.Pack ; exit; end; end; end; Bild_Aktualisieren; end;
procedure TForm1.Show_Creep_Info; begin Panel2.Color := $002232c6; Creep_Number_Label.Visible := true; HP_Label.Visible := true; POS_Label.Visible := true; Creep_Number_Label.Caption := 'Creep-Nummer: ' + IntToStr(selected_c+1); HP_Label.Caption := 'Leben: ' + IntToStr(TCreep(creep_liste.Items[selected_c]).HP); POS_Label.Caption := '(' + IntToStr(TCreep(creep_liste.Items[selected_c]).x_Creep) + '|' + IntToStr(TCreep(creep_liste.Items[selected_c]).y_Creep) + ')'; refresh_creepI := true ; end;
procedure TForm1.Show_Game_Info; begin refresh_creepI := false ; Panel2.Color := clCream; Creep_Number_Label.Visible := false; HP_Label.Visible := false; POS_Label.Visible := false; end;
procedure TForm1.Angreifen; var i,n : integer; begin for i := 0 to creep_liste.Count - 1 do begin if creep_liste.Items[i] <> nil then begin for n := 0 to tower_liste.Count - 1 do begin if tower_liste.Items[n] <> nil then begin If TTower(tower_liste.Items[n]).creep_in_range(TCreep(creep_liste.Items[i]).creep_pos) = true then TCreep(creep_liste.Items[i]).HP := TCreep(creep_liste.Items[i]).HP - TTower(tower_liste.Items[n]).damage; end; end; end; end; end;
procedure TForm1.FormCreate(Sender: TObject); begin Init; hintergrund := THintergrund.create(Bild.Width,Bild.Height,clGreen,strassen_farbe);
buffer := TBitmap.Create; with buffer do begin Height := Bild.Height; Width := Bild.Width ; end;
creep_liste := TList.Create;
tower_liste := TList.Create;
Form1.DoubleBuffered := true;
Show_Game_Info;
Bild_Aktualisieren;
Timer1.enabled := true; end;
procedure TForm1.Button1Click(Sender: TObject); var n : integer; begin Init; for n := 0 to StrToInt(Edit4.Text)-1 do begin y_creep := 500 + n*(hoehe_creep+20); creep_liste.Add(TCreep.Create(breite_creep,hoehe_creep,x_creep,y_creep,v_creep,100,creep_farbe)); end; creep_anzahl := creep_liste.Count; Edit5.Text := IntToStr(creep_anzahl); refresh_creep := true; end;
procedure TForm1.Timer1Timer(Sender: TObject); begin if refresh_creep = true then begin creeps_bewegen ; Angreifen ; end; Angreifen; if (refresh_creepI) and (TCreep(creep_liste.Items[selected_c]).Noch_Im_Spielfeld(TCreep(creep_liste.Items[selected_c]).x_Creep,false) <> 0) then Show_Creep_Info else Show_Game_Info;
end;
procedure TForm1.BildMouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer); var c : integer ; begin Maus.X := X; Maus.Y := Y; If NOT t_ja then begin for c := 0 to creep_liste.Count - 1 do begin If TCreep(creep_liste.Items[c]).selected(Maus) then begin selected_c := c ; Show_Creep_Info; exit; end; end; end; If t_ja then begin TTower(tower_liste.Items[selected_t]).x_tower := X; TTower(tower_liste.Items[selected_t]).y_tower := Y; Bild_Aktualisieren; end; end;
procedure TForm1.BildMouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer); var i : integer; begin Maus.X := X; Maus.Y := Y; If NOT t_ja then begin for i := 0 to creep_liste.Count - 1 do begin If not TCreep(creep_liste.Items[i]).selected(Maus) then begin Show_Game_Info; exit; end; end; end; If t_ja then t_ja := false; end;
procedure TForm1.Button2Click(Sender: TObject); begin tower_liste.Add(TTower.create(x_tower,y_tower,t_range,t_damage,t_frequency)); selected_t := tower_liste.Count - 1; t_ja := true; end;
end. |