Multiple Player Trivia Competition

Senior Capstone Project
By: Mac Barrett

Final Blog Post: Monday 05/03

Capstone presentations were last week, and I am proud of the work I've put in this semester. Before presentations I was able to get all major features up and running and fixed most of the bugs that were posing major problems in my application. The server is still sitting on compsci04 and could be run at any time, but I've also included a link to download the full version below. All that being said, I am looking forward to completing my degree in the fall, finishing out my College Football career, and then moving on to the workforce and bigger and better things!

Final Build: DOWNLOAD

Presentation Slides: DOWNLOAD

Saturday 04/24

This week's progress includes some major steps forward towards the implementation of All-Time leaderboards and user stat tracking. I've implemented an extremely basic registration/login system that you may access from the main menu and I've created a "User" class on the Server side (one "User" object resides in each thread). When a user logs in their ServerThread gets the User associated with their username+password. Using this system, I will be able to compile game stats as they happen during the Gameplay Loop and I should later be able to write the changes to file after the game is done.

Also I've fixed a couple of major stability issues by Changing all of my ArrayLists that contained all of the individual ServerThreads to CopyOnWriteArrayLists, which is essentially a thread safe version of the same thing. The issue that would come up, which is now fixed, was a thread that was being blocked in order to wait for all of the other threads would crash when the size of the ArrayList would change due to people quitting. This in addition to some code re-writing has fixed the quit button so there shouldn't be any issues with crashes there.

One final bug that I need to fix which probably won't take to long is an issue where if there's only one player left and that player quits the game, that player's thread crashes. To fix this I probably only need one if() statement in the Category Selecting function but I'd rather implement more features first in case that ends up being more complex than I anticipate.

UPDATE: Sunday 04/25

This is essentially the last week I'll have to work on this project, and I still have a couple of large features I need to work out. While I've got the leaderboard form up and running dynamically, I'd like to make the presentation of that form a lot nicer with HTML ul & li elements. I also would like to get the question submitting feature up and running, though I doubt that will be too hard. And I also never got around to making my CSS on my website or on the app itself nicer, so I've got my work cut out for me until Friday.

Sunday 04/18

Progress for this week hasn't been super big, but I've worked out a couple of major problems with my game. Today was the first day I got my game to run online from another computer which is a large stepping stone for my project. Other than that, I've created a better system for adding players to the game, a better main menu, and implemented scaffolding for several other features.

Right now my biggest problem is that my quit button has stopped working due to the way I handle IOExceptions in the GET_INPUT function. At least thats how I think this feature broke, as before any exception raised would bring me to the area where the thread is removed from the game but now IOExceptions that are raised while blocking for input from the client don't do this. I'm not sure why killing the socket connection doesn't cause other exceptions or the thread to break enough to reach the finally statement, but the problem is that I need to handle the IOExeptions like I am now in GET_INPUT, and so I've currently no idea how to fix this.

Saturday 04/10

After a couple good days work, I've fixed several bugs with that crashed the app regarding the timer, I've implemented code that allocates more points to quicker answers in addition to letting the person who answered the fastest to select the category for the next round, and I've finished the logic for ending the game properly and ensuring that the game can't end on a tie. I've also gone through and de-spaghetti-fyed a lot of my Server side code to make it easier to read.

Here is the game in it's current state: DOWNLOAD

Wednesday 04/07

A major breakthrough for putting events on timers has happened. And in typical fashion it was simply because I missed a built in socket method that does exactly what I needed it to do. Unfortunatley, since things are never actually simple, I'm going to need to rewrite some of my error handling code so that the IO exception the method raises doesn't kill the thread when a user times out. (Alternatively I could leave it like this, but there are many cases where I'd like the timer to not kill the thread)

Tuesday 04/06

Recent improvements have mostly been in general presentation and stability fixes. I've implemented code that properly removes defunct Server Threads from the game--which was much easier than I thought it would be. I've also put in a check to not let players join an ongoing game. Currently this has a couple of visual bugs but techinically works as intended... The first player starts the game once they see fit right now, eventually, I think I'd like to make it so that all the players have to be in agreement to start the game, in tandem with a timer that automatically starts the game after a minute or so.

In addition to this, I've also worked out the basics of ending the game with a clear winner. The win condition is reaching a certain point threshold at the moment. Also have implemented a very rough "quit game" button up and running but some work still needs to be done on the general UI design of my game.

Saturday 03/27

The core gameplay loop is at this point fully functional and somewhat cleaner looking than before. Progress recently hasn't been anything special; however, I've quashed a couple of bugs and have started to conceptualize implementations of new features and yesterday I created a powerpoint for the walkthroughs going on next week.

That being said, my biggest priorities at this point ought to be making the UI of both my project and website a little prettier. I've sort of neglected this aspect for a while and I want to make it look nice before its too late.

Saturday 03/13

I've now finished a rough outline of my core gameplay loop in the WebSocket javascript implementation of my game. All of the basic features are in effect: question category selection, questions and answers, and a scoreboard at the end of each round are all displayed to the player via a clever trick with what the WebSocket recieves. Likewise, the server also does what is necessary for the app to function properly.

Wednesday 03/10

The first order of business now that I've got communication ironed out is figuring out how exactly to display the different forms when I need to. That being said I've got a couple ideas for that and so I've started to implement a very basic UI for scaffolding purposes. Right now, I feel like I've got a lot of good ideas on how to keep my project moving forward.

Tuesday 03/09

It has been a while since I've updated this blog, but that was mostly because of some major roadblocks in implementing client side interfaces with regard to WebSockets. I was having a ton of problems handling the WebSocket handshake protocol initially, and then after that I had issues decoding and encoding the messages I wanted to recieve from or pass to the client. All of this needed to be done on the Server's end, and there wasn't very much I could find that would help me. As of writing this, however, I've finally overcome all of these hurdles and have integreted all of the methods into my server code.

WebSocket Handshake Protocol:
Message Decoding (left) and Encoding (right) logic:

Monday 02/22

After doing some research over the past couple days in order to prepare the next phase of my project, I've learned that I'm almost definitely going to have to rewrite the client half of my program--and likely some Socket portions of my server code--in order to make it a full functioning web app. I'm glad I saw the writing on the wall and didn't try super hard to implement features perfectly this early on, but the demo I created over the past couple weeks will be a great resource to look back on and even pull some code from at times. From this point on, I need to write this project's client in JavaScript, which looks like it'll give me more trouble than Java and HTML on their own.

In other news, I've constructed a basic schedule for myself to follow until the end of the semester, and I think I'll be good to follow it. I was previously ahead of schedule in the last phase of my project, but I also need to redo a lot of it, so we'll see. I need to ask for some help on JavaScript stuff after class tomorrow.

UPDATE: WEDNESDAY 02/24

Here is the link to the demo I've written so far: DOWNLOAD

To run it, redirect in the terminal to the unzipped folder and then run the server class first in terminal (java server) and then run two clients in seperate terminals (java client). Currently, in order to answer the questions correctly, you must input the exact correct answer in the terminal with the keyboard and it crashes if you select a file without any real questions in it, but it's in a rough working state, and should give you an idea of what the final project might look like!

Saturday 02/20

I've made significant progress on my project over the past week. I've been able to send and properly interpret the answers from the client to the server and allocate points accordingly since around Monday. I initially had a ton of issues forcing the users to stay in the same phase of the game at the same time but I gave up on using wait() & notify() Java commands and have since worked this issue out by using boolean flags that each thread blocks on until every thread has set off the flag, a solution that was suggested during my presentation on Thursday.

New features I've developed include a very basic implementation of a scoreboard and a similarly basic output for the results of the client's answer. Also, I have loaded the questions into a six seperate queues--seperated by category--which are stored in an ArrayList object. The data stored in each queue is just the entire string unparsed read straight from the .txt files. Having the queues seperated by category allows me to easily push the questions to the other threads and remove the questions from the pool of available, unasked, questions. The bonus of having them stored in the array list is that it simplifies the process of selecting the question category.

At this stage, I'm almost ready to rewrite the client side of my app to work as a web app instead of being on console using JavaScript and Bootstrap. Many of the features I've added so far are pretty basic, however there are a couple of major systems still missing such as a time limit while the client answers the question and also affects the score, and using that score to determine who selects the next question.

Additionally, I've started keeping a changelog and have been keeping tabs on which versions of my project contain working features.

Sunday 02/14:

After banging my head against the wall all weekend, I've started to get the hang of things. My project now has a couple of the core gameplay loop functions roughly worked out and I've got a good handle on doing the rest from here. Additionally, I have slapped together a method of having multiple clients running at the same time, but have yet to create a good method to force them to be synchronized on the same phase of the game.

The next big hurdle besides synching the clients together will be forcing bootstrap onto my project. Thus far I've done everything in Java, but I'm eventually going to need to add a web app GUI. I'd really hate it if I had to throw all of this work away in a worst case scenario; however, it wouldn't be the worst as I have a good example to look back on how things need to work and more experience with Java, threads, and sockets, which were all giving me trouble over the weekend.

In other news, I've settled on Visual Studio Code as my development platform. The integrated terminal allows for quick and easy testing of the server and clients, plus version control is easy due to how you can open folders into the workspace. Also, I haven't tried to get my program to run on a website yet.

Friday 02/12:

After deliberation with Dr. McVey & Dr. Diederich about whether to build my project as an iOS app or a webapp, I've decided to go with a web app so I didn't have to learn Xcode. Instead, I'll be writing it in java and to this end have started learning javascript.

I spent some time creating a little client/server tutorial app that runs from my terminal and am now feeling confident about working out the overall gameplay loop from here. The two things I have hesitations about now are (a) getting this thing running on an actual website and (b) allowing for multiple clients, however I'm confident I can work things out, hopefully during the weekend.

Fixed the navbar glitch, now it moves my text though.

CLIENT CODE SERVER CODE

Saturday 02/06:

Planned out views for the main gameplay loop and main menu. I believe I'm going to have to create a database for all of the questions and answers, but I'm not entirely sure of that yet.

Still debating what platform to target for my project, but I've downloaded Xcode for iOS development, my other option would be a strict web app, but either way I need to figure out connectivity to a main server that handles pushing the questions to the players and receiving their answers.

I believe that this main server would have most of the logic behind it, as the app just needs to display the questions and answers to the player, and receive and send information to the main server pertaining to the questions and the users answers.

Also, minor problem, but I can't seem to fix a glitch with the dropdown in my navbar on my when scrolling down.