-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuttoncolorchange.lpr
145 lines (126 loc) · 4.45 KB
/
buttoncolorchange.lpr
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
program LoadHexGridFromCSVwithvertice;
uses
raylib, sysutils, classes;
type
TEmplacement = (inconnu, CoinHG, CoinHD, CoinBG, CoinBD, BordH, BordB, BordG, BordD, Classic);
// Structure d'un hexagone avec un numéro, centre, couleur, sélection et voisins
THexCell = record
Number: integer; // Numéro de l'hexagone
Center: TPoint; // Point central de l'hexagone
Vertices: array[0..5] of TPoint; // Les 6 sommets de l'hexagone
Color: TColor; // Couleur de l'hexagone
Selected: boolean; // État de sélection par clic
Neighbors: array[1..6] of integer; // Numéros des voisins contigus (6 voisins)
Colonne: integer; // Colonne de l'hexagone
Ligne: integer; // Ligne de l'hexagone
Poshexagone: TEmplacement; // Emplacement pour la stratégie des voisins
PairImpairLigne: boolean; // Aide à déterminer les voisins
end;
const
TotalNbreHex =100; // Total des hexagones
LoadFileName = 'hexgrid.csv';
var
HexGrid: array[1..TotalNbreHex] of THexCell;
i: Integer;
// Fonction pour convertir une chaîne en couleur
function StringToColor(const ColorStr: string): TColor;
var
Colors: TStringArray;
begin
Colors := ColorStr.Split([',']);
Result.r := StrToInt(Colors[0]);
Result.g := StrToInt(Colors[1]);
Result.b := StrToInt(Colors[2]);
Result.a := 255; // Alpha par défaut
end;
// Fonction pour convertir une chaîne en TEmplacement
function StringToEmplacement(const EmplacementStr: string): TEmplacement;
begin
if EmplacementStr = 'CoinHG' then
Result := CoinHG
else if EmplacementStr = 'CoinHD' then
Result := CoinHD
else if EmplacementStr = 'CoinBG' then
Result := CoinBG
else if EmplacementStr = 'CoinBD' then
Result := CoinBD
else if EmplacementStr = 'BordH' then
Result := BordH
else if EmplacementStr = 'BordB' then
Result := BordB
else if EmplacementStr = 'BordG' then
Result := BordG
else if EmplacementStr = 'BordD' then
Result := BordD
else
Result := Classic;
end;
// Procédure pour charger la structure HexGrid depuis un fichier CSV, y compris les vertices
procedure LoadHexGridFromCSV();
var
F: TextFile;
Line: string;
Fields: TStringArray;
i, k: Integer;
begin
AssignFile(F, LoadFileName);
Reset(F);
try
// Ignorer l'en-tête
Readln(F, Line);
i := 1;
while not EOF(F) do
begin
Readln(F, Line);
Fields := Line.Split([',']);
// Charger les valeurs depuis le fichier CSV dans la structure HexCell
HexGrid[i].Number := StrToInt(Fields[0]);
HexGrid[i].Center.x := StrToInt(Fields[1]);
HexGrid[i].Center.y := StrToInt(Fields[2]);
HexGrid[i].Color := StringToColor(Fields[3] + ',' + Fields[4] + ',' + Fields[5]);
HexGrid[i].Selected := StrToBool(Fields[6]);
HexGrid[i].Colonne := StrToInt(Fields[7]);
HexGrid[i].Ligne := StrToInt(Fields[8]);
HexGrid[i].Poshexagone := StringToEmplacement(Fields[9]);
HexGrid[i].PairImpairLigne := StrToBool(Fields[10]);
// Charger les vertices
for k := 0 to 5 do
begin
HexGrid[i].Vertices[k].x := StrToInt(Fields[11 + k * 2]); // Coordonnée X des vertices
HexGrid[i].Vertices[k].y := StrToInt(Fields[12 + k * 2]); // Coordonnée Y des vertices
end;
// Charger les voisins
HexGrid[i].Neighbors[1] := StrToInt(Fields[23]);
HexGrid[i].Neighbors[2] := StrToInt(Fields[24]);
HexGrid[i].Neighbors[3] := StrToInt(Fields[25]);
HexGrid[i].Neighbors[4] := StrToInt(Fields[26]);
HexGrid[i].Neighbors[5] := StrToInt(Fields[27]);
HexGrid[i].Neighbors[6] := StrToInt(Fields[28]);
Inc(i);
end;
finally
CloseFile(F);
end;
end;
// Initialisation de la fenêtre Raylib
procedure InitializeWindow();
begin
InitWindow(800, 600, 'Hexagonal Grid - Load from CSV');
SetTargetFPS(60);
end;
// Fonction principale
begin
// Initialisation de la fenêtre Raylib
InitializeWindow();
// Charger la grille hexagonale depuis un fichier CSV
LoadHexGridFromCSV();
// Boucle principale (vide ici car on se concentre sur le chargement)
while not WindowShouldClose() do
begin
BeginDrawing();
ClearBackground(RAYWHITE);
DrawText('HexGrid has been loaded from hexgrid.csv', 100, 100, 20, DARKGRAY);
EndDrawing();
end;
CloseWindow();
end.