id
stringlengths
36
36
text
stringlengths
1
1.25M
80f7a1a4-63dd-422f-b9e5-bc8b4dba19b1
abstract void gameKeyUp(int keyCode);
918e13f8-d6e9-4526-851f-d8ee11ba02da
public Game(String name, int width, int height) { super(name); this.screenWidth = width; this.screenHeight = height; // Graphics Setup backBuffer = new BufferedImage(screenWidth, screenHeight, BufferedImage.TYPE_INT_RGB); g2d = backBuffer.createGraphics(); // Controls addKeyListener(this); }
8eeb4255-18b1-4cb7-9cf7-da8f5301a8e6
public void start() { // Show the screen setSize(this.screenWidth, this.screenHeight); Dimension dim = Toolkit.getDefaultToolkit().getScreenSize(); this.setLocation(dim.width/2-this.getSize().width/2, dim.height/2-this.getSize().height/2); setVisible(true); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE...
1f9482a3-8a06-482c-9e63-cc292aa6c659
public void run() { Thread t = Thread.currentThread(); /** * Credit to Eli Delvanthal for the loop structure * http://www.java-gaming.org/index.php?topic=24220.0 */ final double GAME_HERTZ = 30.0; // Calculate how many ns each frame should take for our target game hertz. final double TIME_BETWE...
d5f60669-1506-4200-a94f-386a866fa5c7
public void stop() { gameLoop = null; }
38a289e2-8c25-4fbd-b410-4c81c57da7e7
public void pauseGame() { paused = true; }
a74c5697-2506-4462-a205-ffb38aebb168
public void unpauseGame() { paused = false; }
2cd64e07-1310-4fc7-b231-37f6a19df3ab
public void render(float interpolation) { setInterpolation(interpolation); repaint(); }
375704a9-cd31-4e16-99a5-d607d7d304e8
public void setInterpolation(float interp) { interpolation = interp; }
1fae7db3-3081-4344-a7e7-e6f89c5f0d7a
public void paint(Graphics g) { g2d.clearRect(0, 0, this.screenWidth, this.screenHeight); // Draw individual components gameDraw(interpolation); g.drawImage(backBuffer, 0, 0, this); }
ec6dee3f-ce7b-486a-a51d-772ad913983f
public void keyTyped(KeyEvent k) {}
84802d79-bb80-444f-8cbf-3c8835ed38ea
public void keyPressed(KeyEvent k) { gameKeyDown(k.getKeyCode()); }
894ef158-390f-4b1f-9537-552e4b13ee3d
public void keyReleased(KeyEvent k) { gameKeyUp(k.getKeyCode()); }
b441c22d-7f72-421b-aa06-5692ff9c6fd4
public static <T> List<T> listOf(final T... entries) { final List<T> list = new ArrayList<T>(); for (final T t : entries) { list.add(t); } return list; }
aca6d991-b310-4e80-b246-a5d4d68c1c80
public static BorderLayout newPaddedBorderLayout() { final BorderLayout borderLayout = new BorderLayout(); borderLayout.setVgap(PADDING); borderLayout.setHgap(PADDING); return borderLayout; }
cdf44c22-d02a-4934-9f65-2644b67284c0
public static GridLayout newPaddedGridLayout(final int rows, final int columns) { final GridLayout gridLayout = new GridLayout(rows, columns); gridLayout.setVgap(PADDING); gridLayout.setHgap(PADDING); return gridLayout; }
d9c330bb-771d-4103-8a9f-9398c41e93e4
public static JPanel newEmptyBorderedPanel() { final JPanel panel = new JPanel(); panel.setBorder(new EmptyBorder(PADDING, PADDING, PADDING, PADDING)); return panel; }
08135a78-7cc6-4c43-b6ac-741cfa254dba
public GUI() { makeFrame(); }
874a4b57-97de-4f62-9d80-53d2d354d9dd
public void makeFrame() { frame = new JFrame("Word Up"); frame.setMinimumSize(new Dimension(400, 200)); contentPane = frame.getContentPane(); buttonsPanel = new JPanel(); buttonsPanel.setLayout(new GridLayout(1,2)); submit = new JButton("Submit"); submit.addActionListener(new ActionListener() { public void ...
3a925288-c225-49c3-8c5c-a3569114d9a0
{ public void actionPerformed(final ActionEvent e) { submitWord(); }
102e6f92-a0bf-43a4-968e-da2c9f15b3ed
public void actionPerformed(final ActionEvent e) { if(Game.round == 5){ ScoresDisplay.highScores.loadScores(); Game.endGame(); }else{ Game.startRound(); } }
a6f171bd-a09c-491f-8222-63265d480344
public void makeMenuBar(final JFrame frame) { final JMenuBar menubar = new JMenuBar(); frame.setJMenuBar(menubar); final JMenu fileName = new JMenu("File"); menubar.add(fileName); final JMenuItem newGameItem = new JMenuItem("Start New Game"); newGameItem.addActionListener(new ActionListener(){ public v...
f1c62d5c-8c36-4199-95e3-4d2ec1b13183
public void actionPerformed(final ActionEvent e){ Game.round = 0; Game.points = 0; Game.startRound(); }
daf586da-ba2a-4ac0-8aff-bb0d10d8a6c4
{ public void actionPerformed(final ActionEvent e) { new About(); }
472b622a-583a-465d-85eb-dd0547add141
{ public void actionPerformed(final ActionEvent e) { quit(); }
1e7e4051-1b72-4190-bb5f-93da8c6ad532
public void actionPerformed(final ActionEvent e){ Game.scores.displayScores(); }
41aee645-b619-43af-8456-4f68d797990d
public void submitWord(){ Game.latestWord = wordBox.getText(); Game.endRound(); }
43f02d10-411d-40bf-9693-3a50d10472bd
private void quit() { System.exit(0); }
31328f5f-2d42-4134-8a23-aff0c62d38f4
public void initialiseRound(){ submit.setEnabled(true); nextRound.setEnabled(false); nextRound.setText("Next Round"); resultText.setText(""); couldveHadText.setText(""); wordBox.setText(""); lettersText.setText("Your Letters Are: "); enterText.setText("Please Enter Your Word:"); }
347b1252-7ab3-4e34-b4a4-3d87dadf6f21
public void setRoundText(final String s){ roundText.setText(s); }
895fd9d4-3548-4f5d-bf33-5fed829e637a
public void setNextRoundText(final String s){ nextRound.setText(s); }
6477b641-a0bd-429f-922a-f9619d2c7f3f
public void setLetrersText(final String s){ lettersText.setText(s); }
05df38d3-026a-4d85-a495-1220ec815671
public void setLetter1(final String s){ Letter1.setText(s); }
ba9a3c9a-0719-4858-96f8-b86a13d3656a
public void setLetter2(final String s){ Letter2.setText(s); }
bdd11428-2d0e-4754-8c30-975de53b12af
public void setLetter3(final String s){ Letter3.setText(s); }
560d6da8-cccf-4aec-bc35-075d0040fa0c
public void updatePotentialSolutionsBar(final List<String> answers) { final int a = answers.size(); final String[] answersToPrint = new String[5]; for(int i = 0; i < a && i < 5; i++){ final double z = Math.random(); answersToPrint[i] = answers.get((int)(answers.size()*z)); answers.remove((int)(answer...
59da29f5-93de-4b2b-a6dd-a6f787eeb617
public void endGame(final int points, final int round) { GUI.nextRound.setEnabled(false); GUI.submit.setEnabled(false); GUI.enterText.setText(""); GUI.roundText.setText("Game Complete"); GUI.lettersText.setText(""); GUI.Letter1.setText(""); GUI.Letter2.setText(""); GUI.Letter3.setText(""); GUI.resultText.setTe...
61bc7948-f336-4634-8ea6-539fb5f7c3a6
public ScoresDisplay() { }
6750e203-1f00-480a-aa7b-3f516c1e12d5
public void displayScores() { this.frame = new JFrame("Word Up"); this.frame.setLocationRelativeTo(null); this.contentPane = this.frame.getContentPane(); highScores.loadScores(); this.title = new JLabel("High Scores:"); this.title.setHorizontalAlignment(SwingConstants.CENTER); this.scoresPanel = new JPane...
c51923a1-7229-4bc9-8704-d2950dc560de
public void newHighScore(){ this.frame = new JFrame("Word Up Scores"); this.frame.setLocationRelativeTo(null); this.contentPane = this.frame.getContentPane(); this.title = new JLabel("Well Done! You Got A High Score"); this.title.setHorizontalAlignment(SwingConstants.CENTER); this.scoresPanel = new JPanel(); ...
6b0393ae-24c7-4248-8405-e58a270dd12c
{ public void actionPerformed(final ActionEvent e) { final String i = ScoresDisplay.wordBox.getText(); highScores.saveHighScore(Game.points, i); displayScores(); ScoresDisplay.submit.setEnabled(false); }
b5cec5f9-824b-40b8-b1cf-6ce27f7a3ade
public About() { makeFrame(); }
cede5793-be67-4d0b-9add-f41c090750a4
public void makeFrame() { initializeCenterPanel(); this.frame.setLayout(GuiUtils.newPaddedBorderLayout()); this.frame.add(this.panel, BorderLayout.CENTER); this.frame.pack(); this.frame.setLocationRelativeTo(null); this.frame.setVisible(true); }
d0f47337-2880-4107-8934-7088165f62e1
private void initializeCenterPanel() { this.panel.setLayout(GuiUtils.newPaddedGridLayout(4, 1)); this.panel.add(this.gameName); this.panel.add(this.author1); this.panel.add(this.author2); this.panel.add(this.version); }
739f8564-5d5e-44b3-a24b-f1779e27274a
public boolean wordContainsLettersInOrder(final LetterGen letGen, final String word) { final char[] a = word.toCharArray(); final char[] test = new char[a.length]; for(int i=0; i < a.length; i++){ test[i] = Character.toLowerCase(a[i]); } int i = 0; char temp = Character.toLowerCase(letGen.getLetter1()); w...
6f4d8c6c-af7f-4281-9a0a-0b63522459f8
public boolean wordExists(final String word, final List<String> words){ for (final String current : words) { if( word.equalsIgnoreCase(current) ) { return true; } } return false; }
a67fbaad-b04b-42c2-aa39-d6592c0407f5
public List<String> findSolutions(final LetterGen letGen, final List<String> words) { final List<String> solutions = new ArrayList<String>(); for (final String word : words) { if( wordContainsLettersInOrder(letGen, word) ) { solutions.add(word); } } return solutions; }
5e5d2e85-bfb2-4396-9bed-2caac133a8b5
public LetterGen(){ final int x = (int)(Math.random()*26); final int y = (int)(Math.random()*26); final int z = (int)(Math.random()*26); this.letter1 = letters[x]; this.letter2 = letters[y]; this.letter3 = letters[z]; }
33c06d01-b6be-46f6-b911-0823146f2b0d
public LetterGen(final char letter1, final char letter2, final char letter3){ this.letter1 = letter1; this.letter2 = letter2; this.letter3 = letter3; }
c4c1ce38-0664-4948-937e-46431127fdc3
public char getLetter1(){ return this.letter1; }
dd22de2d-263f-4645-aa99-c50fcf8117e5
public char getLetter2(){ return this.letter2; }
5c5605ea-ee7d-4799-8818-0c159ec8fe54
public char getLetter3(){ return this.letter3; }
5bfe262d-101f-46bf-9901-3e6e4706f07a
public wordListCombinor(String newFile){ }
bc3d6efa-3ae9-4dd9-8e12-b9f3a1a7874a
public static void main(String firstFile, String secondFile){ combine(firstFile, secondFile); }
19da8315-2c40-4e71-b2de-7ebc9e7b9ec9
private static void combine(String f, String s){ try{ readerA = new BufferedReader(new FileReader("" + f + ".txt")); new Scanner(readerA); readerB = new BufferedReader(new FileReader("" + s + ".txt")); new Scanner(readerB); } catch(FileNotFoundException e){ System.err.println("Files Could Not Be Fo...
b49b3d50-c356-4ac0-b4dc-cb6563ea4368
public WordListCleanUp() { }
a90d8b7a-3d6b-44d2-b740-639b7c0c16f6
public static void main(String args[]){ wordListCombinor.main("extraWords", "wordList"); WordListCleanUp.readIn(); WordListCleanUp.writeCleanFile(); System.out.println("File Clean Complete"); }
696a8de9-f6c0-4f94-90c3-d9faf381a5f3
private static void readIn(){ try{ reader = new BufferedReader(new FileReader("MegaDictionary.txt")); new Scanner(reader); } catch(FileNotFoundException e){ System.err.println("File Could Not Be Found"); return; } try{ String word = reader.readLine(); while(word != null){ if(goodWord(wor...
c4b8b0a6-4103-4f8b-96ea-fb01fdb18685
private static boolean goodWord(String s){ if(s.contains("-")){ return false; }else if(s.contains("'")){ return false; }else if(s.contains(" ")){ return false; }else if(s.contains(".")){ return false; }else if(s.contains("fuck")){ return false; }else if(s.contains("shit")){ return false; ...
73fc0da2-9003-496b-9c0e-ac3734134796
private static void writeCleanFile(){ try{ writer = new FileWriter("MegaDictionary.txt"); } catch(IOException e){ System.err.println("New File Could Not Be Initialised For Writing"); } for(int i = 0; i<words.size(); i++){ String toWrite = (words.get(i)); char[] write = toWrite.toCharArray(); ...
428cba03-c8e6-4f63-a1cc-14f320400140
public Scores() { }
ed962e7a-aece-481d-9017-f416401e65e3
public void loadScores(){ try{ reader = new BufferedReader(new FileReader("HighScore.txt")); new Scanner(reader); } catch(FileNotFoundException e){ System.out.println("waah!"); return; } for(int x = 0; x<5; x++){ ...
71a1aad6-4cc5-4926-8476-e39ac510b3b4
public static boolean isHighScore(int score){ Integer scorez = 0; for(int i = 0; i < 5; i++){ scorez = Integer.parseInt(topScores[i][1]); if(score > scorez){ return true; } } return false; }
6f82e7b7-d9a4-4251-8b74-d6db67bf698c
public void saveHighScore(int score, String name){ try{ f= new FileWriter("HighScore.txt"); }catch(IOException e){ System.out.println("fail"); } sort(); Integer lowest = 1000; Integer lowestKey = 0; for(int i = 0; i<5; i++){ if(...
a2eedf84-63e1-450b-b849-fa816423e0b5
public void sort(){ for(int i = 0; i<5; i++){ for(int j = 0; j<4; j++){ if(Integer.parseInt(topScores[j][1]) < Integer.parseInt(topScores[j+1][1])){ String score = topScores[j+1][1]; String name = topScores[j+1][0]; ...
6fc8120e-29fa-411c-90ed-2c86adf4c132
public Game(){ }
dabfcc86-c172-4ba0-bc9d-860497c8a9ca
public static void main(final String[] args){ final Game game = new Game(); game.initialiseWordsList(); game.launch(); }
c9631458-a898-44f8-9120-fe04f48a1088
private void launch() { gui = new GUI(); }
3941a0e6-4116-48b2-ab4d-39e9bc45fed4
public void initialiseWordsList() { try{ final BufferedReader reader = new BufferedReader(new FileReader("MegaDictionary.txt")); String current = reader.readLine(); while(current != null) { Game.words.add(current.toLowerCase()); current = reader.readLine(); } reader.close(); } catch(fi...
f4c63834-b2be-410a-8748-498ef591bcca
public static int getPoints(){ return points; }
f3b8f476-686e-4020-8291-b87e471b4ad4
public static void startRound(){ round = round + 1; gui.initialiseRound(); letGen = new LetterGen(); while(howHardCanItBe() == false) { letGen = new LetterGen(); } if(Game.round == 1){ gui.setRoundText("Let's Begin! Round 1"); } else if(Game.round == 5){ gui.setRoundText("Last Round, Final Chanc...
a23cfd33-e22a-4111-b0ea-69746c099de5
public static void endRound() { GUI.nextRound.setEnabled(true); GUI.submit.setEnabled(false); if(wordExists(latestWord) == false){ GUI.resultText.setText("That Word Doesn't Exist. You Scored 0 Points."); heresWhatYouCouldHaveWon(); gui.updatePotentialSolutionsBar(answers); } else if(lettersInOrder(...
d61ea3d2-1a1d-40e2-a101-4844ee713eac
public static void endGame() { gui.endGame(points, round); //Handle high score scenario if(Scores.isHighScore(points)) { GUI.enterText.setText("So, You Got A High Score =D"); Game.highScores(); } else { GUI.enterText.setText("Unfortunately, This Wasn't Good Enough For A High Score =("); } }
b5a4ec65-3956-4df6-9a2b-69b18d25294c
public static void highScores() { scores.newHighScore(); }
498bcb9b-c91a-415a-976c-e5c5741c2a8b
public static boolean wordExists(final String word){ return wordValidator.wordExists(word, words); }
d9ed7feb-1446-4bf7-8d18-af0180fd572c
public static boolean lettersInOrder(final String word){ return wordValidator.wordContainsLettersInOrder(letGen, word); }
c9349e61-cb75-4e37-8329-cd73a76c05b8
public static boolean howHardCanItBe(){ for (final String word : words) { if( wordValidator.wordContainsLettersInOrder(letGen, word) ) { return true; } } return false; }
a226311b-7fac-4942-943d-e4907b248aec
public static void heresWhatYouCouldHaveWon(){ answers.clear(); answers.addAll(wordValidator.findSolutions(letGen, words)); }
ac1f1db1-82aa-41bc-be0a-4ffee6ffe4fe
@Before public void setUp() { this.wordValidator = new WordValidator(); }
0999721e-0e96-41a0-bed4-83e981132a23
@Test public void thatWordContainsAllLettersInOrderIsTrue() { assertThat(this.wordValidator.wordContainsLettersInOrder(new LetterGen('a', 'b', 'c'), "abc"), is(true)); }
8e157014-c238-42ac-b73b-9c8122c81e82
@Test public void thatWordContainsAllLettersInOrderIsTrueWithUpperCaseLetters() { assertThat(this.wordValidator.wordContainsLettersInOrder(new LetterGen('A', 'B', 'C'), "abc"), is(true)); }
551d0c8f-e033-467c-89ec-8889798090e2
@Test public void thatWordContainsAllLettersInOrderIsTrueWithUpperCaseWord() { assertThat(this.wordValidator.wordContainsLettersInOrder(new LetterGen('a', 'b', 'c'), "ABC"), is(true)); }
ff0dbc56-df65-4882-b08d-6a37f5ba840e
@Test public void thatWordContainsAllLettersOutOfOrderIsFalse() { assertThat(this.wordValidator.wordContainsLettersInOrder(new LetterGen('c', 'b', 'a'), "abc"), is(false)); }
8b8f8489-0170-4233-bea3-3a769bddeae3
@Test public void thatWordDoesNotContainFinalLetterIsFalse() { assertThat(this.wordValidator.wordContainsLettersInOrder(new LetterGen('a', 'b', 'd'), "abc"), is(false)); }
5b53ceec-c6b1-48fa-bea2-6f2f34ac166c
@Test public void thatWordDoesNotContainMiddleLetterIsFalse() { assertThat(this.wordValidator.wordContainsLettersInOrder(new LetterGen('a', 'd', 'c'), "abc"), is(false)); }
ffe19685-976c-45cd-b6d7-b99b757ecbe2
@Test public void thatWordDoesNotContainFirstLetterIsFalse() { assertThat(this.wordValidator.wordContainsLettersInOrder(new LetterGen('d', 'b', 'c'), "abc"), is(false)); }
e3d2632d-29df-48f7-9feb-dbf572d3f65a
@Test public void thatWordExistsIsTrueWhenWordExistsFirstWord() { final List<String> words = CollectionUtils.listOf("abc", "def", "ghi", "jkl", "mno"); assertThat(this.wordValidator.wordExists("abc", words), is(true)); }
3bf8ec61-149b-46c4-9a41-a8fe97fe2f46
@Test public void thatWordExistsIsTrueWhenWordExistsNotFirstWord() { final List<String> words = CollectionUtils.listOf("abc", "def", "ghi", "jkl", "mno"); assertThat(this.wordValidator.wordExists("jkl", words), is(true)); }
3b605a80-3f30-4a3c-8171-627fdfbca10e
@Test public void thatWordExistsIsFalseWhenWordDoesNotExist() { final List<String> words = CollectionUtils.listOf("abc", "def", "ghi", "jkl", "mno"); assertThat(this.wordValidator.wordExists("zyx", words), is(false)); }
5c6a7e22-be64-4a05-8f4b-f9325f34ee0f
@Test public void thatWordExistsIgnoresCaseOfWord() { final List<String> words = CollectionUtils.listOf("abc", "def", "ghi", "jkl", "mno"); assertThat(this.wordValidator.wordExists("DEF", words), is(true)); }
e21cab54-69fa-4a65-ae0a-2f64c9702044
@Test public void thatWordExistsIgnoresCaseOfWordsInList() { final List<String> words = CollectionUtils.listOf("ABC", "DEF", "GHI", "JKL", "MNO"); assertThat(this.wordValidator.wordExists("abc", words), is(true)); }
da202250-8aba-4b6c-97da-fa5964a53825
@Test public void thatFindSolutionsReturnsAllSolutions() { final List<String> words = CollectionUtils.listOf("ananad", "bnbnbd", "cncnc"); final List<String> solutions = this.wordValidator.findSolutions(new LetterGen('n','n','d'), words); assertThat(solutions.size(), is(2)); assertThat(solutions.get(0), is("an...
31425387-1852-4896-b88f-8efdab62adc1
public WinCanvas(){ setPreferredSize(dim); setMaximumSize(dim); setMinimumSize(dim); hnd = new Handler(); rand = new Random(); for(int i = 0; i < AMOUNT; i++){ int tSize = 18+ rand.nextInt(20); hnd.addObject(new Tiplets(rand.nextInt(dim.width), rand.nextInt(dim.height),tSize, tSize)); } hnd.ord...
2c578e23-a81c-4e41-a198-f42642f0dba9
public synchronized void start(){ if(running) return; running = true; thread = new Thread(this); thread.start(); }
cbcfddd5-ce96-404f-aea9-e8842cb00f77
public synchronized void stop(){ if(!running)return; running = false; try{ thread.join(); } catch(Exception e){ e.printStackTrace(); } }
c54ad930-00ca-46a7-ae10-3727f718d278
public void run(){ long lastTime = System.nanoTime(); double ns = 1000000000 / 60; double delta = 0; long timer = System.currentTimeMillis(); while(running){ long now = System.nanoTime(); delta += (now - lastTime) / ns; lastTime = now; while(delta >= 1){ update(); delta--; ups++; }...
5d2a3633-202e-420b-b4f5-b3ddac80c5d8
public void update(){ hnd.update(); }
8ee406da-edac-4238-8931-119e815ab65e
public void draw(){ BufferStrategy bs = getBufferStrategy(); if(bs == null){ createBufferStrategy(3); return; } Graphics2D g = (Graphics2D)bs.getDrawGraphics(); // g.setColor(Color.yellow); g.fillRect(0, 0, dim.width, dim.height); hnd.draw(g); // bs.show(); g.dispose(); }
0a69e8f7-9223-4b65-b0a5-873615c2015d
public static void main(String[] args){ WinCanvas canvas = new WinCanvas(); JFrame frame = new JFrame("Rain!"); frame.add(canvas); frame.setResizable(false); frame.pack(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setVisible(true); canvas.start(); }
602d0c2f-3666-41d9-bed1-a84d0d9f1848
public Handler(){ }