Reference no: EM13594
(1) Write a recursive instance method called countConnectedPipes(int row, int col). The method must not contain any loops and must be directly recursive (i.e., no indirect recursion). This method will be called from your user interface with the row and col being set to the row and column of the valve pipe placed on the grid. It should count and return the number of pipes that have been successfully connected to the valve pipe. Any pipes not connected to the main valve "chain" of pipes should not be counted. For example, the picture here shows 24 placed pipes and the picture on the right shows the 14 pipes (as enabled buttons) that are connected to the valve (including the valve) and the 10 pipes (disabled buttons) that are not connected. You will need to ensure that your pipes are initially unmarked. which you should do with a different method (in which may use a FOR loop to run through the array and reset things accordingly).
(2) Write a recursive instance method in the PipeGame class called countOpenEnds(row, col) which takes the valve location as a parameter (just like the countConnectedPipes method) and returns the integer count of open ends. As with your other method, this method must NOT use indirect recursion. The example above has 6 open ends.
(3) Adjust your PipeGameApp code so that the score is calculated as 10 times the number of connected pipes minus 5 times the number of open ends. You MUST calculate this value using your recursive methods. The example above would give a score of (14*10) - (6*5) = (140-30) = 110.
(4) Adjust your PipeGameApp code so that when the game is completed, you should also disable all buttons that do not have pipes connected to the valve (as shown in the picture here). Also, add a JLabel to your user interface (placed nicely of course) saying "Open Ends: xxx" which displays the number of open ends of pipes that are connected to the valve. The number of open ends should be displayed continuously while the game is running (i.e., after every pipe piece is placed), not just when the game has stopped.