Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
P
Prog2Aix-tp3
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
FAURE Mathias
Prog2Aix-tp3
Compare revisions
master to master
Compare revisions
Changes are shown as if the
source
revision was being merged into the
target
revision.
Learn more about comparing revisions.
Source
f19003868/tp3
Select target project
No results found
master
Select Git revision
Branches
master
1 result
Swap
Target
das.s/tp3
Select target project
das.s/tp3
f19002502/tp3
r17010960/tp3
l19004806/tp3
y19010055/tp3
o18034026/tp3
z18029613/tp3
p19021289/tp3
d19027596/tp3
f18010428/tp3
f19003868/tp3
c19022214/tp3
c19017929/tp3
m16014784/tp3
a19028956/tp3
c19026071/tp3
h18008908/tp3
17 results
master
Select Git revision
Branches
master
1 result
Show changes
Only incoming changes from source
Include changes to target since source was created
Compare
Commits on Source (4)
First part of the TP.
· b6abba86
Mathias
authored
4 years ago
b6abba86
First part of the TP.
· 52a34777
Mathias
authored
4 years ago
52a34777
Tout le TP terminé.
· 18d9a2da
FAURE Mathias
authored
4 years ago
18d9a2da
Ajout de commentaires.
· 97481c2d
Mathias
authored
4 years ago
97481c2d
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
Cell.java
+8
-1
8 additions, 1 deletion
Cell.java
GameOfLifeGUI.java
+10
-2
10 additions, 2 deletions
GameOfLifeGUI.java
Grid.java
+108
-12
108 additions, 12 deletions
Grid.java
with
126 additions
and
15 deletions
Cell.java
View file @
97481c2d
...
@@ -5,10 +5,17 @@
...
@@ -5,10 +5,17 @@
public
class
Cell
{
public
class
Cell
{
private
boolean
isAlive
;
private
boolean
isAlive
;
//String qui garde la couleur de la cellule
private
String
color
=
"Red"
;
public
Cell
(){
public
Cell
(){
this
.
isAlive
=
false
;
this
.
isAlive
=
false
;
}
}
public
void
setColor
(
String
hisColor
)
{
color
=
hisColor
;
}
public
String
getColor
()
{
return
color
;
}
/**
/**
* Determines whether this {@link Cell} is alive or not.
* Determines whether this {@link Cell} is alive or not.
*
*
...
...
This diff is collapsed.
Click to expand it.
GameOfLifeGUI.java
View file @
97481c2d
...
@@ -39,8 +39,16 @@ public class GameOfLifeGUI extends JFrame {
...
@@ -39,8 +39,16 @@ public class GameOfLifeGUI extends JFrame {
for
(
int
x
=
0
;
x
<
numberOfColumns
;
x
++)
for
(
int
x
=
0
;
x
<
numberOfColumns
;
x
++)
for
(
int
y
=
0
;
y
<
numberOfRows
;
y
++){
for
(
int
y
=
0
;
y
<
numberOfRows
;
y
++){
JLabel
label
=
labelGrid
[
x
][
y
];
JLabel
label
=
labelGrid
[
x
][
y
];
if
(
g
.
getCell
(
x
,
y
).
isAlive
())
//On regarde ici si la cellule est vivante
if
(
g
.
getCell
(
x
,
y
).
isAlive
())
{
//On fonction de l'instance qui gère la couleur on change sa couleur sur la grille
if
((
g
.
getCell
(
x
,
y
).
getColor
()).
equals
(
"Red"
))
{
label
.
setForeground
(
Color
.
red
);
label
.
setForeground
(
Color
.
red
);
}
else
{
label
.
setForeground
(
Color
.
blue
);
}
}
//sinon on l'a met blanc
else
else
label
.
setForeground
(
Color
.
white
);
label
.
setForeground
(
Color
.
white
);
}
}
...
...
This diff is collapsed.
Click to expand it.
Grid.java
View file @
97481c2d
import
java.util.Arrays
;
import
java.util.*
;
import
java.util.Iterator
;
import
java.util.List
;
import
java.util.Random
;
/**
/**
* {@code Grid} instances represent the grid in <i>The Game of Life</i>.
* {@code Grid} instances represent the grid in <i>The Game of Life</i>.
...
@@ -98,29 +95,111 @@ public class Grid implements Iterable<Cell> {
...
@@ -98,29 +95,111 @@ public class Grid implements Iterable<Cell> {
}
}
private
boolean
[][]
calculateNextStates
()
{
private
boolean
[][]
calculateNextStates
()
{
return
null
;
//On crée une nouvelle matrice qui correspond à la prochaine grille
boolean
[][]
newState
=
new
boolean
[
getNumberOfRows
()][
getNumberOfColumns
()];
//On parcours toute la grille puis on fait appelle à la fonction calculateNextStates
for
(
int
r
=
0
;
r
<
numberOfRows
;
r
++)
{
for
(
int
c
=
0
;
c
<
numberOfColumns
;
c
++)
{
newState
[
r
][
c
]
=
this
.
calculateNextState
(
r
,
c
,
this
.
getCell
(
r
,
c
));
}
}
return
newState
;
}
private
void
goToNextState
(
boolean
[][]
nextState
)
{
//On utilise la nouvelle matrice pour savoir si la cellule est vivante ou non
for
(
int
r
=
0
;
r
<
numberOfRows
;
r
++)
{
for
(
int
c
=
0
;
c
<
numberOfColumns
;
c
++)
{
if
(
nextState
[
r
][
c
])
{
this
.
getCell
(
r
,
c
).
setAlive
();
}
else
{
this
.
getCell
(
r
,
c
).
setDead
();
}
}
}
}
}
private
boolean
calculateNextState
(
int
rowIndex
,
int
columnIndex
,
Cell
cell
)
{
private
boolean
calculateNextState
(
int
rowIndex
,
int
columnIndex
,
Cell
cell
)
{
return
false
;
//On fait appelle à la méthode de Cell pour savoir si la cellule est vivante
boolean
Nextstate
=
cell
.
isAliveInNextState
(
this
.
countAliveNeighbours
(
rowIndex
,
columnIndex
));
//C'est ici aussi que l'on change la couleur de la cellule en fonction de ses voisins en appelant la méthode setColor
if
(
Nextstate
)
{
if
(
this
.
countAliveNeighbours
(
rowIndex
,
columnIndex
)
!=
2
)
{
cell
.
setColor
(
this
.
countColorNeighbours
(
rowIndex
,
columnIndex
));
}
}
return
Nextstate
;
}
}
private
int
countAliveNeighbours
(
int
rowIndex
,
int
columnIndex
)
{
private
int
countAliveNeighbours
(
int
rowIndex
,
int
columnIndex
)
{
return
0
;
//Ici on compte le nombre de cellules voisines vivantes
int
CounterAliveCell
=
0
;
for
(
Cell
NeighboursCell
:
this
.
getNeighbours
(
rowIndex
,
columnIndex
))
{
if
(
NeighboursCell
.
isAlive
())
{
CounterAliveCell
+=
1
;
}
}
return
CounterAliveCell
;
}
private
String
countColorNeighbours
(
int
rowIndex
,
int
columnIndex
)
{
//On compte ici la couleur des voisins
String
CounterColorCell
;
int
Red
=
0
;
int
Blue
=
0
;
//On compte ici la couleur des voisins
for
(
Cell
NeighboursCell
:
this
.
getNeighbours
(
rowIndex
,
columnIndex
))
{
if
(
NeighboursCell
.
isAlive
())
{
if
((
NeighboursCell
.
getColor
()).
equals
(
"Red"
))
{
Red
+=
1
;
}
else
{
Blue
+=
1
;
}
}
}
//Et on fonction du nombre de couleur on change la couleur dans l'instance qui la gère
if
(
Red
>
Blue
)
{
CounterColorCell
=
"Red"
;
}
else
{
CounterColorCell
=
"Blue"
;
}
return
CounterColorCell
;
}
}
private
List
<
Cell
>
getNeighbours
(
int
rowIndex
,
int
columnIndex
)
{
private
List
<
Cell
>
getNeighbours
(
int
rowIndex
,
int
columnIndex
)
{
return
null
;
//On crée une liste de voisin
List
<
Cell
>
Neighbours
=
new
ArrayList
<>();
//On parcours les 8 voisins, en prenant compte à ne pas prendre la cellule de base, et on les ajoutes à la liste
for
(
int
r
=-
1
;
r
<=
1
;
r
++)
{
for
(
int
c
=-
1
;
c
<=
1
;
c
++)
{
if
((
r
!=
0
)
||
(
c
!=
0
))
{
Neighbours
.
add
(
this
.
getCell
(
rowIndex
+
r
,
columnIndex
+
c
));
}
}
}
}
private
void
goToNextState
(
boolean
[][]
nextState
)
{
return
Neighbours
;
}
}
/**
/**
* Sets all {@link Cell}s in this {@code Grid} as dead.
* Sets all {@link Cell}s in this {@code Grid} as dead.
*/
*/
void
clear
()
{
void
clear
()
{
//On tue toutes les cellules
for
(
Iterator
<
Cell
>
it
=
this
.
iterator
();
it
.
hasNext
();
)
{
Cell
cell
=
it
.
next
();
cell
.
setDead
();
}
}
}
/**
/**
...
@@ -131,6 +210,23 @@ public class Grid implements Iterable<Cell> {
...
@@ -131,6 +210,23 @@ public class Grid implements Iterable<Cell> {
*/
*/
void
randomGeneration
(
Random
random
)
{
void
randomGeneration
(
Random
random
)
{
//On utilise la méthode Iterator
for
(
Iterator
<
Cell
>
it
=
this
.
iterator
();
it
.
hasNext
();
)
{
Cell
cell
=
it
.
next
();
//Si le hasard a décidé que la cellule est vivante, on utilise ensuite la même méthode pour mettre sa couleur
if
(
random
.
nextBoolean
())
{
cell
.
setAlive
();
if
(
random
.
nextBoolean
())
{
cell
.
setColor
(
"Red"
);
}
else
{
cell
.
setColor
(
"Blue"
);
}
}
else
{
cell
.
setDead
();
}
}
}
}
}
}
\ No newline at end of file
This diff is collapsed.
Click to expand it.