Génération d'une carte aléatoire
Bonjour,
Avant d'énoncé mon problème, j'aimerais vous remercier car ce site est une véritable mine d'or et cela m'a beaucoup servi dans plusieurs projets. Encore merci !
Donc mon souci c'est que je souhaiterais, grâce à un bouton, générer une carte de façon aléatoire.
Je m'explique.
Dans le célèbre jeu Minecraft on trouve différentes zones, appélées biomes, qui sont des zones aux climats différents (prairie, taïga, océan...), et donc ce que je voudrais c'est une génération d'une carte cohérente (dans le sens où il n'y a pas des petits pixels un peu partout mais qu'il y ait de réels continents et océans et que qu'on ne retrouve pas, par exemple, un désert à côté d'une zone enneigée) avec différentes couleurs représentatives des différents biomes.
Donc je suppose qu'il faudrait tout d'abord remplir une ou plusieurs cellules d'une couleur spécifique et ensuite analysé la couleur du remplissage de ces cellules et avec une certaine probabilité coloré les cellules suivantes.
Mon soucis est donc, plus précisément, de comment analyser les cellules de façon efficace afin de permettre la création de la carte.
Private Sub Carte_Click()
'1 MER bleu denim
MER_R = 21
MER_G = 96
MER_B = 189
MER = RGB(MER_R, MER_G, MER_B)
'2 PRAIRIE vert prairie
PRAIRIE_R = 87
PRAIRIE_G = 213
PRAIRIE_B = 59
PRAIRIE = RGB(PRAIRIE_R, PRAIRIE_G, PRAIRIE_B)
'3 MONTAGNE terre d'ombre
MONTAGNE_R = 146
MONTAGNE_G = 109
MONTAGNE_B = 39
MONTAGNE = RGB(MONTAGNE_R, MONTAGNE_G, MONTAGNE_B)
'4 TAIGA blanc neige
TAIGA_R = 254
TAIGA_G = 254
TAIGA_B = 254
TAIGA = RGB(TAIGA_R, TAIGA_G, TAIGA_B)
'5 DESERT sable
DESERT_R = 224
DESERT_G = 205
DESERT_B = 169
DESERT = RGB(DESERT_R, DESERT_G, DESERT_B)
'Nombre de biome
Nb_b = 3
'Coordonnées
latitude = 80
longitude = 80
'Intérieur de la Carte
Range(Cells(2, 2), Cells(latitude + 1, longitude + 1)).Interior.Color = xlNone
'Bords de la Carte
Cells(1, 1).Interior.Color = RGB(0, 0, 0)
Cells(1, 1).Borders.Weight = xlMedium
Cells(latitude + 2, 1).Interior.Color = RGB(0, 0, 0)
Cells(latitude + 2, 1).Borders.Weight = xlMedium
Cells(1, longitude + 2).Interior.Color = RGB(0, 0, 0)
Cells(1, longitude + 2).Borders.Weight = xlMedium
Cells(latitude + 2, longitude + 2).Interior.Color = RGB(0, 0, 0)
Cells(latitude + 2, longitude + 2).Borders.Weight = xlMedium
'Première Ligne
For c = 1 To longitude
Cells(1, c + 1) = c
Next
Range(Cells(1, 2), Cells(1, longitude + 1)).Borders.Weight = xlMedium
'Dernière Ligne
For c = 1 To longitude
Cells(latitude + 2, c + 1) = c
Next
Range(Cells(latitude + 2, 2), Cells(latitude + 2, longitude + 1)).Borders.Weight = xlMedium
'Première Colonne
For l = 1 To latitude
Cells(l + 1, 1) = l
Next
Range(Cells(2, 1), Cells(latitude + 1, 1)).Borders.Weight = xlMedium
'Dernière Colonne
For l = 1 To latitude
Cells(l + 1, longitude + 2) = l
Next
Range(Cells(2, longitude + 2), Cells(latitude + 1, longitude + 2)).Borders.Weight = xlMedium
'Première Ligne carte
For c = 1 To longitude
Cells(2, c + 1).Interior.Color = MER
Next
'Dernière Ligne carte
For c = 1 To longitude
Cells(latitude + 1, c + 1).Interior.Color = MER
Next
'Première Colonne carte
For l = 1 To latitude
Cells(l + 1, 2).Interior.Color = MER
Next
'Dernière Colonne carte
For l = 1 To latitude
Cells(l + 1, longitude + 1).Interior.Color = MER
Next
For l = 3 To latitude
For c = 3 To longitude
If Cells(l - 1, c - 1).Interior.Color = MER And Cells(l - 1, c).Interior.Color = MER And Cells(l - 1, c + 1).Interior.Color = MER And Cells(l + 1, c - 1).Interior.Color = MER And Cells(l, c - 1).Interior.Color = MER Then 'Analyse de la couleur autour de la cellule
biome = Int(Nb_b * Rnd) + 1
If biome = 1 Then
Cells(l, c).Interior.Color = MER
ElseIf biome = 2 Then
Cells(l, c).Interior.Color = PRAIRIE
ElseIf biome = 3 Then
Cells(l, c).Interior.Color = MONTAGNE
ElseIf biome = 4 Then
Cells(l, c).Interior.Color = TAIGA
ElseIf biome = 5 Then
Cells(l, c).Interior.Color = DESERT
End If
End If
Next
Next
End SubJe vous présente donc ici ce que j'ai déjà fais à présent et après avoir taper ces dernière lignes :
For l = 3 To latitude
For c = 3 To longitude
If Cells(l - 1, c - 1).Interior.Color = MER And Cells(l - 1, c).Interior.Color = MER And Cells(l - 1, c + 1).Interior.Color = MER And Cells(l + 1, c - 1).Interior.Color = MER And Cells(l, c - 1).Interior.Color = MER Then 'Analyse de la couleur autour de la cellule
biome = Int(Nb_b * Rnd) + 1
If biome = 1 Then
Cells(l, c).Interior.Color = MER
ElseIf biome = 2 Then
Cells(l, c).Interior.Color = PRAIRIE
ElseIf biome = 3 Then
Cells(l, c).Interior.Color = MONTAGNE
ElseIf biome = 4 Then
Cells(l, c).Interior.Color = TAIGA
ElseIf biome = 5 Then
Cells(l, c).Interior.Color = DESERT
End If
End If
Next
Next Je me suis dis que j'ai une nombre incalculable de cas possible...
J'espère que mes explications sont claires et si ce n'est pas le cas n'hésitez pas à me demander de rentrer plus dans les détails !
Donc si quelqu'un peux m'aider je suis preneur
Personne ne voit de solution à mon problème ? Mon message n'est peut-être pas assez clair, je ne sais pas ?
bonsoir,
je vais jeter un oeil
bonsoir,
voici un essai de génération de carte.
plusieurs paramètres permettent de piloter la génération de la carte. tu trouveras des explications dans l'onglet paramètres.
lancer par alt F8.