Nifty Assignment: Space Invaders with a database-backed leaderboard

James Vanderhyde
Saint Xavier University
Presented at CCSC: Midwest, 29 September 2018

This assignment is for a course on relational databases, for students with some programming background. It requires both SQL and Java skills. The instructor provides the students with source code for a score-based video game. The students construct the SQL queries necessary to insert scores into a database and retrieve lists of high scores. The students then embed the queries into the provided game source code. I used this assignment at the end of a junior-level databases course. It took about 2 weeks, concurrent with other activities.

The game

I have developed my own twist on the classic video game Space Invaders. It’s like the original, but the player chooses a hero to fight the invaders. Each hero has different gameplay. The heroes are the classic video game archetypes: strong fighter, rogue archer, and intelligent wizard. The Java source code is available here:
github.com/jvanderhyde/space-invaders/.

Space invaders game screenshot

The assignment

The assignment is split into three tasks. For Task 1, the student works on figuring out the SQL queries necessary to build a high score table and a leaderboard (a list of high-scoring players) for each hero. In Task 2, the student creates the database and uses Java and SQL to implement the insertion of scores. Finally, in Task 3, the student combines the queries from Task 1 into the Java code from Task 2. The program displays the high scores and the leaderboards so the players can see how they stack up to the competition.

Game over!
Score: 90
crono achieved a score of 90 while playing Ellis
Score inserted into database.
Your high score is 1950
---------------------------------
       Top 10 High Scores
---------------------------------
     1950 crono            Currer
     1860 marle            Currer
      820 marle            Ellis 
      690 crono            Acton 
      460 crono            Ellis 
      410 crono            Acton 
      400 lucca            Currer
      400 crono            Acton 
      150 crono            Acton 
      130 crono            Currer
---------------------------------

The queries in Task 1 offer a range of challenge, so students at different levels can participate as they are able. For Task 3 I provide solutions to Task 1 so that everyone can gain experience embedding SQL into Java.
Task 1 Word document