TypeRacer, but for the terminal. The words per minute we type on online typing sites often don't reflect how fast we can copy code from StackOverflow without using Ctrl+C. This is because of the special symbols we encounter in code that don't occur in normal text. To solve this, we built TerminalTyper, a terminal-based typing speed test for code.
What it does
TerminalTyper is a CLI. When a player starts a test, it records how long they took to finish the test, along with their accuracy. It then calculates a score and submits it to the server with the player's name. Players can check the leaderboard for the top scores, as well as see all of their own scores.
How we built it
TerminalTyper is a non-live game based on the terminal. We built the client in Java, without the use of an external library to maintain simplicity and make TerminalTyper lightweight and dependency-free. It acts as a CLI, so we wouldn't have to rely on a TUI library. For the typing tests, we have a collection of
.txt files in various programming languages. The score is computed based on the accuracy of characters typed with the characters per minute speed.
The client interacts with the server written in Node.js using the Express.js framework. We have a hacky database in the form of a JSON object. There are three API routes:
POST /api/newscore, and
GET /api/scores. This allows users to know the top 10 scores, submit scores after their typing test, and see the scores they're submitted.
Challenges and Accomplishments
The HTTP requests we made from the client in Java were extremely verbose. In cases where we received JSON from the server, we parsed it manually rather than relying on an extra dependency.
In one case, we were receiving a
NoSuchElementException after a typing race run. This was because we were creating a scanner in each of two Java files. When one scanner closed, it also closed the other one in use. This required some debugging to find.
What we learned
Terminal Racer was a project that allowed some first-time teammates to learn new skills. Our project required us to interact with servers that some of us had never worked with before. Throughout the process, some of the team had to learn about client and server interaction and how we would be able to implement this in Java. It was essential to learn how to send and receive HTTP requests in Java.
What's next for TerminalTyper
Building a terminal user interface while maintaining TerminalTyper's lightweight and dependency-free nature.