Package tk.dmanstrator.connectfour
Class Connect4
- java.lang.Object
-
- tk.dmanstrator.connectfour.Connect4
-
- Direct Known Subclasses:
DefaultConnect4
,FreePositionedConnect4
public abstract class Connect4 extends java.lang.Object
Main class containing the logic for the Connect4 game.
-
-
Constructor Summary
Constructors Constructor Description Connect4(java.lang.String firstPlayerName, java.lang.String secondPlayerName)
Constructor for creating a Connect4 game with two players.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description java.lang.String
getCurrentField()
Returns the current field as string with column and row numbers.
Example:java.lang.String
getCurrentField(boolean fullDetails)
Returns the current field as string.java.lang.String
getCurrentPlayerName()
Returns the name of the current player.java.lang.String
getFirstPlayerName()
Returns the name of the first player.GameLog
getGameLog()
Returns theGameLog
for this game.int
getPlayedRounds()
Returns the amount of valid played rounds.java.lang.String
getSecondPlayerName()
Returns the name of the second player.boolean
isDraw()
Tells if the game has ended and if nobody won.boolean
isGameOver()
Tells if the game has ended.RoundResult
play(int x)
Used to play a round of aDefaultConnect4
game.RoundResult
play(int x, int y)
Used to play a round of aFreePositionedConnect4
game.java.lang.String
toString()
Returns the current field as string without column and row numbers.
-
-
-
Method Detail
-
getFirstPlayerName
public java.lang.String getFirstPlayerName()
Returns the name of the first player.- Returns:
- The name of the first player
-
getSecondPlayerName
public java.lang.String getSecondPlayerName()
Returns the name of the second player.- Returns:
- The name of the second player
-
getCurrentPlayerName
public java.lang.String getCurrentPlayerName()
Returns the name of the current player.- Returns:
- The name of the current player
-
getPlayedRounds
public int getPlayedRounds()
Returns the amount of valid played rounds.- Returns:
- The amount of valid played rounds
-
isDraw
public boolean isDraw()
Tells if the game has ended and if nobody won.- Returns:
true
if the game ended in a draw, elsefalse
-
isGameOver
public boolean isGameOver()
Tells if the game has ended. It doesn't matter if somebody has won or not.- Returns:
true
if the game ended, elsefalse
-
getGameLog
public GameLog getGameLog()
Returns theGameLog
for this game.- Returns:
- The GameLog for this game
-
play
public RoundResult play(int x)
Used to play a round of aDefaultConnect4
game.- Parameters:
x
- X coordinate which has to be between 1 and 7- Returns:
- A
RoundResult
containing a message and a boolean telling if the round was valid - Throws:
java.lang.UnsupportedOperationException
- if this is aFreePositionedConnect4
game.
-
play
public RoundResult play(int x, int y)
Used to play a round of aFreePositionedConnect4
game.- Parameters:
x
- X coordinate which has to be between 1 and 7y
- Y coordinate which has to be between 1 and 6- Returns:
- A
RoundResult
containing a message and a boolean telling if the round was valid - Throws:
java.lang.UnsupportedOperationException
- if this is aDefaultConnect4
game.
-
getCurrentField
public java.lang.String getCurrentField()
Returns the current field as string with column and row numbers.
Example:1234567 1[ ] 2[ ] 3[ y ] 4[ rry ] 5[yrrryyr] 6[rryyyry]
- Returns:
- The current field as string which can be used to illustrate the current state
-
getCurrentField
public java.lang.String getCurrentField(boolean fullDetails)
Returns the current field as string. The boolean determines if column and row numbers should be displayed or not.
Example (without column and row numbers):[ ] [ ] [ y ] [ rry ] [yrrryyr] [rryyyry]
- Parameters:
fullDetails
-true
if column and row numbers should be displayed, elsefalse
- Returns:
- The current field as string which can be used to illustrate the current state
- See Also:
getCurrentField()
-
toString
public java.lang.String toString()
Returns the current field as string without column and row numbers.- Overrides:
toString
in classjava.lang.Object
- Returns:
- the current field as string which can be used to illustrate the current state
- See Also:
getCurrentField(boolean)
-
-