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
Commits
52a34777
Commit
52a34777
authored
4 years ago
by
Mathias
Browse files
Options
Downloads
Patches
Plain Diff
First part of the TP.
parent
b6abba86
No related branches found
No related tags found
No related merge requests found
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
Cell.java
+7
-1
7 additions, 1 deletion
Cell.java
GameOfLifeGUI.java
+7
-2
7 additions, 2 deletions
GameOfLifeGUI.java
Grid.java
+39
-1
39 additions, 1 deletion
Grid.java
with
53 additions
and
4 deletions
Cell.java
+
7
−
1
View file @
52a34777
...
@@ -5,10 +5,16 @@
...
@@ -5,10 +5,16 @@
public
class
Cell
{
public
class
Cell
{
private
boolean
isAlive
;
private
boolean
isAlive
;
private
String
color
=
"Blue"
;
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
+
7
−
2
View file @
52a34777
...
@@ -39,8 +39,13 @@ public class GameOfLifeGUI extends JFrame {
...
@@ -39,8 +39,13 @@ 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
())
if
(
g
.
getCell
(
x
,
y
).
isAlive
())
{
if
((
g
.
getCell
(
x
,
y
).
getColor
()).
equals
(
"Red"
))
{
label
.
setForeground
(
Color
.
red
);
label
.
setForeground
(
Color
.
red
);
}
else
{
label
.
setForeground
(
Color
.
blue
);
}
}
else
else
label
.
setForeground
(
Color
.
white
);
label
.
setForeground
(
Color
.
white
);
}
}
...
...
This diff is collapsed.
Click to expand it.
Grid.java
+
39
−
1
View file @
52a34777
...
@@ -119,7 +119,12 @@ public class Grid implements Iterable<Cell> {
...
@@ -119,7 +119,12 @@ public class Grid implements Iterable<Cell> {
}
}
private
boolean
calculateNextState
(
int
rowIndex
,
int
columnIndex
,
Cell
cell
)
{
private
boolean
calculateNextState
(
int
rowIndex
,
int
columnIndex
,
Cell
cell
)
{
return
cell
.
isAliveInNextState
(
this
.
countAliveNeighbours
(
rowIndex
,
columnIndex
));
boolean
Nextstate
=
cell
.
isAliveInNextState
(
this
.
countAliveNeighbours
(
rowIndex
,
columnIndex
));
if
(
Nextstate
)
{
cell
.
setColor
(
this
.
countColorNeighbours
(
rowIndex
,
columnIndex
));
}
return
Nextstate
;
}
}
private
int
countAliveNeighbours
(
int
rowIndex
,
int
columnIndex
)
{
private
int
countAliveNeighbours
(
int
rowIndex
,
int
columnIndex
)
{
...
@@ -132,6 +137,31 @@ public class Grid implements Iterable<Cell> {
...
@@ -132,6 +137,31 @@ public class Grid implements Iterable<Cell> {
return
CounterAliveCell
;
return
CounterAliveCell
;
}
}
private
String
countColorNeighbours
(
int
rowIndex
,
int
columnIndex
)
{
String
CounterColorCell
;
int
Red
=
0
;
int
Blue
=
0
;
for
(
Cell
NeighboursCell
:
this
.
getNeighbours
(
rowIndex
,
columnIndex
))
{
if
(
NeighboursCell
.
isAlive
())
{
if
((
NeighboursCell
.
getColor
()).
equals
(
"Red"
))
{
Red
+=
1
;
}
else
{
Blue
+=
1
;
}
}
}
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
)
{
List
<
Cell
>
Neighbours
=
new
ArrayList
<>();
List
<
Cell
>
Neighbours
=
new
ArrayList
<>();
...
@@ -167,10 +197,18 @@ public class Grid implements Iterable<Cell> {
...
@@ -167,10 +197,18 @@ public class Grid implements Iterable<Cell> {
*/
*/
void
randomGeneration
(
Random
random
)
{
void
randomGeneration
(
Random
random
)
{
for
(
Iterator
<
Cell
>
it
=
this
.
iterator
();
it
.
hasNext
();
)
{
for
(
Iterator
<
Cell
>
it
=
this
.
iterator
();
it
.
hasNext
();
)
{
Cell
cell
=
it
.
next
();
Cell
cell
=
it
.
next
();
if
(
random
.
nextBoolean
())
{
if
(
random
.
nextBoolean
())
{
cell
.
setAlive
();
cell
.
setAlive
();
if
(
random
.
nextBoolean
())
{
cell
.
setColor
(
"Red"
);
}
else
{
cell
.
setColor
(
"Blue"
);
}
}
}
else
{
else
{
cell
.
setDead
();
cell
.
setDead
();
...
...
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