======================
W14 | jcneally 5pm | zhansaya19, jennyvien | Quiz on US States with GUI
W16 | ashedden 6pm | rowallen, ryankemper | Added hint button, difficulty settings, improved architecture
Zhansaya Abdikarimova Jenny Vien
Ryan Allen Ryan Kemper
-
This application is a geography quiz that tests the users' knowledge of the locations of states and capitals on the US map. As for the future, it can be advanced to choosing different countries and continents.
-
javadoc: http://www.cs.ucsb.edu/~rowallen/cs56/W16/StateQuiz/javadoc/
-
The main frame of the game is in the
GameFrame
class that holds two different main panels:FrontPanel
andGamePanel
. -
When the quiz starts, it askes if the user wants to be tested on state locations or their capital locations. The initial cover page is in the
FrontPanel
class where there are two buttons for the two options, as well as radio buttons to select the difficulty settings.
(Note: user interface screenshots may not reflect the most recent design iteration)
- After selecting option of the quiz,
GamePanel
class runs the selected option. TheGamePanel
class has a MapPanel, a question scrollbar, an answer scroll bar, and 3 difficulty buttons. TheMapPanel
class holds the map of the United States with buttons for every state. If the user selects the state option it asks questions about each state location in random order, and if he or she selects the "states then capitals" option, the game will generate capital questions respectively. Here are the examples of states and capitals quizzes:
-
All of the data is stored in the
States.txt
file. It has a list of states, their capitals and locations for buttons:Alabama,Montgomery,495,310
-
The program stores data in the
Country
class. As you can see, in the constructor, every Country object has its name, capital and list of its states. It creates anArrayList
ofState
objects.
public Country(){
states = new ArrayList<State>();
this.name = null;
this.capital = null;
}
The State
class stores information about each state of a particular country
public State(String name, String capital, int x, int y){
this.name = name;
this.capital = capital;
this.xCoord = x;
this.yCoord = y;
}
Below there is a method in Country
class that reads all the information about the country from a file
public void addStates(int numberOfStates, File file) throws Exception {
Scanner scanner = new Scanner(file);
String line;
int x;
int y;
for(int i=0;i<numberOfStates;i++){
line = scanner.nextLine();
String[] splitted = line.split(",");
x=Integer.parseInt(splitted[2]);
y=Integer.parseInt(splitted[3]);
states.add(new State(splitted[0],splitted[1],x,y));
}
}
- Another very important file that actually runs the game is
QuestionManager
class. It has the basic logic for running the quiz. It stores the list of states and their capitals, generates random indexes for the questions, and asks questions until all of the states asked. QuestionManager also supports the aforementioned game modes (states, capitals, states then capitals).
The main method is in GameFrame
and in order to start the game, use ant run
.
-
While our project does not specifically employ the Model-Viewer-Controller (MVC) design pattern, the existing architecture distributes the tasks in a way that loosely aligns with the design. Storage of data is handled by the State and Country classes, corresponding to the "model" part of MVC. QuestionManager serves as the intermediary between the data in the "model" classes and the graphical display, so it functions as the controller. Finally, graphical elements are handled by GameFrame.java, GamePanel and FrontPanel, corresponding to the "viewer".
-
Future refactoring of the project could more formally implement the MVC framework. This would have the benefit of making it far easier to comprehend the overall structure of the project. Additionally, separating out the 3 different roles (M-V-C) will make it easy to make changes that only affect the relevant portion of the MVC pattern.
There are several ways of how the game can be developed further:
- game has quizzes for states and capitals mixed together
- there is an option for continent, countries quizes
- quizzes for states and capitals of other countries respectively
- go back button for both state and capital quiz
- expand behavior of hint button to offer deeper functionality
- play a sound based off whether a correct or incorrect answer is selected
- record and analyze statistics about player performance to generate a "report" at the end of the game
-
Take the time at the beginning of the project to go through each class and fully understand how they all connect to each other (perhaps by drawing out the connections). At this stage, using an IDE could be useful to jump around the different classes and find the implementation and usages of all the functions. This will be really helpful in adding new features and refactoring the code. At first glance, it may look intuitive, but once you try to add new code, you find that there are usually more levels of the program that interact with it.
-
This code would benefit from more extensive commenting. Some of the variable names are straightforward, but some of them seem similar.
This game has plenty of room for improvement!
- game has quizzes for states and capitals mixed together
- there is an option for continent, countries quizes
- quizzes for states and capitals of other countries respectively
- record and analyze statistics about player performance to generate a "report" at the end of the game
- expand the high score system- add nicknames, save scores from each mode, encrypt the file
- implement an online chat room system
- add an options menu (for muting the sound effects, etc.)
- Some helpful tips before starting this project is to play the game and figure out where the features are coded and how each class works together. QuestionManager is quite long and is probably hard to understand. It is where a lot of the action happens (recording answers, keeping score, etc), but once you understand it, it helps with the majority of the game. It could definitely use A LOT of refactoring to make it easier to understand. The game is pretty good so far, and we think there is more to add than there is to fix. Also, try to add some tests. There's literally zero tests.
- Refactor QuestionManager (pls, it's so bad :( )
- Alabama is left out of the game. No button and no question for it.
- Make the buttons un-clickable before the game starts.
- Improve the GUI. It looks very old school. ADD SOME PIZZAZZ!!
- Have the score be visible at all times. Currently, the score is not visible when you click on a wrong answer.
- The hint from a previous question does not disappear until a new hint is available. Make it disappear!
- Change the "Cancel" button to "Skip" in the States and Capitals mode (maybe deduct some points for that too)
- Add skip option to all game modes.
- To understand the gist of the project, you should look at QuestionManager first. Unfortunately, this class still needs refactoring to be more concise. It would be helpful to split up parts of QuestionManager into their own classes and/or move parts to GamePanel. Understanding how each class interacts with each other is tiresome, so creating a diagram could help show how everything works together. In addition to a better understanding, tests can be written so that future developers don't have to manually test not only their new feature, but also test that they didn't break anything along the way.
-Refactor QuestionManager (split parts into different classes and/or move things to a more appropriate class)
-Improve GUI to get rid of ugly buttons and change the background map to something more pretty
-Possibly add a zoom feature
-High score screen shows up in places it shouldn't. Includes: when `Cancel` is pressed when entering a username. Pressing `Main Menu`.
-Add more countries
-Record the high scores. Right now, nothing is getting saved/printed
-Create test classes. Both unit and integration tests