Skip to content

Commit

Permalink
Homeworks and mini assignments
Browse files Browse the repository at this point in the history
  • Loading branch information
joel0 committed Jan 8, 2016
1 parent 0500c64 commit 2481072
Show file tree
Hide file tree
Showing 83 changed files with 14,215 additions and 0 deletions.
7 changes: 7 additions & 0 deletions homework2/.classpath
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path="src"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.7"/>
<classpathentry kind="con" path="org.eclipse.jdt.junit.JUNIT_CONTAINER/4"/>
<classpathentry kind="output" path="bin"/>
</classpath>
17 changes: 17 additions & 0 deletions homework2/.project
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>homework2</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
</projectDescription>
11 changes: 11 additions & 0 deletions homework2/.settings/org.eclipse.jdt.core.prefs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.7
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
org.eclipse.jdt.core.compiler.compliance=1.7
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
org.eclipse.jdt.core.compiler.debug.localVariable=generate
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
org.eclipse.jdt.core.compiler.source=1.7
5 changes: 5 additions & 0 deletions homework2/homework2.eml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<component jdk="JavaSE-1.7">
<exclude-output/>
<contentEntry url="file://$MODULE_DIR$"/>
</component>
2 changes: 2 additions & 0 deletions homework2/homework2.iml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<?xml version="1.0" encoding="UTF-8"?>
<module classpath="eclipse" classpath-dir="$MODULE_DIR$" type="JAVA_MODULE" version="4" />
94 changes: 94 additions & 0 deletions homework2/src/gui/UIMain.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
package gui;

import hw2.ScoreCalculator;
import hw2.Words;

import java.io.FileNotFoundException;
import java.util.Random;

import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.SwingUtilities;

import util.PermutationGenerator;

/**
* Main class for starting an instance of <code>WordGameUI</code>.
*/
public class UIMain
{
/**
* Entry point.
*/
public static void main(String[] args)
{
// Edit here to use a different word file
final String filename = "words2.txt";

// Edit here to change the seed for the WordScrambler's
// random number generator. For unpredictable behavior,
// use the system time as a seed:
final int seed = (int) System.currentTimeMillis();
//final int seed = 42;

// Boilerplate code for safely starting up a Swing application
// on the event-handling thread.
Runnable r = new Runnable()
{
public void run()
{
createAndShow(filename, seed);
}
};
SwingUtilities.invokeLater(r);
}

/**
* Helper method for creating and starting the UI.
* @param filename
* filename for word list
* @param seed
* seed for random number generator in the WordScrambler
*/
private static void createAndShow(String filename, int seed)
{
// the main window for this application
JFrame frame = new JFrame("Com S 227 Word Scramble");

try
{
// this may throw FileNotFoundException
Words wordList = new Words(filename);

// scoring based on
// 5 seconds per letter
// 5 second penalty for a letter hint
// 1/10 second penalty for rescrambling
// 1-second penalty for submitting an incorrect guess
ScoreCalculator calc = new ScoreCalculator(5000, 5000, 100, 1000);
Random rand = new Random(seed);
PermutationGenerator pg = new PermutationGenerator(rand);

// construct the main game panel and add it to the frame
JPanel mainPanel = new WordGameUI(calc, wordList, rand, pg);
frame.getContentPane().add(mainPanel);

// size the frame based on the preferred size of the mainPanel
frame.pack();

// make sure it closes when you click the close button on the window
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

// rock and roll...
frame.setVisible(true);
}
catch (FileNotFoundException e)
{
JOptionPane.showMessageDialog(frame, "Unable to open word file: " + e.getMessage());
frame.dispose();
}

}

}
Loading

0 comments on commit 2481072

Please sign in to comment.