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
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
MULLER Etienne
Prog2Aix-tp3
Commits
d75d0b87
Commit
d75d0b87
authored
Oct 13, 2020
by
etienne
Browse files
Options
Downloads
Patches
Plain Diff
bug de clignotement corrigé
parent
7c215aef
No related branches found
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
GameOfLifeGUI.java
+3
-2
3 additions, 2 deletions
GameOfLifeGUI.java
Grid.java
+11
-5
11 additions, 5 deletions
Grid.java
with
14 additions
and
7 deletions
GameOfLifeGUI.java
+
3
−
2
View file @
d75d0b87
...
@@ -22,8 +22,9 @@ public class GameOfLifeGUI extends JFrame {
...
@@ -22,8 +22,9 @@ public class GameOfLifeGUI extends JFrame {
labelGrid
[
x
][
y
]
=
new
JLabel
(
"*"
);
labelGrid
[
x
][
y
]
=
new
JLabel
(
"*"
);
JLabel
label
;
JLabel
label
;
if
(
g
.
getCell
(
x
,
y
).
isAlive
()){
if
(
g
.
getCell
(
x
,
y
).
isAlive
()){
if
(
g
.
getCell
(
x
,
y
).
isRed
())
labelGrid
[
x
][
y
].
setForeground
(
Color
.
red
);
labelGrid
[
x
][
y
].
setForeground
(
Color
.
red
);
else
labelGrid
[
x
][
y
].
setForeground
(
Color
.
BLUE
);
//if (g.getCell(x,y).isRed()) labelGrid[x][y].setForeground(Color.red);
//else labelGrid[x][y].setForeground(Color.BLUE);
}
}
else
else
labelGrid
[
x
][
y
].
setForeground
(
Color
.
white
);
labelGrid
[
x
][
y
].
setForeground
(
Color
.
white
);
...
...
This diff is collapsed.
Click to expand it.
Grid.java
+
11
−
5
View file @
d75d0b87
...
@@ -132,10 +132,15 @@ public class Grid implements Iterable<Cell> {
...
@@ -132,10 +132,15 @@ public class Grid implements Iterable<Cell> {
private
boolean
calculateNextColor
(
int
rowIndex
,
int
columnIndex
)
{
private
boolean
calculateNextColor
(
int
rowIndex
,
int
columnIndex
)
{
int
aliveNeighbours
=
countAliveNeighbours
(
rowIndex
,
columnIndex
);
//int aliveNeighbours = countAliveNeighbours(rowIndex,columnIndex);
int
redNeighbours
=
countRedNeighbours
(
rowIndex
,
columnIndex
);
//int redNeighbours = countRedNeighbours(rowIndex,columnIndex);
if
(
aliveNeighbours
==
3
)
return
(
redNeighbours
>
aliveNeighbours
-
redNeighbours
);
//if (aliveNeighbours == 3) return (redNeighbours >= aliveNeighbours - redNeighbours);
return
!(
redNeighbours
>
aliveNeighbours
-
redNeighbours
);
//return !(redNeighbours >= aliveNeighbours - redNeighbours);
if
(
getCell
(
rowIndex
,
columnIndex
).
isDead
()
&&
calculateNextState
(
rowIndex
,
columnIndex
)){
return
countRedNeighbours
(
rowIndex
,
columnIndex
)>=
countAliveNeighbours
(
rowIndex
,
columnIndex
)-
countRedNeighbours
(
rowIndex
,
columnIndex
);
}
return
getCell
(
rowIndex
,
columnIndex
).
isRed
();
}
}
private
int
countAliveNeighbours
(
int
rowIndex
,
int
columnIndex
)
{
private
int
countAliveNeighbours
(
int
rowIndex
,
int
columnIndex
)
{
...
@@ -226,8 +231,9 @@ public class Grid implements Iterable<Cell> {
...
@@ -226,8 +231,9 @@ public class Grid implements Iterable<Cell> {
for
(
int
row
=
0
;
row
<
this
.
numberOfRows
;
row
++){
for
(
int
row
=
0
;
row
<
this
.
numberOfRows
;
row
++){
for
(
int
col
=
0
;
col
<
this
.
numberOfColumns
;
col
++)
{
for
(
int
col
=
0
;
col
<
this
.
numberOfColumns
;
col
++)
{
if
(
random
.
nextBoolean
()){
if
(
random
.
nextBoolean
()){
this
.
cells
[
row
][
col
].
setAlive
();
this
.
cells
[
row
][
col
].
setColor
(
random
.
nextBoolean
());
this
.
cells
[
row
][
col
].
setColor
(
random
.
nextBoolean
());
this
.
cells
[
row
][
col
].
setAlive
();
}
}
}
}
}
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment