diff --git a/bin/gameWindow$mySurface.class b/bin/gameWindow$mySurface.class new file mode 100644 index 0000000..9311a86 Binary files /dev/null and b/bin/gameWindow$mySurface.class differ diff --git a/bin/gameWindow.class b/bin/gameWindow.class new file mode 100644 index 0000000..1a37f36 Binary files /dev/null and b/bin/gameWindow.class differ diff --git a/bin/key.class b/bin/key.class new file mode 100644 index 0000000..a99addd Binary files /dev/null and b/bin/key.class differ diff --git a/bin/keyboard.class b/bin/keyboard.class new file mode 100644 index 0000000..d50bf1d Binary files /dev/null and b/bin/keyboard.class differ diff --git a/bin/language.class b/bin/language.class new file mode 100644 index 0000000..1e5dcea Binary files /dev/null and b/bin/language.class differ diff --git a/bin/runner.class b/bin/runner.class new file mode 100644 index 0000000..96c3762 Binary files /dev/null and b/bin/runner.class differ diff --git a/bin/utils.class b/bin/utils.class new file mode 100644 index 0000000..39bf892 Binary files /dev/null and b/bin/utils.class differ diff --git a/bin/variables.class b/bin/variables.class new file mode 100644 index 0000000..9596ade Binary files /dev/null and b/bin/variables.class differ diff --git a/src/gameWindow.java b/src/gameWindow.java new file mode 100644 index 0000000..c02bd4c --- /dev/null +++ b/src/gameWindow.java @@ -0,0 +1,478 @@ +import javax.swing.JFrame; +import javax.swing.JPanel; +import javax.swing.Timer; +import java.awt.*; +import java.awt.event.KeyEvent; +import java.awt.event.KeyListener; +import java.awt.event.MouseEvent; +import java.awt.event.MouseListener; +import java.awt.event.WindowEvent; +import java.awt.event.WindowListener; +import java.util.ArrayList; + +public class gameWindow implements KeyListener, WindowListener, MouseListener { + private JFrame mainFrame; + private keyboard k = new keyboard(); + private variables v = new variables(); + private language l = new language(); + mySurface s; + + /** + * Initializes window and starts the graphics runner. + * Graphics runner runs @v.fps times a second. + */ + public gameWindow (int x, int y, String name) { + mainFrame = new JFrame(name); + mainFrame.setSize(x, y); + mainFrame.addKeyListener(this); + mainFrame.addWindowListener(this); + mainFrame.getContentPane().addMouseListener(this); + mainFrame.setFocusTraversalKeysEnabled(false); + s = new mySurface(); + mainFrame.add(s); + mainFrame.setVisible(true); + graphicsRunner(); + } + + /** + * Redraws the window @v.fps times a second + */ + public void graphicsRunner() { + while(true) { + try { + Thread.sleep(1000/v.fps); + s.repaint(); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + } + + protected class mySurface extends JPanel { + double topBarHeight = 0.075; + double textHeight = 0.075; + int UIWidthArea = (int) (getWidth() * 0.8); + int UIHeight = (int) (getHeight() * 0.025); + int UITopBarHeightArea = (int) (getHeight() * topBarHeight); + int UIHeightArea = (int) (getHeight() * 0.9 * 0.5); + + /** + * Main drawing method + * Calls UI drawing methods + */ + private void draw(Graphics g) { + Graphics2D g2d = (Graphics2D) g; + g2d.setRenderingHint( + RenderingHints.KEY_TEXT_ANTIALIASING, + RenderingHints.VALUE_TEXT_ANTIALIAS_ON); + drawUI(g); + drawKeyboard(g); + } + + /** + * Draws the UI for typing teacher. + */ + private void drawUI(Graphics g) { + Font wordsFont = new Font("Arial", Font.PLAIN, 24); + double topBarHeight = 0.075; + double textHeight = 0.075; + int UIWidthArea = (int) (getWidth() * 0.8); + int UIHeight = (int) (getHeight() * 0.025); + int UITopBarHeightArea = (int) (getHeight() * topBarHeight); + int UIHeightArea = (int) (getHeight() * 0.9 * 0.5); + + v.rOptions = new Rectangle(UIWidthArea, UIHeight, (int) + (getWidth() * 0.15), UITopBarHeightArea); + v.rScore = new Rectangle((int) (getWidth() * 0.05), + UIHeight, (int) (getWidth() * 0.15), UITopBarHeightArea); + v.rWPM = new Rectangle((int) + ((UIWidthArea - getWidth() * 0.15)/2 + getWidth() * 0.1), + UIHeight, (int) (getWidth() * 0.15), UITopBarHeightArea); + v.rTopBar = new Rectangle((int) (getWidth() * 0.05), + UIHeight, (int) (getWidth() * 0.9), UITopBarHeightArea); + + generateTestStrings(g, wordsFont, (int) (getWidth() * 0.8)); + Rectangle lines[] = new Rectangle[v.drawLines]; + + v.WPMText = l.wpm + ": " + v.getWPM(); + v.ScoreText = l.score + ": " + 0; + + // Draw debug rectangles + if(v.debug) { + g.drawRect((int) v.rWPM.getX(), (int) v.rWPM.getY(), + (int) v.rWPM.getWidth(), (int) v.rWPM.getHeight()); + g.drawRect((int) v.rScore.getX(), (int) v.rScore.getY(), + (int) v.rScore.getWidth(), (int) v.rScore.getHeight()); + g.drawRect((int) v.rOptions.getX(), (int) v.rOptions.getY(), + (int) v.rOptions.getWidth(), (int) v.rOptions.getHeight()); + } + + 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); + drawCenteredString(g, v.WPMText, v.rWPM, wordsFont); + drawCenteredString(g, v.ScoreText, v.rScore, wordsFont); + drawCenteredString(g, v.testWords + l.words, v.rOptions, wordsFont); + + int textSizeY = (int) (textHeight * getHeight() * lines.length); + + double topOfBarPadding = getHeight() * 0.025; + double topBarPadding = getHeight() * 0.025 + getHeight() * topBarHeight; + + int yPadding = (int) ((getHeight() * 0.35) - textSizeY)/2; + + generateTestStrings(g, wordsFont, UIWidthArea); + generateUserInputStrings(); + + int k = 0; + int middle = v.drawLines/2; + while(v.typedLines - middle - k > 0 && v.drawStrings.size() > k + + v.drawLines) + k++; + + for(int i = 0; i < lines.length; i++) { + lines[i] = new Rectangle((int) (getWidth() * 0.1), + (int) (topOfBarPadding/2 + topBarPadding + yPadding + + textHeight * getHeight() * i), + (int) (getWidth() * 0.8), (int) (getHeight() * textHeight)); + drawTypingPrompt(g, v.drawStrings.get(i+k), + v.userInputStrings.get(i+k), lines[i], wordsFont); + } + + if(v.testOver) { + 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); + + } + } + + /** + * Takes the user's input and converts it into strings the length of + * the test lines. + * Example: + * v.drawStrings: [window enter noon star, believe expect wash, chair city tube] + * User input: "window enter noon staa bnelieve expect was charity t tube" + * 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; + for(int i = 0; i < v.drawStrings.size(); i++) { + if(v.userString.length() - position <= v.drawStrings.get(i).length()) {// If userString is not as long as line + v.userInputStrings.add(v.userString.substring(position, + v.userString.length())); + i = v.drawStrings.size(); + } + else { // If user completed string + v.userInputStrings.add(v.userString.substring(position, + position + v.drawStrings.get(i).length())); + position += v.drawStrings.get(i).length() + 1; // + 1 For space + v.typedLines++; + } + } + while(v.userInputStrings.size() < v.drawStrings.size()) { + v.userInputStrings.add(""); + } + } + + /** + * Calculates how many words can be displayed on a line and adds them + */ + private void generateTestStrings(Graphics g, Font font, int lineLength) { + String temp[] = v.getTestWords(); + String toAdd = ""; + FontMetrics metrics = g.getFontMetrics(font); + v.drawStrings.clear(); + int length = 0; + for(String x : temp) { + int textLength = metrics.stringWidth(" " + x); + if(length + textLength < lineLength) { + length += textLength; + toAdd += x + " "; + } + else { + toAdd = v.backspace(toAdd); + v.drawStrings.add(toAdd); + length = textLength; + toAdd = x + " "; + } + } + toAdd = v.backspace(toAdd); + v.drawStrings.add(toAdd); + + if (v.drawStrings.size() < v.lines) + v.drawLines = v.drawStrings.size(); + else + v.drawLines = v.lines; + } + + /** + * Draws the on-screen keyboard and displays which keys the user is + * pressing. + */ + private void drawKeyboard(Graphics g) { + int keySizeX = getWidth()/16; + int keySizeY = getHeight()/12; + Font keyboardFont = new Font("Dialog", Font.PLAIN, 24); + Graphics gr = (Graphics2D) g; + 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++) { + int xLength = keySizeX * keyboard[y].length; // Calculates how many pixels each row will take + int leftPadding = (getWidth() - xLength)/2; + int yLength = keySizeY * keyboard.length; + int yPadding = (getHeight() - yLength); + + // Font size will be calculated by window size later. + if(keyboard[y][x].specialChar) + keyboardFont = new Font("Dialog", Font.PLAIN, 24); + else + keyboardFont = new Font("Dialog", Font.PLAIN, 9); + + 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); + } + } + } + } + + /** + * Draws a centered string. + * Credit: https://stackoverflow.com/questions/27706197/how-can-i-center-graphics-drawstring-in-java + */ + public void drawCenteredString(Graphics gr, String text, int x, int y, + int xHeight, int yHeight, Font font) { + // Get the FontMetrics + FontMetrics metrics = gr.getFontMetrics(font); + // Determine the X coordinate for the text + int drawx = x + (xHeight - metrics.stringWidth(text)) / 2; + // Determine the Y coordinate for the text (note we add the ascent, + // as in java 2d 0 is top of the screen) + int drawy = y + ((yHeight - metrics.getHeight()) / 2) + metrics.getAscent(); + // Set the font + gr.setFont(font); + // Draw the String + gr.drawString(text, drawx, drawy); + } + + /** + * Draws a centered string. + */ + public void drawCenteredString(Graphics g, String text, + Rectangle rect, Font font) { + // Get the FontMetrics + FontMetrics metrics = g.getFontMetrics(font); + // Determine the X coordinate for the text + int x = rect.x + (rect.width - metrics.stringWidth(text)) / 2; + // Determine the Y coordinate for the text (note we add the ascent, as in java 2d 0 is top of the screen) + int y = rect.y + ((rect.height - metrics.getHeight()) / 2) + metrics.getAscent(); + // Set the font + g.setFont(font); + // Draw the String + g.drawString(text, x, y); + } + /** + * Draws the typing prompt text + * Aligns text left and in the middle (y) + * Sets the color of each letter according to its status + */ + public void drawTypingPrompt(Graphics g, String testText, + String userText, Rectangle rect, Font font) { + FontMetrics metrics = g.getFontMetrics(font); + int x = rect.x; + int y = rect.y + ((rect.height - metrics.getHeight()) / 2) + + metrics.getAscent(); + 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 + g.setColor(v.typingPromptColors[0]); + else if (userText.charAt(i) == testText.charAt(i)) + g.setColor(v.typingPromptColors[1]); + else + g.setColor(v.typingPromptColors[2]); + c = testText.charAt(i); + int width = g.getFontMetrics(font).charWidth(c); + g.drawString("" + c, x, y); + x += width; + } + } + + 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); + } + + } + + @Override + public void keyTyped(KeyEvent e) { + // TODO Auto-generated method stub + } + + /** + * Handles user key presses + */ + @Override + public void keyPressed(KeyEvent e) { + // TODO Auto-generated method stub + + if(e.getKeyCode() == KeyEvent.VK_BACK_SPACE) { + v.userString = v.backspace(v.userString); + } + else if (e.getKeyCode() == KeyEvent.VK_TAB) { + v.resetVars(); + } + else if (e.getKeyCode() == KeyEvent.VK_ESCAPE) { + mainFrame.dispose(); + System.exit(0); + } + else if (e.getKeyChar() != '\uFFFF' && v.gameRunning){ + v.userString += e.getKeyChar(); + v.timingHandler(); + } + String pressedKey = "" + e.getKeyChar(); + if(!v.pressedKeys.contains(pressedKey)) { + v.pressedKeys.add(pressedKey.toLowerCase()); + } + + v.checkTest(); + + // Refreshes keyboard graphics to reduce visual input delay + refreshGraphics(); + } + + /** + * Handles key released for keyboard graphics + */ + @Override + public void keyReleased(KeyEvent e) { + String depressedKey = "" + e.getKeyChar(); + v.pressedKeys.remove(depressedKey.toLowerCase()); + refreshGraphics(); + } + + private void refreshGraphics() { + s.repaint(); + } + + public void windowClosing(WindowEvent e) { + mainFrame.dispose(); + System.exit(0); + } + + @Override + public void windowOpened(WindowEvent e) { + // TODO Auto-generated method stub + + } + + @Override + public void windowClosed(WindowEvent e) { + // TODO Auto-generated method stub + + } + + @Override + public void windowIconified(WindowEvent e) { + // TODO Auto-generated method stub + + } + + @Override + public void windowDeiconified(WindowEvent e) { + // TODO Auto-generated method stub + + } + + @Override + public void windowActivated(WindowEvent e) { + // TODO Auto-generated method stub + + } + + @Override + public void windowDeactivated(WindowEvent e) { + // TODO Auto-generated method stub + + } + + @Override + public void mouseClicked(MouseEvent e) { + // TODO Auto-generated method stub + + } + + @Override + public void mousePressed(MouseEvent e) { + // TODO Auto-generated method stub + + } + + @Override + public void mouseReleased(MouseEvent e) { + if(v.isInRect(v.rOptions, e.getPoint())) { + if(v.wordMode + 1 >= v.wordModes.length) { + v.wordMode = 0; + v.testWords = v.wordModes[0]; + } + else { + v.wordMode++; + v.testWords = v.wordModes[v.wordMode]; + } + v.resetVars(); + } + } + + @Override + public void mouseEntered(MouseEvent e) { + // TODO Auto-generated method stub + + } + + @Override + public void mouseExited(MouseEvent e) { + // TODO Auto-generated method stub + + } +} diff --git a/src/keyboard.java b/src/keyboard.java new file mode 100644 index 0000000..f3b881b --- /dev/null +++ b/src/keyboard.java @@ -0,0 +1,40 @@ + +public class keyboard { + + public String engl[][] = {{"`", "1", "2", "3", "4", "5", "6", "7", "8", "9", "0", "-", "=", "backspace"}, + {"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; + + public keyboard() { + generateEngl(); + } + + /** + * Creates a Jagged Array of keys + */ + public void generateEngl() { + kb = new key[engl.length][]; + for (int i = 0; i < engl.length; i++) { + 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]); + } + } + } +} + +class key { + public String key; + public int keyID; + public boolean specialChar; + + public key(String text) { + key = text; + specialChar = text.length() == 1; + } +} diff --git a/src/language.java b/src/language.java new file mode 100644 index 0000000..f367c76 --- /dev/null +++ b/src/language.java @@ -0,0 +1,24 @@ + +public class language { + public String score, words, testOver, wpm, raw, accuracy, time; + + // This will later load from a text file so uses can change languages + public language() { + loadLanguage(); + } + + private void loadLanguage() { + loadEnglish(); + } + + // Temporary method + private void loadEnglish() { + score = "Score"; + words = " Words"; + testOver = "Test Complete!"; + wpm = "WPM"; + raw = " (raw)"; + accuracy = "Accuracy"; + time = "Time"; + } +} diff --git a/src/runner.java b/src/runner.java new file mode 100644 index 0000000..cb77af4 --- /dev/null +++ b/src/runner.java @@ -0,0 +1,7 @@ + +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"); + } +} diff --git a/src/utils.java b/src/utils.java new file mode 100644 index 0000000..8a7e233 --- /dev/null +++ b/src/utils.java @@ -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) + "\", "); + } + } + +} diff --git a/src/variables.java b/src/variables.java new file mode 100644 index 0000000..ab09154 --- /dev/null +++ b/src/variables.java @@ -0,0 +1,236 @@ +import java.io.File; +import java.io.FileNotFoundException; +import java.util.ArrayList; +import java.util.Random; +import java.util.Scanner; +import java.awt.*; + +public class variables { + public int fps = 5, lines = 3; + public boolean debug = false; + // Updating variables + private double WPM, score; + private String testString; + private String[] testWord; + private long startTime, endTime, elapsedTime; + public int typedLines, testWords, drawLines, wordMode; + public int wordModes[] = {5, 10, 25, 50, 100}; + public String userString; + public String WPMText, ScoreText; + public boolean gameRunning, testOver; + public ArrayList pressedKeys = new ArrayList(); + public ArrayList words = new ArrayList(); + public ArrayList drawStrings = new ArrayList(); + public ArrayList userInputStrings = new ArrayList(); + + // to do: + // Finish test when last word is spelled right + // calculate real WPM and actual WPM + boolean repeatWords, timerRunning; + Color typingPromptColors[], backgroundColor, textColor; + Rectangle rOptions, rScore, rWPM, rTopBar; + Random r = new Random(); + + public variables() { + loadSettings(); + loadWords(); + resetVars(); + generateNewTest(); + generateThemes(); + } + + public void resetVars() { + userString = ""; + testString = ""; + typedLines = 0; + generateNewTest(); + timerRunning = false; + elapsedTime = -1; + WPM = 0; + score = 0; + drawLines = lines; + gameRunning = true; + testOver = false; + } + + public void loadSettings() { + // This will load from a config file later. + wordMode = 1; + testWords = wordModes[wordMode]; + repeatWords = false; + } + + /** + * typingPromptColors + * 0 = not typed + * 1 = correctly typed + * 2 = incorrectly typed + */ + 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); + + backgroundColor = new Color(255,255,255); + textColor = new Color(0,0,0); + } + + public void loadWords() { + try { + File myObj = new File("words.txt"); + Scanner myReader = new Scanner(myObj); + while (myReader.hasNextLine()) { + String data = myReader.nextLine(); + words.add(data); + } + myReader.close(); + } catch (FileNotFoundException e) { + System.out.println("Could not find words file"); + e.printStackTrace(); + } + } + + /** + * Generates new test + * Called when program is first started and when user requests a new one. + */ + public void generateNewTest() { + testWord = generateRandomWords(); + testString = ""; + for (String x : testWord) + testString += x + " "; + testString = backspace(testString); + } + + /** + * Generates 'size' amount of random words + * Can only draw the same word once + */ + public String[] generateRandomWords() { + String[] toReturn = new String[testWords]; + ArrayList usedWords = new ArrayList(); + int wordChoice = r.nextInt(words.size()); + + if(!repeatWords) { + for(int i = 0; i < testWords; i++) { + while(usedWords.contains(wordChoice)) + wordChoice = r.nextInt(words.size()); + usedWords.add(wordChoice); + toReturn[i] = words.get(wordChoice); + } + } + else { + for(int i = 0; i < testWords; i++) { + wordChoice = r.nextInt(words.size()); + toReturn[i] = words.get(wordChoice); + } + } + return toReturn; + } + + /** + * Checks if user has completed test + * Called when user presses key + */ + public void checkTest() { + String lastWordOfTest = testString.substring(testString.lastIndexOf(" ") + 1); + String lastWordOfUser = userString.substring(userString.lastIndexOf(" ") + 1); + if(userString.length() == testString.length() && lastWordOfTest.equals(lastWordOfUser)) { + stopTimer(); + gameRunning = false; + testOver = true; + } + } + + public String backspace(String str) { + if (str != null && str.length() > 0) { + str = str.substring(0, str.length() - 1); + } + return str; + } + + /** + * Called when user presses key + * Updates game stats to prevent delayed info + */ + public void timingHandler() { + if(!timerRunning) { // Starts test + startTimer(); + timerRunning = true; + } + calculateGameStats(); + } + + public void startTimer() { + startTime = System.nanoTime(); + } + + public void stopTimer() { + if(timerRunning) + endTime = System.nanoTime(); + timerRunning = false; + calculateGameStats(); + } + + public void calculateGameStats() { + if(timerRunning) + elapsedTime = (System.nanoTime() - startTime)/10000; + else + elapsedTime = (endTime - startTime)/10000; + WPM = (double) userString.length() / 5 / elapsedTime * (60 / 0.00001); + WPM = round(WPM, 2); + } + + public double calculateAccuracy() { + int counter = 0; + for(int i = 0; i < testString.length(); i++) { + if(testString.charAt(i) == userString.charAt(i)) + counter++; + } + double toReturn = round((double)(counter)/testString.length(), 3); + return toReturn * 100; + } + + public double round(double number, int places) { + long shift = (long) Math.pow(10, places); + double shifted = number * shift; + shifted = Math.round(shifted); + return (double) (shifted)/shift; + } + + public void setTestSize(int x) { + testWords = x; + } + + public String getString() { + return testString; + } + + public String[] getTestWords() { + return testWord; + } + + public double getWPM() { + return WPM; + } + + public String generateElapsedTimeString() { + double time = ((double) (elapsedTime / 1000))/100; + return time + "s"; + } + public Long getElapsedTime() { + return elapsedTime; + } + + /** + * Checks if a specified point is inside a rectangle + * @param r the rectangle + * @param p the point + */ + public boolean isInRect(Rectangle r, Point p) { + return r.x <= p.x && r.x + r.width >= p.x + && r.y <= p.y && r.y + r.height >= p.y; + } + +} diff --git a/words.txt b/words.txt new file mode 100644 index 0000000..a28eef0 --- /dev/null +++ b/words.txt @@ -0,0 +1,1000 @@ +the +of +to +and +a +in +is +it +you +that +he +was +for +on +are +with +as +I +his +they +be +at +one +have +this +from +or +had +by +not +word +but +what +some +we +can +out +other +were +all +there +when +up +use +your +how +said +an +each +she +which +do +their +time +if +will +way +about +many +then +them +write +would +like +so +these +her +long +make +thing +see +him +two +has +look +more +day +could +go +come +did +number +sound +no +most +people +my +over +know +water +than +call +first +who +may +down +side +been +now +find +any +new +work +part +take +get +place +made +live +where +after +back +little +only +round +man +year +came +show +every +good +me +give +our +under +name +very +through +just +form +sentence +great +think +say +help +low +line +differ +turn +cause +much +mean +before +move +right +boy +old +too +same +tell +does +set +three +want +air +well +also +play +small +end +put +home +read +hand +port +large +spell +add +even +land +here +must +big +high +such +follow +act +why +ask +men +change +went +light +kind +off +need +house +picture +try +us +again +animal +point +mother +world +near +build +self +earth +father +head +stand +own +page +should +country +found +answer +school +grow +study +still +learn +plant +cover +food +sun +four +between +state +keep +eye +never +last +let +thought +city +tree +cross +farm +hard +start +might +story +saw +far +sea +draw +left +late +run +don't +while +press +close +night +real +life +few +north +open +seem +together +next +white +children +begin +got +walk +example +ease +paper +group +always +music +those +both +mark +often +letter +until +mile +river +car +feet +care +second +book +carry +took +science +eat +room +friend +began +idea +fish +mountain +stop +once +base +hear +horse +cut +sure +watch +color +face +wood +main +enough +plain +girl +usual +young +ready +above +ever +red +list +though +feel +talk +bird +soon +body +dog +family +direct +pose +leave +song +measure +door +product +black +short +numeral +class +wind +question +happen +complete +ship +area +half +rock +order +fire +south +problem +piece +told +knew +pass +since +top +whole +king +space +heard +best +hour +better +true +during +hundred +five +remember +step +early +hold +west +ground +interest +reach +fast +verb +sing +listen +six +table +travel +less +morning +ten +simple +several +vowel +toward +war +lay +against +pattern +slow +center +love +person +money +serve +appear +road +map +rain +rule +govern +pull +cold +notice +voice +unit +power +town +fine +certain +fly +fall +lead +cry +dark +machine +note +wait +plan +figure +star +box +noun +field +rest +correct +able +pound +done +beauty +drive +stood +contain +front +teach +week +final +gave +green +oh +quick +develop +ocean +warm +free +minute +strong +special +mind +behind +clear +tail +produce +fact +street +inch +multiply +nothing +course +stay +wheel +full +force +blue +object +decide +surface +deep +moon +island +foot +system +busy +test +record +boat +common +gold +possible +plane +stead +dry +wonder +laugh +thousand +ago +ran +check +game +shape +equate +hot +miss +brought +heat +snow +tire +bring +yes +distant +fill +east +paint +language +among +grand +ball +yet +wave +drop +heart +am +present +heavy +dance +engine +position +arm +wide +sail +material +size +vary +settle +speak +weight +general +ice +matter +circle +pair +include +divide +syllable +felt +perhaps +pick +sudden +count +square +reason +length +represent +art +subject +region +energy +hunt +probable +bed +brother +egg +ride +cell +believe +fraction +forest +sit +race +window +store +summer +train +sleep +prove +lone +leg +exercise +wall +catch +mount +wish +sky +board +joy +winter +sat +written +wild +instrument +kept +glass +grass +cow +job +edge +sign +visit +past +soft +fun +bright +gas +weather +month +million +bear +finish +happy +hope +flower +clothe +strange +gone +jump +baby +eight +village +meet +root +buy +raise +solve +metal +whether +push +seven +paragraph +third +shall +held +hair +describe +cook +floor +either +result +burn +hill +safe +cat +century +consider +type +law +bit +coast +copy +phrase +silent +tall +sand +soil +roll +temperature +finger +industry +value +fight +lie +beat +excite +natural +view +sense +ear +else +quite +broke +case +middle +kill +son +lake +moment +scale +loud +spring +observe +child +straight +consonant +nation +dictionary +milk +speed +method +organ +pay +age +section +dress +cloud +surprise +quiet +stone +tiny +climb +cool +design +poor +lot +experiment +bottom +key +iron +single +stick +flat +twenty +skin +smile +crease +hole +trade +melody +trip +office +receive +row +mouth +exact +symbol +die +least +trouble +shout +except +wrote +seed +tone +join +suggest +clean +break +lady +yard +rise +bad +blow +oil +blood +touch +grew +cent +mix +team +wire +cost +lost +brown +wear +garden +equal +sent +choose +fell +fit +flow +fair +bank +collect +save +control +decimal +gentle +woman +captain +practice +separate +difficult +doctor +please +protect +noon +whose +locate +ring +character +insect +caught +period +indicate +radio +spoke +atom +human +history +effect +electric +expect +crop +modern +element +hit +student +corner +party +supply +bone +rail +imagine +provide +agree +thus +capital +won't +chair +danger +fruit +rich +thick +soldier +process +operate +guess +necessary +sharp +wing +create +neighbor +wash +bat +rather +crowd +corn +compare +poem +string +bell +depend +meat +rub +tube +famous +dollar +stream +fear +sight +thin +triangle +planet +hurry +chief +colony +clock +mine +tie +enter +major +fresh +search +send +yellow +gun +allow +print +dead +spot +desert +suit +current +lift +rose +continue +block +chart +hat +sell +success +company +subtract +event +particular +deal +swim +term +opposite +wife +shoe +shoulder +spread +arrange +camp +invent +cotton +born +determine +quart +nine +truck +noise +level +chance +gather +shop +stretch +throw +shine +property +column +molecule +select +wrong +gray +repeat +require +broad +prepare +salt +nose +plural +anger +claim +continent +oxygen +sugar +death +pretty +skill +women +season +solution +magnet +silver +thank +branch +match +suffix +especially +fig +afraid +huge +sister +steel +discuss +forward +similar +guide +experience +score +apple +bought +led +pitch +coat +mass +card +band +rope +slip +win +dream +evening +condition +feed +tool +total +basic +smell +valley +nor +double +seat +arrive +master +track +parent +shore +division +sheet +substance +favor +connect +post +spend +chord +fat +glad +original +share +station +dad +bread +charge +proper +bar +offer +segment +slave +duck +instant +market +degree +populate +chick +dear +enemy +reply +drink +occur +support +speech +nature +range +steam +motion +path +liquid +log +meant +quotient +teeth +shell +neck \ No newline at end of file