- Timestamp:
- Feb 8, 2014, 11:28:47 PM (11 years ago)
- Location:
- trunk
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/UFormMain.lfm
r2 r3 9 9 OnCreate = FormCreate 10 10 OnDestroy = FormDestroy 11 OnShow = FormShow 11 12 LCLVersion = '1.3' 12 13 object PaintBox1: TPaintBox -
trunk/UFormMain.pas
r2 r3 17 17 procedure FormCreate(Sender: TObject); 18 18 procedure FormDestroy(Sender: TObject); 19 procedure FormShow(Sender: TObject); 19 20 procedure PaintBox1MouseDown(Sender: TObject; Button: TMouseButton; 20 21 Shift: TShiftState; X, Y: Integer); … … 45 46 procedure TFormMain.PaintBox1Paint(Sender: TObject); 46 47 begin 47 Game.Player.Paint(PaintBox1);48 TPlayer(Game.Players[0]).Paint(PaintBox1); 48 49 end; 49 50 … … 62 63 end; 63 64 65 procedure TFormMain.FormShow(Sender: TObject); 66 begin 67 Game.New; 68 end; 69 64 70 procedure TFormMain.PaintBox1MouseDown(Sender: TObject; Button: TMouseButton; 65 71 Shift: TShiftState; X, Y: Integer); 66 72 begin 67 73 StartMousePoint := Point(X, Y); 68 StartViewPoint := Point( Game.Player.View.Left, Game.Player.View.Top);74 StartViewPoint := Point(TPlayer(Game.Players[0]).View.Left, TPlayer(Game.Players[0]).View.Top); 69 75 MoveActive := True; 70 76 end; … … 79 85 begin 80 86 if MoveActive then begin 81 Game.Player.View := Bounds(StartViewPoint.X + StartMousePoint.X - X,87 TPlayer(Game.Players[0]).View := Bounds(StartViewPoint.X + StartMousePoint.X - X, 82 88 StartViewPoint.Y + StartMousePoint.Y - Y, 83 Game.Player.View.Right - Game.Player.View.Left,84 Game.Player.View.Bottom - Game.Player.View.Top);89 TPlayer(Game.Players[0]).View.Right - TPlayer(Game.Players[0]).View.Left, 90 TPlayer(Game.Players[0]).View.Bottom - TPlayer(Game.Players[0]).View.Top); 85 91 PaintBox1.Repaint; 86 92 end; 87 Caption := IntToStr( Game.Player.View.Right - Game.Player.View.Left);93 Caption := IntToStr(TPlayer(Game.Players[0]).View.Right - TPlayer(Game.Players[0]).View.Left); 88 94 end; 89 95 -
trunk/UGame.pas
r2 r3 6 6 7 7 uses 8 Classes, SysUtils, ExtCtrls, Graphics ;8 Classes, SysUtils, ExtCtrls, Graphics, Contnrs; 9 9 10 10 type 11 11 TGame = class; 12 TPlayer = class; 12 13 13 14 TFloatPoint = record … … 15 16 end; 16 17 18 TTerrainType = (ttVoid, ttNormal); 19 20 { TCell } 21 17 22 TCell = class 18 Visible: Boolean; 19 BackgroundColor: TColor; 20 Name: string; 23 Terrain: TTerrainType; 24 Power: Integer; 25 Player: TPlayer; 26 function GetColor: TColor; 21 27 end; 22 28 … … 28 34 procedure Paint(Canvas: TCanvas; Rect: TRect); 29 35 constructor Create; 36 procedure Init(Size: TPoint); 30 37 end; 31 38 … … 36 43 Name: string; 37 44 View: TRect; 45 Color: TColor; 38 46 procedure Paint(PaintBox: TPaintBox); 39 47 end; … … 42 50 43 51 TGame = class 44 Player : TPlayer;52 Players: TObjectList; 45 53 Map: TMap; 46 54 constructor Create; 47 55 destructor Destroy; override; 56 procedure New; 48 57 end; 49 58 … … 55 64 Result.X := AX; 56 65 Result.Y := AY; 66 end; 67 68 { TCell } 69 70 function TCell.GetColor: TColor; 71 begin 72 if Assigned(Player) then Result := Player.Color 73 else Result := clGray; 57 74 end; 58 75 … … 70 87 constructor TGame.Create; 71 88 var 89 Player: TPlayer; 90 begin 91 Players := TObjectList.Create; 92 Player := TPlayer.Create; 93 Player.Game := Self; 94 Player.Color := clBlue; 95 Players.Add(Player); 96 Player := TPlayer.Create; 97 Player.Game := Self; 98 Player.Color := clRed; 99 Players.Add(Player); 100 101 Map := TMap.Create; 102 end; 103 104 destructor TGame.Destroy; 105 begin 106 FreeAndNil(Players); 107 FreeAndNil(Map); 108 inherited Destroy; 109 end; 110 111 procedure TGame.New; 112 var 72 113 X, Y: Integer; 73 114 NewCell: TCell; 74 C: Integer; 75 begin 76 Player := TPlayer.Create; 77 Player.Game := Self; 78 Map := TMap.Create; 79 SetLength(Map.Cells, 100, 100); 80 C := 0; 115 I: Integer; 116 StartCell: TCell; 117 begin 118 Map.Init(Point(20, 20)); 81 119 for Y := 0 to Length(Map.Cells) - 1 do 82 for X := 0 to Length(Map.Cells[0]) - 1 do begin 83 NewCell := TCell.Create; 84 NewCell.Visible := Boolean(Random(2)); 85 NewCell.Name := IntToStr(C); 86 Map.Cells[Y, X] := NewCell; 87 //Map.Cells[Y, X].Color := Boolean(Random(2)); 88 Inc(C); 89 end; 90 end; 91 92 destructor TGame.Destroy; 93 begin 94 FreeAndNil(Player); 95 FreeAndNil(Map); 96 inherited Destroy; 120 for X := 0 to Length(Map.Cells[0]) - 1 do 121 with Map.Cells[Y, X] do begin 122 if Random(2) = 0 then Terrain := ttVoid 123 else Terrain := ttNormal; 124 Power := Random(4); 125 end; 126 for I := 0 to Players.Count - 1 do 127 with TPlayer(Players[I]) do begin 128 StartCell := Map.Cells[Random(Length(Map.Cells)), Random(Length(Map.Cells[0]))]; 129 StartCell.Terrain := ttNormal; 130 StartCell.Player := TPlayer(Players[I]); 131 end; 97 132 end; 98 133 … … 129 164 LineTo(Round(X + 0 * HexSize.X), Round(Y - 0.5 * HexSize.Y)); 130 165 *) 166 Font.Color := clWhite; 131 167 TextOut(Round(X) - TextWidth(Text) div 2, Round(Y) - TextHeight(Text) div 2, Text); 132 168 end; … … 139 175 with Canvas do try 140 176 Lock; 141 for CY := Trunc(Rect.Top / CellSize.Y) to Trunc(Rect.Bottom / CellSize.Y) do142 for CX := Trunc(Rect.Left / CellSize.X) to Trunc(Rect.Right / CellSize.X) do begin177 for CY := Trunc(Rect.Top / CellSize.Y) to Trunc(Rect.Bottom / CellSize.Y) + 1 do 178 for CX := Trunc(Rect.Left / CellSize.X) to Trunc(Rect.Right / CellSize.X) + 1 do begin 143 179 X := CX - Trunc(Rect.Left / CellSize.X); 144 180 Y := CY - Trunc(Rect.Top / CellSize.Y); … … 148 184 end; 149 185 if (CX >= 0) and (CY >= 0) and (CY < Length(Cells)) and (CX < Length(Cells[0])) then 150 if Cells[CY, CX].Visible then 151 PaintHexagon(X * CellSize.X - Frac(Rect.Left / CellSize.X) * CellSize.X, 152 Y * CellSize.Y - Frac(Rect.Top / CellSize.Y) * CellSize.Y, Cells[CY, CX].Name); 153 //Break; 186 if Cells[CY, CX].Terrain = ttNormal then begin 187 Brush.Color := Cells[CY, CX].GetColor; 188 PaintHexagon(X * CellSize.X - Frac(Rect.Left / CellSize.X) * CellSize.X, 189 Y * CellSize.Y - Frac(Rect.Top / CellSize.Y) * CellSize.Y, IntToStr(Cells[CY, CX].Power)); 190 end; 154 191 end; 155 192 finally … … 163 200 end; 164 201 202 procedure TMap.Init(Size: TPoint); 203 var 204 X, Y: Integer; 205 NewCell: TCell; 206 C: Integer; 207 begin 208 // Free previous 209 for Y := 0 to Length(Cells) - 1 do 210 for X := 0 to Length(Cells[0]) - 1 do begin 211 Cells[Y, X].Destroy; 212 end; 213 // Allocate and init new 214 SetLength(Cells, Size.X, Size.Y); 215 for Y := 0 to Length(Cells) - 1 do 216 for X := 0 to Length(Cells[0]) - 1 do begin 217 NewCell := TCell.Create; 218 Cells[Y, X] := NewCell; 219 end; 220 end; 221 165 222 end. 166 223 -
trunk/xtactics.lpi
r2 r3 43 43 <IsPartOfProject Value="True"/> 44 44 <ComponentName Value="FormMain"/> 45 <HasResources Value="True"/> 45 46 <ResourceBaseClass Value="Form"/> 46 47 <UnitName Value="UFormMain"/>
Note:
See TracChangeset
for help on using the changeset viewer.