Changeset 9
- Timestamp:
- Feb 12, 2014, 10:58:00 PM (11 years ago)
- Location:
- trunk
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/UFormMain.lfm
r7 r9 1 1 object FormMain: TFormMain 2 Left = 5 262 Left = 503 3 3 Height = 621 4 Top = 2 704 Top = 263 5 5 Width = 775 6 6 Caption = 'xTactics' … … 12 12 OnShow = FormShow 13 13 LCLVersion = '1.3' 14 WindowState = wsMaximized 14 15 object PaintBox1: TPaintBox 15 16 Left = 0 … … 52 53 end 53 54 object ActionList1: TActionList 54 left = 22 355 left = 224 55 56 top = 49 56 57 object AGameNew: TAction 57 58 Caption = 'New' 58 59 OnExecute = AGameNewExecute 60 ShortCut = 16462 59 61 end 60 62 object AExit: TAction 61 63 Caption = 'Exit' 62 64 OnExecute = AExitExecute 65 ShortCut = 32883 63 66 end 64 67 object AGameEnd: TAction 65 68 Caption = 'End' 69 ShortCut = 16454 66 70 end 67 71 object AGameEndTurn: TAction 68 72 Caption = 'End turn' 73 OnExecute = AGameEndTurnExecute 74 ShortCut = 16468 69 75 end 70 76 object AGameRestart: TAction 71 77 Caption = 'Restart' 78 ShortCut = 16466 72 79 end 73 80 end -
trunk/UFormMain.pas
r8 r9 34 34 Timer1: TTimer; 35 35 procedure AExitExecute(Sender: TObject); 36 procedure AGameEndTurnExecute(Sender: TObject); 36 37 procedure AGameNewExecute(Sender: TObject); 37 38 procedure FormCreate(Sender: TObject); … … 92 93 RedrawPending := False; 93 94 PaintBox1.Repaint; 95 Caption := Game.CurrentPlayer.Name + ' - xTactics'; 94 96 end; 95 97 end; … … 108 110 begin 109 111 Application.Terminate; 112 end; 113 114 procedure TFormMain.AGameEndTurnExecute(Sender: TObject); 115 begin 116 Game.NextTurn; 117 Redraw; 110 118 end; 111 119 … … 128 136 begin 129 137 Game.New; 138 Redraw; 130 139 end; 131 140 -
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.