Class Connect4

    • Constructor Summary

      Constructors 
      Constructor Description
      Connect4​(java.lang.String firstPlayerName, java.lang.String secondPlayerName)
      Constructor for creating a Connect4 game with two players.
    • Constructor Detail

      • Connect4

        public Connect4​(java.lang.String firstPlayerName,
                        java.lang.String secondPlayerName)
        Constructor for creating a Connect4 game with two players.
        Parameters:
        firstPlayerName - Name of the first player
        secondPlayerName - Name of the second player
    • 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, else false
      • 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, else false
      • getGameLog

        public GameLog getGameLog()
        Returns the GameLog for this game.
        Returns:
        The GameLog for this game
      • play

        public RoundResult play​(int x)
        Used to play a round of a DefaultConnect4 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 a FreePositionedConnect4 game.
      • play

        public RoundResult play​(int x,
                                int y)
        Used to play a round of a FreePositionedConnect4 game.
        Parameters:
        x - X coordinate which has to be between 1 and 7
        y - 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 a DefaultConnect4 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, else false
        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 class java.lang.Object
        Returns:
        the current field as string which can be used to illustrate the current state
        See Also:
        getCurrentField(boolean)