Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Johan Gustav Thrane-Nielsen
inf101.v20.sem2.losning
Commits
b6925aa9
Commit
b6925aa9
authored
Mar 25, 2020
by
Anna Maria Eilertsen
Browse files
renamed methods for consistency
parent
91005af4
Changes
2
Show whitespace changes
Inline
Side-by-side
src/main/java/inf101/v20/sem2/mnkgames/GUI/MNKGameGUI.java
View file @
b6925aa9
...
@@ -77,7 +77,7 @@ s * Initializes a JFrame in which we place the game
...
@@ -77,7 +77,7 @@ s * Initializes a JFrame in which we place the game
}
}
private
void
reset
(
MNKGame
newGame
)
{
private
void
reset
(
MNKGame
newGame
)
{
this
.
game
=
game
.
getN
ewGame
(
newGame
);
this
.
game
=
game
.
n
ewGame
(
newGame
);
updateMessage
();
updateMessage
();
removeAll
();
removeAll
();
initialize
();
initialize
();
...
@@ -101,9 +101,9 @@ s * Initializes a JFrame in which we place the game
...
@@ -101,9 +101,9 @@ s * Initializes a JFrame in which we place the game
*/
*/
private
void
updateMessage
()
{
private
void
updateMessage
()
{
if
(
game
.
hasWinner
())
if
(
game
.
hasWinner
())
statusMessage
.
setText
(
"The game is over! The winner is "
+
game
.
getW
inner
());
statusMessage
.
setText
(
"The game is over! The winner is "
+
game
.
w
inner
());
else
if
(
game
.
hasPossibleMoves
())
{
else
if
(
game
.
hasPossibleMoves
())
{
statusMessage
.
setText
(
"Next move from "
+
game
.
getC
urrentPlayer
());
statusMessage
.
setText
(
"Next move from "
+
game
.
c
urrentPlayer
());
}
else
{
}
else
{
statusMessage
.
setText
(
"The game is over! No one won."
);
statusMessage
.
setText
(
"The game is over! No one won."
);
}
}
...
@@ -192,7 +192,7 @@ s * Initializes a JFrame in which we place the game
...
@@ -192,7 +192,7 @@ s * Initializes a JFrame in which we place the game
@Override
@Override
public
Color
getBackground
()
{
public
Color
getBackground
()
{
return
pieceToColor
(
game
.
getP
ieceAt
(
x
,
y
));
return
pieceToColor
(
game
.
p
ieceAt
(
x
,
y
));
}
}
}
}
...
...
src/main/java/inf101/v20/sem2/mnkgames/gameplay/TwoPlayerGame.java
View file @
b6925aa9
...
@@ -80,11 +80,11 @@ public class TwoPlayerGame<T extends MNKGame> {
...
@@ -80,11 +80,11 @@ public class TwoPlayerGame<T extends MNKGame> {
return
p1
.
name
();
return
p1
.
name
();
}
}
public
String
getP
layer2
()
{
public
String
p
layer2
()
{
return
p2
.
name
();
return
p2
.
name
();
}
}
public
String
getC
urrentPlayer
()
{
public
String
c
urrentPlayer
()
{
return
currentPlayer
.
name
();
return
currentPlayer
.
name
();
}
}
...
@@ -92,19 +92,23 @@ public class TwoPlayerGame<T extends MNKGame> {
...
@@ -92,19 +92,23 @@ public class TwoPlayerGame<T extends MNKGame> {
return
game
.
hasWinner
();
return
game
.
hasWinner
();
}
}
public
String
getW
inner
()
{
public
String
w
inner
()
{
return
getP
layerFromPiece
(
game
.
getWinner
());
return
p
layerFromPiece
(
game
.
getWinner
());
}
}
public
boolean
hasPossibleMoves
()
{
public
boolean
hasPossibleMoves
()
{
return
!
game
.
hasWinner
()
&&
game
.
hasPossibleMoves
();
return
!
game
.
hasWinner
()
&&
game
.
hasPossibleMoves
();
}
}
public
Piece
getP
ieceAt
(
int
x
,
int
y
)
{
public
Piece
p
ieceAt
(
int
x
,
int
y
)
{
return
game
.
getPieceAt
(
x
,
y
);
return
game
.
getPieceAt
(
x
,
y
);
}
}
public
String
getPlayerFromPiece
(
Piece
piece
)
{
public
boolean
hasPieceAt
(
int
x
,
int
y
)
{
return
game
.
getPieceAt
(
x
,
y
)
!=
Piece
.
NONE
;
}
public
String
playerFromPiece
(
Piece
piece
)
{
if
(
piece
.
equals
(
Piece
.
NONE
))
if
(
piece
.
equals
(
Piece
.
NONE
))
return
"No Player"
;
return
"No Player"
;
if
(
p1
.
getColor
()==
piece
)
if
(
p1
.
getColor
()==
piece
)
...
@@ -148,11 +152,8 @@ public class TwoPlayerGame<T extends MNKGame> {
...
@@ -148,11 +152,8 @@ public class TwoPlayerGame<T extends MNKGame> {
currentPlayer
=
next
();
currentPlayer
=
next
();
}
}
public
TwoPlayerGame
<
T
>
getN
ewGame
(
T
game
)
{
public
TwoPlayerGame
<
T
>
n
ewGame
(
T
game
)
{
return
new
TwoPlayerGame
<
T
>(
game
,
p1
,
p2
);
return
new
TwoPlayerGame
<
T
>(
game
,
p1
,
p2
);
}
}
public
boolean
hasPieceAt
(
int
x
,
int
y
)
{
return
game
.
getPieceAt
(
x
,
y
)
!=
Piece
.
NONE
;
}
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment