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.ObjectMain 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.StringgetCurrentField()Returns the current field as string with column and row numbers.
Example:java.lang.StringgetCurrentField(boolean fullDetails)Returns the current field as string.java.lang.StringgetCurrentPlayerName()Returns the name of the current player.java.lang.StringgetFirstPlayerName()Returns the name of the first player.GameLoggetGameLog()Returns theGameLogfor this game.intgetPlayedRounds()Returns the amount of valid played rounds.java.lang.StringgetSecondPlayerName()Returns the name of the second player.booleanisDraw()Tells if the game has ended and if nobody won.booleanisGameOver()Tells if the game has ended.RoundResultplay(int x)Used to play a round of aDefaultConnect4game.RoundResultplay(int x, int y)Used to play a round of aFreePositionedConnect4game.java.lang.StringtoString()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:
trueif 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:
trueif the game ended, elsefalse
-
getGameLog
public GameLog getGameLog()
Returns theGameLogfor this game.- Returns:
- The GameLog for this game
-
play
public RoundResult play(int x)
Used to play a round of aDefaultConnect4game.- Parameters:
x- X coordinate which has to be between 1 and 7- Returns:
- A
RoundResultcontaining a message and a boolean telling if the round was valid - Throws:
java.lang.UnsupportedOperationException- if this is aFreePositionedConnect4game.
-
play
public RoundResult play(int x, int y)
Used to play a round of aFreePositionedConnect4game.- Parameters:
x- X coordinate which has to be between 1 and 7y- Y coordinate which has to be between 1 and 6- Returns:
- A
RoundResultcontaining a message and a boolean telling if the round was valid - Throws:
java.lang.UnsupportedOperationException- if this is aDefaultConnect4game.
-
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-trueif 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:
toStringin classjava.lang.Object- Returns:
- the current field as string which can be used to illustrate the current state
- See Also:
getCurrentField(boolean)
-
-