Changeset 9 for trunk/UGame.pas
- Timestamp:
- Feb 12, 2014, 10:58:00 PM (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/UGame.pas
r8 r9 34 34 private 35 35 public 36 MaxPower: Integer; 36 37 DefaultCellSize: TPoint; 37 38 Cells: array of array of TCell; … … 43 44 destructor Destroy; override; 44 45 procedure Init(Size: TPoint); 46 procedure Grow(APlayer: TPlayer); 45 47 end; 46 48 … … 65 67 Map: TMap; 66 68 VoidEnabled: Boolean; 69 CurrentPlayer: TPlayer; 70 procedure NextTurn; 67 71 constructor Create; 68 72 destructor Destroy; override; … … 99 103 end; 100 104 105 function IsCellsNeighbor(Cell1, Cell2: TPoint): Boolean; 106 var 107 DX: Integer; 108 DY: Integer; 109 MinY: Integer; 110 begin 111 if Cell1.Y < Cell2.Y then MinY:= Cell1.Y 112 else MinY := Cell2.Y; 113 DX := Cell2.X - Cell1.X; 114 DY := Cell2.Y - Cell1.Y; 115 Result := (Abs(DX) <= 1) and (Abs(DY) <= 1) and 116 ((((MinY mod 2) = 1) and 117 not ((DX = 1) and (DY = -1)) and 118 not ((DX = -1) and (DY = 1))) or 119 (((MinY mod 2) = 0) and 120 not ((DX = -1) and (DY = -1)) and 121 not ((DX = 1) and (DY = 1)))); 122 end; 123 101 124 { TCell } 102 125 … … 114 137 begin 115 138 NewSelectedCell := Game.Map.PosToCell(Pos, View, ViewZoom); 116 if (NewSelectedCell.X = SelectedCell.X) and (NewSelectedCell.Y = SelectedCell.Y) then 117 SelectedCell := Point(-1, -1) 118 else SelectedCell := NewSelectedCell; 139 if (NewSelectedCell.X >= 0) and (NewSelectedCell.X < Length(Game.Map.Cells[0])) and 140 (NewSelectedCell.Y >= 0) and (NewSelectedCell.Y < Length(Game.Map.Cells)) then begin 141 if IsCellsNeighbor(NewSelectedCell, SelectedCell) then begin 142 // Attack 143 TCell(Game.Map.Cells[NewSelectedCell.Y, NewSelectedCell.X]).Player := Self; 144 TCell(Game.Map.Cells[NewSelectedCell.Y, NewSelectedCell.X]).Power := 145 TCell(Game.Map.Cells[NewSelectedCell.Y, NewSelectedCell.X]).Power + 146 TCell(Game.Map.Cells[SelectedCell.Y, SelectedCell.X]).Power; 147 TCell(Game.Map.Cells[SelectedCell.Y, SelectedCell.X]).Power := 0; 148 SelectedCell := Point(-1, -1); 149 end else 150 if (NewSelectedCell.X <> SelectedCell.X) and (NewSelectedCell.Y <> SelectedCell.Y) and 151 (TCell(Game.Map.Cells[NewSelectedCell.Y, NewSelectedCell.X]).Player = Self) then 152 SelectedCell := NewSelectedCell 153 else 154 if (NewSelectedCell.X = SelectedCell.X) and (NewSelectedCell.Y = SelectedCell.Y) and 155 (TCell(Game.Map.Cells[NewSelectedCell.Y, NewSelectedCell.X]).Player = Self) then 156 SelectedCell := Point(-1, -1); 157 end; 119 158 end; 120 159 … … 127 166 begin 128 167 ViewZoom := 1; 168 SelectedCell := Point(-1, -1); 129 169 end; 130 170 131 171 { TGame } 172 173 procedure TGame.NextTurn; 174 begin 175 Map.Grow(CurrentPlayer); 176 CurrentPlayer := TPlayer(Players[(Players.IndexOf(CurrentPlayer) + 1) mod Players.Count]); 177 end; 132 178 133 179 constructor TGame.Create; … … 137 183 Players := TObjectList.Create; 138 184 Player := TPlayer.Create; 185 Player.Name := 'Player 1'; 139 186 Player.Game := Self; 140 187 Player.Color := clBlue; 141 188 Players.Add(Player); 142 189 Player := TPlayer.Create; 190 Player.Name := 'Player 2'; 143 191 Player.Game := Self; 144 192 Player.Color := clRed; 145 193 Players.Add(Player); 194 195 //VoidEnabled := True; 146 196 147 197 Map := TMap.Create; … … 176 226 StartCell.Player := TPlayer(Players[I]); 177 227 end; 228 CurrentPlayer := TPlayer(Players[0]); 178 229 end; 179 230 … … 261 312 if Cells[CY, CX].Terrain = ttNormal then begin 262 313 if (SelectedCell.X = CX) and (SelectedCell.Y = CY) then Brush.Color := clGreen 314 else if IsCellsNeighbor(SelectedCell, Point(CX, CY)) then Brush.Color := clPurple 263 315 else Brush.Color := Cells[CY, CX].GetColor; 264 316 PaintHexagon(X * CellSize.X - Frac(Rect.Left / CellSize.X) * CellSize.X, … … 274 326 begin 275 327 DefaultCellSize := Point(62, 62); 328 MaxPower := 99; 276 329 end; 277 330 … … 302 355 end; 303 356 357 procedure TMap.Grow(APlayer: TPlayer); 358 var 359 X, Y: Integer; 360 begin 361 for Y := 0 to Length(Cells) - 1 do 362 for X := 0 to Length(Cells[0]) - 1 do 363 with TCell(Cells[Y, X]) do begin 364 if Player = APlayer then begin 365 Power := Power + 1; 366 if Power > MaxPower then Power := MaxPower; 367 end; 368 end; 369 end; 370 304 371 end. 305 372
Note:
See TracChangeset
for help on using the changeset viewer.