Compare commits

..

No commits in common. "d8e46cc5857f131cb40f3cc72b88be8b1df0ca26" and "758a607f339b285d8be0df5670188d5f9a64dcc0" have entirely different histories.

15 changed files with 98 additions and 360 deletions

View File

@ -1,11 +0,0 @@
# 1.0.1 - 1/16/2022
![image](https://user-images.githubusercontent.com/94150901/149679448-59391325-a938-4613-81b4-42423d17306f.png)
* Added a dark mode. Theme can be toggled by clicking on the WPM text. (This is temporary until the settings menu is implemented)
* Added key stats. User inputs are logged by test. Currently logging time taken to press the key as well as accuracy.
* Added UI for user stats. Stats can be seen by hovering over a key.
* [Key Stats and Theme Demo](https://www.youtube.com/watch?v=3ciaPUMzseg)
# 1.0.0 - 1/4/22 - Inital Release
![image](https://user-images.githubusercontent.com/94150901/149679413-ce6b3de1-8590-4a50-bb1e-d9335ca990b3.png)
* The first version of Typing Teaher. Implemented fundamental features like the typing prompt and on-screen keyboard for later features to build on.
* [Version Demo Video](http://www.youtube.com/watch?v=qMUSCpTL98k)![149679413-ce6b3de1-8590-4a50-bb1e-d9335ca990b3](https://user-images.githubusercontent.com/94150901/149819070-0f13e716-725d-4eb3-9457-fc6707fc8f74.png)

View File

@ -1,11 +1,13 @@
# Typing Teacher (Depreciated, see Typing-Test-C)
# Typing Teacher
A program built to improve user typing speed and accuracy. While still in the early stages, the goal of this project is to analyze the users typing patterns to give them words with letters they struggle with the most (keys they take the longest to find or mistype most frequently).
Typing Teacher provides an array of tests to target what the user is trying to improve on, from short burst typing to endurance modes. In addition, Typing Teacher will provide users with insights on what they need to work on and highlight their improvements to motivate them to continue practicing.
# Typing Teacher Demo Video
[MP4 Link](https://user-images.githubusercontent.com/94150901/149820428-e1360f02-582d-47ca-a90f-3eaabd2d2a4a.mp4)
https://user-images.githubusercontent.com/94150901/148817246-e267be1f-5ee0-4bdd-92ae-35ee99a3d59a.mp4
[Higher Quality Video Here](http://www.youtube.com/watch?v=qMUSCpTL98k)
# Using Typing Teacher
![image](https://user-images.githubusercontent.com/94150901/149679448-59391325-a938-4613-81b4-42423d17306f.png)
![image](https://user-images.githubusercontent.com/94150901/148121685-3650fbb0-b662-4101-a5b5-d905e5f9b230.png)
Using Typing Teacher is easy. Simply launch the application and begin typing. To change the test length, click on the “x Words” text on the top right. To start a new test, press the tab key on your keyboard.
*Not implemented yet:* To view your key stats, hover over the desired key with your mouse.
# The UI
@ -18,7 +20,7 @@ Following suite with the goal of simplicity, I made sure to make my code as neat
The first development milestone for this project is to have a working typing prompt. The program will generate a prompt from a list of words. After the user completes a test, the program will provide basic information such as WPM and accuracy after completing the test.
This milestone will have most of the UI elements implemented, with later milestones focusing on features like refinements and user data parsing.
****Milestone 2**** - Partially released - See changelog
****Milestone 2**** - In development
The second development milestone is to analyze user test data more thoroughly. Mis-keys and time between inputs will be recorded. This data will also be saved locally to the users computer to persist across sessions. An information tab will be added to show the users progress.
Additionally, the ability to hover over an on-screen key to get information about it will be implemented.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -6,15 +6,14 @@ import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.awt.event.MouseMotionListener;
import java.awt.event.WindowEvent;
import java.awt.event.WindowListener;
import java.util.ArrayList;
public class gameWindow implements KeyListener, WindowListener, MouseListener, MouseMotionListener {
public class gameWindow implements KeyListener, WindowListener, MouseListener {
private JFrame mainFrame;
private keyboard k = new keyboard();
private variables v = new variables();
private keyboard k = new keyboard(v);
private language l = new language();
mySurface s;
@ -28,7 +27,6 @@ public class gameWindow implements KeyListener, WindowListener, MouseListener, M
mainFrame.addKeyListener(this);
mainFrame.addWindowListener(this);
mainFrame.getContentPane().addMouseListener(this);
mainFrame.getContentPane().addMouseMotionListener(this);
mainFrame.setFocusTraversalKeysEnabled(false);
s = new mySurface();
mainFrame.add(s);
@ -96,15 +94,9 @@ public class gameWindow implements KeyListener, WindowListener, MouseListener, M
generateTestStrings(g, wordsFont, (int) (getWidth() * 0.8));
Rectangle lines[] = new Rectangle[v.drawLines];
v.WPMText = l.wpm + ": " + v.getWPM();
v.ScoreText = l.score + ": " + 0;
g.setColor(v.backgroundColor);
g.fillRect(0,0, getWidth(), getHeight());
g.setColor(v.UIColor);
// Draw debug rectangles
if(v.debug) {
g.drawRect((int) v.rWPM.getX(), (int) v.rWPM.getY(),
@ -115,13 +107,11 @@ public class gameWindow implements KeyListener, WindowListener, MouseListener, M
(int) v.rOptions.getWidth(), (int) v.rOptions.getHeight());
}
g.drawRoundRect(v.rTopBar.x, v.rTopBar.y, v.rTopBar.width,
v.rTopBar.height, 20, 20);
g.drawRoundRect((int) (getWidth() * 0.05),
g.drawRect((int) v.rTopBar.getX(), (int) v.rTopBar.getY(),
(int) v.rTopBar.getWidth(), (int) v.rTopBar.getHeight());
g.drawRect((int) (getWidth() * 0.05),
(int) (getHeight() * 0.025), (int) (getWidth() * 0.90),
UIHeightArea, 20, 20);
g.setColor(v.textColor);
UIHeightArea);
drawCenteredString(g, v.WPMText, v.rWPM, wordsFont);
drawCenteredString(g, v.ScoreText, v.rScore, wordsFont);
drawCenteredString(g, v.testWords + l.words, v.rOptions, wordsFont);
@ -152,43 +142,32 @@ public class gameWindow implements KeyListener, WindowListener, MouseListener, M
}
if(v.testOver) {
v.calculateEndGameStats();
String[] endStats = {l.testOver, l.wpm + ": " + v.getRealWPM(),
l.wpm + l.raw + ": " + v.getWPM(), l.accuracy + ": "
+ v.getAccuracy()
+ "%", l.time + ": " + v.generateElapsedTimeString()};
drawStatsWindow(g, endStats, wordsFont);
Rectangle rStatsWindow = new Rectangle((int) (getWidth() * 0.25),
UIHeight + UITopBarHeightArea * 2,
(int) (getWidth() * 0.5), (int) (UIHeightArea * 0.5));
Rectangle[] textLines = new Rectangle[4];
g.setColor(v.backgroundColor);
g.fillRect((int) rStatsWindow.getX(), (int) rStatsWindow.getY(),
(int) rStatsWindow.getWidth(), (int) rStatsWindow.getHeight());
g.setColor(v.textColor);
int counter = (int) (rStatsWindow.getY() / (textLines.length - 1));
for(int i = 0; i < textLines.length; i++) {
textLines[i] = new Rectangle((int) rStatsWindow.getX(),
(int) rStatsWindow.getY() + counter * i,
(int) rStatsWindow.getWidth(), counter);
}
drawCenteredString(g, l.testOver, textLines[0], wordsFont);
drawCenteredString(g, v.WPMText + l.raw, textLines[1], wordsFont);
drawCenteredString(g, l.accuracy + ": " + v.calculateAccuracy()
+ "%", textLines[2], wordsFont);
drawCenteredString(g, l.time + ": "
+ v.generateElapsedTimeString(), textLines[3], wordsFont);
}
}
private void drawStatsWindow(Graphics g, String[] s, Font f) {
double topBarHeight = 0.075;
int UIHeight = (int) (getHeight() * 0.025);
int UITopBarHeightArea = (int) (getHeight() * topBarHeight);
int UIHeightArea = (int) (getHeight() * 0.9 * 0.5);
Rectangle rStatsWindow = new Rectangle((int) (getWidth() * 0.25),
UIHeight + UITopBarHeightArea * 2,
(int) (getWidth() * 0.5), (int) (UIHeightArea * 0.5));
Rectangle[] textLines = new Rectangle[s.length];
g.setColor(v.backgroundColor);
g.fillRoundRect(rStatsWindow.x, rStatsWindow.y, rStatsWindow.width,
rStatsWindow.height, 25, 25);
g.setColor(v.textColor);
int counter = (int) (rStatsWindow.getY() / (textLines.length - 1));
for(int i = 0; i < textLines.length; i++) {
textLines[i] = new Rectangle((int) rStatsWindow.getX(),
(int) rStatsWindow.getY() + counter * i,
(int) rStatsWindow.getWidth(), counter);
drawCenteredString(g, s[i], textLines[i], f);
}
g.setColor(v.UIColor);
g.drawRoundRect(rStatsWindow.x, rStatsWindow.y, rStatsWindow.width,
rStatsWindow.height, 25, 25);
g.drawRoundRect(textLines[0].x, textLines[0].y, textLines[0].width, textLines[0].height, 20, 20);
}
/**
* Takes the user's input and converts it into strings the length of
* the test lines.
@ -198,6 +177,7 @@ public class gameWindow implements KeyListener, WindowListener, MouseListener, M
* Output: [window enter noon staa, bnelieve expect was, charity t tube]
*/
private void generateUserInputStrings() {
//v.userString = v.getString();
v.userInputStrings.clear();
int position = 0;
v.typedLines = 0;
@ -259,8 +239,8 @@ public class gameWindow implements KeyListener, WindowListener, MouseListener, M
int keySizeY = getHeight()/12;
Font keyboardFont = new Font("Dialog", Font.PLAIN, 24);
Graphics gr = (Graphics2D) g;
gr.setColor(v.keyColor);
Key keyboard[][] = k.kb;
gr.setColor(new Color(0,128,128));
key keyboard[][] = k.kb;
for(int y = 0; y < keyboard.length; y++) {
for(int x = 0; x < keyboard[y].length; x++) {
@ -268,36 +248,22 @@ public class gameWindow implements KeyListener, WindowListener, MouseListener, M
int leftPadding = (getWidth() - xLength)/2;
int yLength = keySizeY * keyboard.length;
int yPadding = (getHeight() - yLength);
Key key = keyboard[y][x];
Rectangle keyRect = new Rectangle(leftPadding + x*keySizeX, yPadding + (y-1)
*keySizeY, keySizeX, keySizeY);
boolean specialChar = keyboard[y][x].specialChar;
// Font size will be calculated by window size later.
if(!specialChar)
if(keyboard[y][x].specialChar)
keyboardFont = new Font("Dialog", Font.PLAIN, 24);
else
keyboardFont = new Font("Dialog", Font.PLAIN, 9);
gr.setColor(v.translucentKeyColor);
gr.drawRoundRect(keyRect.x, keyRect.y, keyRect.width, keyRect.height, 25, 25);
if (v.pressedKeys.contains(key.key)){
gr.fillRoundRect(leftPadding + x*keySizeX, yPadding + (y-1)
*keySizeY, keySizeX, keySizeY, 25, 25);
}
// Checks if game is running
if (!v.timerRunning) {
if(v.isInRect(keyRect, v.mouseLocation) && !specialChar) {
String[] keyStats = key.getStats(l);
drawStatsWindow(g, keyStats, keyboardFont);
gr.setColor(v.translucentKeyColor);
gr.fillRoundRect(leftPadding + x*keySizeX, yPadding + (y-1)
*keySizeY, keySizeX, keySizeY, 25, 25);
}
gr.drawRect(leftPadding + x*keySizeX, yPadding + (y-1)
*keySizeY, keySizeX, keySizeY);
drawCenteredString(gr, keyboard[y][x].key, leftPadding +
x*keySizeX, yPadding + (y-1)
* keySizeY, keySizeX, keySizeY, keyboardFont);
if (v.pressedKeys.contains(keyboard[y][x].key)){
gr.fillRect(leftPadding + x*keySizeX, yPadding + (y-1)
*keySizeY, keySizeX, keySizeY);
}
gr.setColor(v.keyColor);
drawCenteredString(gr, key.key, keyRect, keyboardFont);
}
}
}
@ -343,7 +309,7 @@ public class gameWindow implements KeyListener, WindowListener, MouseListener, M
* Sets the color of each letter according to its status
*/
public void drawTypingPrompt(Graphics g, String testText,
String userText, Rectangle rect, Font font) {
String userText, Rectangle rect, Font font) {
FontMetrics metrics = g.getFontMetrics(font);
int x = rect.x;
int y = rect.y + ((rect.height - metrics.getHeight()) / 2)
@ -351,6 +317,8 @@ public class gameWindow implements KeyListener, WindowListener, MouseListener, M
g.setFont(font);
g.drawString(testText, x, y);
g.setColor(new Color(128,128,128));
char c = ' ';
for (int i = 0; i < testText.length(); i++) {
if(userText.length() <= i) // User hasn't typed
@ -366,6 +334,10 @@ public class gameWindow implements KeyListener, WindowListener, MouseListener, M
}
}
public void drawCenteredRect(Graphics g, Rectangle rect) {
g.drawRect(rect.x, rect.y, rect.width, rect.y);
}
public void paintComponent(Graphics g) {
super.paintComponent(g);
draw(g);
@ -398,7 +370,6 @@ public class gameWindow implements KeyListener, WindowListener, MouseListener, M
else if (e.getKeyChar() != '\uFFFF' && v.gameRunning){
v.userString += e.getKeyChar();
v.timingHandler();
checkKey(e.getKeyChar());
}
String pressedKey = "" + e.getKeyChar();
if(!v.pressedKeys.contains(pressedKey)) {
@ -411,43 +382,6 @@ public class gameWindow implements KeyListener, WindowListener, MouseListener, M
refreshGraphics();
}
/**
* Checks if the pressed key is the correct key for test stats.
*/
public void checkKey(char input) {
int x = 0, y = 0;
char correctKey = v.getString().charAt(0);
if(v.userString.length() > 0 && v.userString.length()
<= v.getString().length())
correctKey = v.getString().charAt(v.userString.length() - 1);
// Finds the location of the correct key in the KB array
for(int i = 0; i < k.kb.length; i++) {
for(int k = 0; k < this.k.kb[i].length; k++) {
if(!this.k.kb[i][k].specialChar && this.k.kb[i][k].key.charAt(0) == correctKey) {
x = k; y = i;
}
}
}
// Checks if user pressed the correct key
if(v.userString.length() <= v.getString().length()) {
boolean isCorrect = correctKey == input;
if(isCorrect) {
if(v.keyLastPressed == -1) { // If its the first key of the test
k.kb[y][x].update(isCorrect);
}
else {
Long elapsedTime = (System.nanoTime() - v.keyLastPressed)/10000;
k.kb[y][x].update(isCorrect, elapsedTime);
}
v.keyLastPressed = System.nanoTime();
}
else { // updates key as being incorrectly pressed
k.kb[y][x].update(isCorrect);
}
}
}
/**
* Handles key released for keyboard graphics
*/
@ -528,10 +462,6 @@ public class gameWindow implements KeyListener, WindowListener, MouseListener, M
}
v.resetVars();
}
else if (v.isInRect(v.rWPM, e.getPoint())) {
v.darkMode = !v.darkMode;
v.generateThemes();
}
}
@Override
@ -545,16 +475,4 @@ public class gameWindow implements KeyListener, WindowListener, MouseListener, M
// TODO Auto-generated method stub
}
@Override
public void mouseDragged(MouseEvent e) {
// TODO Auto-generated method stub
}
@Override
public void mouseMoved(MouseEvent e) {
v.mouseLocation = e.getPoint();
}
}

View File

@ -1,4 +1,3 @@
import java.util.ArrayList;
public class keyboard {
@ -6,160 +5,36 @@ public class keyboard {
{"tab", "q", "w", "e", "r", "t", "y", "u", "i", "o", "p", "[", "]", "\\"},
{"caps lock", "a", "s", "d", "f", "g", "h", "j", "k", "l", ";", "'", "enter"},
{"shift", "z", "x", "c", "v", "b", "n", "m", ",", ".", "/", "shift"}};
public Key[][] kb;
private variables v;
public key[][] kb;
public keyboard(variables v) {
this.v = v;
public keyboard() {
generateEngl();
}
/**
* Creates a Jagged Array of keys
* This later will read from a text file which the user can edit
*/
public void generateEngl() {
kb = new Key[engl.length][];
kb = new key[engl.length][];
for (int i = 0; i < engl.length; i++) {
kb[i] = new Key[engl[i].length];
kb[i] = new key[engl[i].length];
}
for (int y = 0; y < kb.length; y++) {
for (int x = 0; x < kb[y].length; x++) {
kb[y][x] = new Key(engl[y][x], v);
kb[y][x] = new key(engl[y][x]);
}
}
}
}
class Key {
class key {
public String key;
public int keyID, dataPoints;
public int keyID;
public boolean specialChar;
private variables v;
// Backspace needs to count as a miss or some way of preventing
// exploit
// Need to make arraylist of arraylists for the word modes
private ArrayList<ArrayList<Boolean>> correctStrikes = new ArrayList<>();
private ArrayList<ArrayList<Double>> timesToStrike = new ArrayList<>();
private ArrayList<Boolean> correctStrike = new ArrayList<>();
private ArrayList<Double> timeToStrike = new ArrayList<>();
int correctStrikeCounter, timeToStrikeCounter;
public Key(String text, variables v) {
public key(String text) {
key = text;
this.v = v;
specialChar = text.length() != 1;
dataPoints = 100;
// Correct strike will be changed based on gamemode
for(int i = 0; i < v.wordModes.length; i++) {
correctStrikes.add(new ArrayList<Boolean>());
timesToStrike.add(new ArrayList<Double>());
}
// Initalize arraylists here
specialChar = text.length() == 1;
}
/**
* @param correctStrike
* @param timeToStrike
*
* Adds data to ArrayList. Checks if ArrayList is at max
* capacity. If so, it rolls over back to zero.
*/
public void update(boolean correctStrike, double timeToStrike) {
this.correctStrike = correctStrikes.get(v.wordMode);
this.timeToStrike = timesToStrike.get(v.wordMode);
timeToStrike = timeToStrike / 100000; // 10^5 Converts to seconds
if(correctStrikeCounter == dataPoints)
correctStrikeCounter = 0;
if(timeToStrikeCounter == dataPoints)
timeToStrikeCounter = 0;
if(this.correctStrike.size() >= dataPoints)
this.correctStrike.set(correctStrikeCounter, correctStrike);
else
this.correctStrike.add(correctStrike);
if(this.timeToStrike.size() >= dataPoints)
this.timeToStrike.set(timeToStrikeCounter, timeToStrike);
else
this.timeToStrike.add(timeToStrike);
correctStrikeCounter++;
timeToStrikeCounter++;
correctStrikes.set(v.wordMode, this.correctStrike);
timesToStrike.set(v.wordMode, this.timeToStrike);
}
public void update(boolean correctStrike) {
this.correctStrike = correctStrikes.get(v.wordMode);
if(correctStrikeCounter == dataPoints)
correctStrikeCounter = 0;
if(this.correctStrike.size() >= dataPoints)
this.correctStrike.set(correctStrikeCounter, correctStrike);
else
this.correctStrike.add(correctStrike);
correctStrikeCounter++;
correctStrikes.set(v.wordMode, this.correctStrike);
}
public String[] getStats(language l) {
correctStrike = correctStrikes.get(v.wordMode);
timeToStrike = timesToStrike.get(v.wordMode);
double counter = 0, accuracy = 100, averageTime = 0;
for(boolean temp : correctStrike) {
counter += temp ? 1 : 0;
}
if(correctStrike.size() > 0) {
accuracy = counter / correctStrike.size() * 100;
accuracy = v.round(accuracy, 2);
}
counter = 0;
for(double temp: timeToStrike) {
counter += temp;
}
if(timeToStrike.size() > 0) {
averageTime = counter / timeToStrike.size() * 100;
averageTime = v.round(averageTime, 2);
}
String[] toReturn = {l.keyStats + " - " + v.wordModes[v.wordMode] + " Words - " + key, l.accuracy + ": " + accuracy + "%", l.averageTime + ": " + averageTime + "ms", l.sampleSize + ": " + correctStrike.size()};
return toReturn;
}
public ArrayList<Boolean> getCorrectStrike() {
return correctStrike;
}
public void setCorrectStrike(ArrayList<Boolean> correctStrike) {
if(correctStrike.size() == 100) {
correctStrikeCounter = 0;
}
else {
correctStrikeCounter = correctStrike.size();
}
this.correctStrike = correctStrike;
}
public ArrayList<Double> getTimeToStrike() {
return timeToStrike;
}
public void setTimeToStrike(ArrayList<Double> timeToStrike) {
if(timeToStrike.size() == 100) {
timeToStrikeCounter = 0;
}
else {
timeToStrikeCounter = timeToStrike.size();
}
this.timeToStrike = timeToStrike;
}
// Need getters and setters for the two arraylists
}

View File

@ -1,7 +1,6 @@
public class language {
public String score, words, testOver, wpm, raw, accuracy, time, keyStats,
averageTime, sampleSize;
public String score, words, testOver, wpm, raw, accuracy, time;
// This will later load from a text file so uses can change languages
public language() {
@ -21,8 +20,5 @@ public class language {
raw = " (raw)";
accuracy = "Accuracy";
time = "Time";
keyStats = "Key Stats";
averageTime = "Average Time";
sampleSize = "Sample Size";
}
}

View File

@ -2,6 +2,6 @@
public class runner {
public static void main(String[] args) {
// TODO Auto-generated method stub
gameWindow w = new gameWindow(800, 600, "Typing Teacher Alpha v1.0.1");
gameWindow w = new gameWindow(800, 600, "Typing Teacher Alpha v1.0");
}
}
}

16
src/utils.java Normal file
View File

@ -0,0 +1,16 @@
public class utils {
public static void main(String[] args) {
// TODO Auto-generated method stub
}
public void generateKB() {
String x = "ASDFGHJKL";
for(int i = 0; i < x.length(); i++) {
System.out.print("\"" + x.charAt(i) + "\", ");
}
}
}

View File

@ -6,20 +6,18 @@ import java.util.Scanner;
import java.awt.*;
public class variables {
public int fps = 10, lines = 3;
public int fps = 5, lines = 3;
public boolean debug = false;
// Updating variables
private double WPM, realWPM, score, accuracy;
private double WPM, score;
private String testString;
private String[] testWord;
private long startTime, endTime, elapsedTime;
public long keyLastPressed;
public int typedLines, testWords, drawLines, wordMode;
public int wordModes[] = {5, 10, 25, 50, 100};
public Point mouseLocation;
public String userString;
public String WPMText, ScoreText;
public boolean darkMode, gameRunning, testOver;
public boolean gameRunning, testOver;
public ArrayList<String> pressedKeys = new ArrayList();
public ArrayList<String> words = new ArrayList();
public ArrayList<String> drawStrings = new ArrayList();
@ -29,8 +27,7 @@ public class variables {
// Finish test when last word is spelled right
// calculate real WPM and actual WPM
boolean repeatWords, timerRunning;
Color typingPromptColors[], backgroundColor, textColor, UIColor, keyColor,
translucentKeyColor;
Color typingPromptColors[], backgroundColor, textColor;
Rectangle rOptions, rScore, rWPM, rTopBar;
Random r = new Random();
@ -40,20 +37,16 @@ public class variables {
resetVars();
generateNewTest();
generateThemes();
mouseLocation = new Point(0,0);
}
public void resetVars() {
userString = "";
testString = "";
typedLines = 0;
accuracy = 0;
generateNewTest();
timerRunning = false;
elapsedTime = -1;
keyLastPressed = -1;
WPM = 0;
realWPM = 0;
score = 0;
drawLines = lines;
gameRunning = true;
@ -65,7 +58,6 @@ public class variables {
wordMode = 1;
testWords = wordModes[wordMode];
repeatWords = false;
darkMode = true;
}
/**
@ -73,38 +65,15 @@ public class variables {
* 0 = not typed
* 1 = correctly typed
* 2 = incorrectly typed
* This will later load from a file the user can change.
* Values are set manually until feature added.
*/
public void generateThemes() {
typingPromptColors = new Color[3];
typingPromptColors[0] = new Color(128,128,128);
typingPromptColors[1] = new Color(0,0,0);
typingPromptColors[2] = new Color(255,128,128);
if(darkMode) {
typingPromptColors = new Color[3];
typingPromptColors[0] = new Color(150,150,150);
typingPromptColors[1] = new Color(255,255,255);
typingPromptColors[2] = new Color(255,128,128);
backgroundColor = new Color(48,44,44);
textColor = new Color(120,236,220);
UIColor = new Color(8,132,132);
keyColor = new Color(4,220,200);
translucentKeyColor = new Color(4,220,200,128);
}
else {
typingPromptColors = new Color[3];
typingPromptColors[0] = new Color(128,128,128);
typingPromptColors[1] = new Color(0,0,0);
typingPromptColors[2] = new Color(255,128,128);
backgroundColor = new Color(255,255,255);
textColor = new Color(0,0,0);
UIColor = new Color(8,132,132);
keyColor = new Color(0,128,128);
translucentKeyColor = new Color(0,128,128,128);
}
backgroundColor = new Color(255,255,255);
textColor = new Color(0,0,0);
}
public void loadWords() {
@ -132,10 +101,6 @@ public class variables {
for (String x : testWord)
testString += x + " ";
testString = backspace(testString);
if(debug) {
testString = "aaa";
testWord[0] = "aaa";
}
}
/**
@ -208,41 +173,25 @@ public class variables {
calculateGameStats();
}
/**
* Called at the end of a test
*/
public void calculateGameStats() {
if(timerRunning)
elapsedTime = (System.nanoTime() - startTime)/10000;
else
elapsedTime = (endTime - startTime)/10000;
if(elapsedTime != 0) {
WPM = (double) userString.length() / 5 / elapsedTime * (60 / 0.00001);
WPM = round(WPM, 2);
}
else
WPM = 0;
WPM = (double) userString.length() / 5 / elapsedTime * (60 / 0.00001);
WPM = round(WPM, 2);
}
public void calculateEndGameStats() {
public double calculateAccuracy() {
int counter = 0;
for(int i = 0; i < testString.length(); i++) {
if(testString.charAt(i) == userString.charAt(i))
counter++;
}
accuracy = (double)(counter)/testString.length();
accuracy = round(accuracy, 3) * 100;
realWPM = (double) counter / 5 / elapsedTime * (60 / 0.00001);
realWPM = round(realWPM, 2);
double toReturn = round((double)(counter)/testString.length(), 3);
return toReturn * 100;
}
/**
* Rounds to specified decimal place
* @param number number to round
* @param places decimal places
* @return
*/
public double round(double number, int places) {
long shift = (long) Math.pow(10, places);
double shifted = number * shift;
@ -273,13 +222,6 @@ public class variables {
public Long getElapsedTime() {
return elapsedTime;
}
public double getRealWPM() {
return realWPM;
}
public double getAccuracy() {
return accuracy;
}
/**
* Checks if a specified point is inside a rectangle