Package org.swtpra1

Class GameView


  • public class GameView
    extends java.lang.Object
    Displays the state of the game graphically.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void changeVisualizedTurn​(int turnIndex)
      Renders the board after a turn based on the index of that turn in the list of all turns.
      int getCurrentGameId()
      Returns the id of the game currently shown.
      Game getGameObject()
      Gets the Game object with the right id from the Game array in the observer.
      javax.swing.JPanel getPanel()
      Gets the panel that displays this view.
      void initialize()
      Initializes the mainPanel and adds all of the required elements to it.
      void setCurrentGameId​(int gameId)
      Sets the id of the game to be displayed, loads the game object and sets all the ui elements to display its info.
      void setPlayerNames​(java.lang.String p1, java.lang.String p2)
      Displays the names of the players and their colors.
      void setWinnerName​(java.lang.String winnerName)
      Display the name of the winner.
      void showInitialBoard()
      Renders the board before any turns have been made.
      void showLatestTurn()
      Renders the latest available turn.
      void showNextTurn()
      Renders the move turn after the current turn if possible.
      void showPreviousTurn()
      Renders the move before the current turn if possible.
      void visualizeBoard​(int[][] boardArray)
      Given a board, display the pieces graphically.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Method Detail

      • initialize

        public void initialize()
        Initializes the mainPanel and adds all of the required elements to it.
      • getPanel

        public javax.swing.JPanel getPanel()
        Gets the panel that displays this view.
        Returns:
        JPanel object
      • changeVisualizedTurn

        public void changeVisualizedTurn​(int turnIndex)
        Renders the board after a turn based on the index of that turn in the list of all turns.
        Parameters:
        turnIndex - the index of the turn of which we want to see the resulting board
      • showNextTurn

        public void showNextTurn()
        Renders the move turn after the current turn if possible.
      • showPreviousTurn

        public void showPreviousTurn()
        Renders the move before the current turn if possible.
      • showLatestTurn

        public void showLatestTurn()
        Renders the latest available turn.
      • showInitialBoard

        public void showInitialBoard()
        Renders the board before any turns have been made.
      • setPlayerNames

        public void setPlayerNames​(java.lang.String p1,
                                   java.lang.String p2)
        Displays the names of the players and their colors.
        Parameters:
        p1 - name of WHITE player
        p2 - name of BLACK player
      • setWinnerName

        public void setWinnerName​(java.lang.String winnerName)
        Display the name of the winner.
        Parameters:
        winnerName - name of the winner
      • getCurrentGameId

        public int getCurrentGameId()
        Returns the id of the game currently shown.
        Returns:
        positive integer game id
      • setCurrentGameId

        public void setCurrentGameId​(int gameId)
        Sets the id of the game to be displayed, loads the game object and sets all the ui elements to display its info.
        Parameters:
        gameId - the id of the game we want to see
      • getGameObject

        public Game getGameObject()
        Gets the Game object with the right id from the Game array in the observer.
        Returns:
        Game object if exists; null otherwise
      • visualizeBoard

        public void visualizeBoard​(int[][] boardArray)
        Given a board, display the pieces graphically. Expects a 10x10 array of integers, will fail/not display correctly otherwise
        Parameters:
        boardArray - the array to be displayed