-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsecteur.php
More file actions
158 lines (137 loc) · 3.61 KB
/
Copy pathsecteur.php
File metadata and controls
158 lines (137 loc) · 3.61 KB
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
146
147
148
149
150
151
152
153
154
155
156
157
158
<?php
include_once ("constantes_carte.php");
class Secteur {
private $secteurType;
private $secteurVolume;
private $secteurOrdre;
private $posX;
private $posY;
private $asteroids;
private $planete;
private $epave;
// constantes secteurs
//const TAUX_ASTEROIDE = 220;
//const TAUX_PLANETE = 30;
//const TAUX_EPAVE = 15;
//const TAUX_TROU_NOIR = 3;
//const VOLUME_SECTEUR_MIN = 20;
//const VOLUME_SECTEUR_MAX = 40;
// Constantes asteroides
//const ASTEROIDE_TAUX = [2,7,12,30,40,50];
//const ASTEROIDE_VOLUME = [20,12,8,5,2,1];
//const MINERAI_VOLUME_MIN = [10000,3000,1000,300,100,50];
//const MINERAI_VOLUME_MAX = [50000,10000,3000,1000,300,100];
// constantes planetes et lunes
// const NB_PLANETE_MIN = 2;
// const NB_PLANETE_MAX = 9;
// const TAUX_LUNE = 60;
// constantes epaves
//const TAUX_TYPE_EPAVE = [50,15,30,5];
//const NB_EPAVE_MIN = [2,1,1,1];
//const NB_EPAVE_MAX = [12,1,1,1];
public function __construct($posY, $posX) {
$this->posX = $posX;
$this->posY = $posY;
$this->secteurType = $this->randomise_secteur();
$this->secteurVolume = rand(VOLUME_SECTEUR_MIN,VOLUME_SECTEUR_MAX);
$this->secteurOrdre = 0;
$this->asteroids = array();
switch ($this->secteurType) {
case 0:
return 0;
break;
case 1:
$this->generer_asteroids();
break;
case 2:
$this->generer_planetes();
break;
case 3:
$this->generer_epaves();
break;
case 4:
// Trous noir, rien à générer
break;
}
}
private function randomise_secteur() {
$t=mt_rand(1,1000);
$type=0;
if($t <= TAUX_ASTEROIDE) {
$type=1;
}
if($t <= TAUX_PLANETE) {
$type=2;
}
if($t <= TAUX_EPAVE) {
$type=3;
}
if($t <= TAUX_TROU_NOIR) {
$type=4;
}
return $type;
}
private function generer_asteroids() {
$i=0;
while ($this->secteurVolume<>0) {
if (rand(1,100)<=ASTEROIDE_TAUX[$i] AND $this->secteurVolume-ASTEROIDE_VOLUME[$i]>=0) {
array_push($this->asteroids, new Asteroid(rand(MINERAI_VOLUME_MIN[$i],MINERAI_VOLUME_MAX[$i])));
$this->secteurVolume-=ASTEROIDE_VOLUME[$i];
}
$i++;
if ($i==count(ASTEROIDE_VOLUME)) {
$i=0;
}
}
}
private function generer_planetes() {
$planetes_nb=rand(NB_PLANETE_MIN,NB_PLANETE_MAX);
$p=0;
for ($i=1;$i<=$planetes_nb;$i++) {
if (rand(1,100)<TAUX_LUNE and $p==1){ // teste si la planete est une lune
new Lune;
} else {
new Planete;
}
$p=1;
}
}
private function generer_epaves() {
$tirage=rand(1,100);
$t=0; $epave_type=0;
while ($t<100) { // recherche du type d'epave
$t+=TAUX_TYPE_EPAVE[$epave_type];
if ($tirage<=$t) {
$t=100;
} else {
$epave_type++;
}
}
$epaves_nb=rand(NB_EPAVE_MIN[$epave_type],NB_EPAVE_MAX[$epave_type]); // tirage du nombre d'epaves
for ($i=1;$i<=$epaves_nb;$i++) {
new Epave($epave_type);
}
}
public function getPosX() {
return $this->posX;
}
public function getPosY() {
return $this->posY;
}
public function getSecteurVolume() {
return $this->secteurVolume;
}
public function getSecteurType() {
return $this->secteurType;
}
public function getSecteurOrdre() {
return $this->secteurOrdre;
}
public function setSecteurType($type) { // utile pour affecter les secteurs de pop
$this->secteurType = $type;
}
public function setSecteurOrdre($ordre) { // utile pour affecter l'odre de pop des secteurs de pop
$this->secteurOrdre = $ordre;
}
}
?>