Starter project
Software to manage a tournament
For our next assignment you and a partner are going to build a GUI application with JavaFX and FXML. The application will manage a tournament in which a group of players play games against each other.
Here are some requirements for this application:
- The application will allow players to register for the tournament.
- The application will generate pairs of players to play games in the tournament.
- The tournament is a round-robin style tournament, which means that every player in the tournament will play every other player exactly once.
- As the players are registering, the application will construct a list of all possible matches to be played.
- Once a pair of players completes a game, the tournament director will enter the winner of that match. Those players then go back into the pool of players used to play matches.
- The application will also display a leader board that ranks players by the number of matches they have won.
Requirements for the user interface
For this assignment you will use FXML to construct a user interface that consists of a single window. The window will use a tabbed interface with the following three tabs:
- A register tab where players can register to enter the tournament.
- A matches tab that displays the current active matches and allows the user to select a match and enter the winner of that match.
- A leaderboard tab to display the leaderboard.
At the top of this page there is a button that you can click to download a simple FXML example project that implements a tabbed interface for the "Hello FXML" example I showed earlier. You can use this project as the starting point for your work.
Suggestions for classes
To manage the data for this application I suggest you create at least two classes, a Player class and a Match class.
The Player class should store the player's name, whether or not they are currently assigned to an active match, a count of how many games they have played, and a count of how many games they have won.
The Match class should store the two players who participated in that match. In addition, each match should have a status. Here are the various status values that a match can have and their meanings:
- CREATED - this simply means that the match has been set up, but we have not yet confirmed that the two players involved in the match are available to play it.
- ACTIVE - this means that the two players in the match have been confirmed available to play the match.
- COMPLETED - this means that the match has ended and a winner has been recorded for the match.
In addition to these two classes, you should also set up a list of players and a list of matches. Here are some things you will need to do with the list of matches.
- When players register, create matches for them by setting up a match between that player and every other currently registered player. All of these matches get a status of CREATED and then go into the list of matches.
- You should provide a button on the matches tab to generate matches. When the user clicks this button, your program should search the list of matches to find matches in the CREATED state where both of the participants are not currently assigned to a match. For each such match that you find, change the status of that match from CREATED to ACTIVE and mark both participants in the match as assigned.
- To display the list of active matches in the matches tab you should filter the list of all matches down to only the matches that are currently in the ACTIVE state.
- When the user selects an ACTIVE match and enters a winner for that match you should change the status of that match to COMPLETED and mark both of the players as now being available again to play other matches.
- Each time you record the winner for a match you should resort the list of players into order of descending number of games won. That way the list you display on the leaderboard tab will always be up to date with the latest win/loss information.