Skip to content

Commit

Permalink
Fixing Things
Browse files Browse the repository at this point in the history
  • Loading branch information
erjoh committed Nov 10, 2019
0 parents commit 86bc56b
Show file tree
Hide file tree
Showing 14 changed files with 925 additions and 0 deletions.
7 changes: 7 additions & 0 deletions .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="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"/>
<classpathentry kind="src" path="src"/>
<classpathentry kind="con" path="org.eclipse.jdt.junit.JUNIT_CONTAINER/5"/>
<classpathentry kind="output" path="bin"/>
</classpath>
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/bin/
17 changes: 17 additions & 0 deletions .project
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>Individual_Project_2</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 .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.8
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
org.eclipse.jdt.core.compiler.compliance=1.8
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.8
19 changes: 19 additions & 0 deletions src/starter/Main.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package starter;

import starter.model.Model;
import starter.view.DoubleSlidedApp;

public class Main {

/**
* Main Method
* @param args: Arguments
*/
public static void main(String[] args) {
Model model = new Model();
DoubleSlidedApp dsa = new DoubleSlidedApp(model);

dsa.setVisible(true);
}

}
171 changes: 171 additions & 0 deletions src/starter/MyTests.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,171 @@
package starter;

import static org.junit.jupiter.api.Assertions.*;

import java.awt.Graphics;
import java.awt.event.MouseEvent;

import javax.swing.JPanel;

import org.junit.jupiter.api.Test;

import starter.controller.FlipController;
import starter.controller.ResetController;
import starter.model.EmptyTile;
import starter.model.Location;
import starter.model.Model;
import starter.model.Tile;
import starter.view.DoubleSlidedApp;
import starter.view.PuzzleView;

// REQUIRED CODE COVERAGE: 80%

public class MyTests {

// Main
@Test
public void testMain() {
Main m = new Main();
}

// Flip Controller Tests
@Test
public void testFlipController() {
Model m = new Model();
DoubleSlidedApp app = new DoubleSlidedApp(m);
FlipController fc = new FlipController(app, m);

// Standard Mouse Event
MouseEvent me = new MouseEvent(app, 0, 0, 0, 0, 0, 0, false);
fc.mousePressed(me);

// One inside the range
MouseEvent me1 = new MouseEvent(app, 100, 100, 100, 100, 100, 1, false);
fc.mousePressed(me1);

MouseEvent me2 = new MouseEvent(app, 100, 100, 150, 150, 100, 1, false);
fc.mousePressed(me2);

MouseEvent me3 = new MouseEvent(app, 100, 100, 300, 300, 300, 1, false);
fc.mousePressed(me3);

MouseEvent me4 = new MouseEvent(app, 100, 100, 250, 250, 250, 1, false);
fc.mousePressed(me4);

MouseEvent me5 = new MouseEvent(app, 100, 100, 250, 425, 425, 1, false);
fc.mousePressed(me5);

MouseEvent me6 = new MouseEvent(app, 100, 100, 285, 285, 285, 1, false);
fc.mousePressed(me6);
}

// Reset Controller Tests
@Test
public void testResetController() {
Model m = new Model();
DoubleSlidedApp app = new DoubleSlidedApp(m);
ResetController r = new ResetController(app, m);
}

@Test
public void testResetControllerReset() {
Model m = new Model();
DoubleSlidedApp app = new DoubleSlidedApp(m);
ResetController r = new ResetController(app, m);

r.reset();
}

// DoubleSlidedApp Class Tests
@Test
public void testDoubleSlidedApp() {
Model m = new Model();
DoubleSlidedApp app = new DoubleSlidedApp(m);

}

// Location Class Tests
@Test
public void testCheckLocation() {
Location loc = new Location(3, 5);
loc.setLocation(4, 4);
assertTrue(loc.row == 4 & loc.col == 4);
assertFalse(loc.row == 3);
assertFalse(loc.col == 5);
}

// Empty Tile Class Tests
@Test
public void testGetEmptyLocation() {
EmptyTile emp = new EmptyTile(new Location(1, 2));
assertTrue(emp.getLocation().row == 1 & emp.getLocation().col == 2);
}

// Tile Class Tests
@Test
public void testSetLocation() {
Tile t = new Tile(1, 4, true, new Location(0, 0));

t.setLocation(new Location(4, 4));

assertTrue(t.getLocation().row == 4 & t.getLocation().col == 4);
}

@Test
public void testGetLocation() {
Tile t = new Tile(1, 4, true, new Location(0, 0));

assertTrue(t.getLocation().row == 0 & t.getLocation().col == 0);
}

@Test
public void testVisibleDigit() {
Tile t = new Tile(1, 4, true, new Location(0, 0));
assertTrue(t.visibleDigit() == 1);
assertFalse(t.visibleDigit() == 4);

Tile t1 = new Tile(1, 4, false, new Location(0, 0));
assertTrue(t1.visibleDigit() == 4);
assertFalse(t1.visibleDigit() == 1);
}

@Test
public void testIsUp() {
Tile t1 = new Tile(1, 4, false, new Location(0, 0));
assertTrue(t1.isUp());
Tile t2 = new Tile(1, 4, true, new Location(0, 0));
assertTrue(t2.isUp() == false);
}

@Test
public void testFlipTile() {
Tile t3 = new Tile(1, 4, true, new Location(0, 0));
t3.flipTile();
assertTrue(t3.isUp());
t3.flipTile();
assertTrue(!t3.isUp());
}

// Model Class Tests
@Test
public void testNeighboringEmpty() {
Model m = new Model();

m.getEmpty().setLocation(new Location(0, 1));
Tile[] t = m.getTiles();
t[0].setLocation(new Location(0, 0));

assertTrue(m.neighboringEmpty(t[0]));
}

// // PuzzleView Tests
// @Test
// public void testPuzzleView() {
// Model m = new Model();
// JPanel j = new JPanel();
// PuzzleView pv = new PuzzleView(m);
// Graphics g = j.getGraphics();
// pv.paintComponent(g);
// }

}
120 changes: 120 additions & 0 deletions src/starter/controller/FlipController.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
package starter.controller;

import java.awt.Graphics;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;

import javax.swing.JOptionPane;

import starter.model.Location;
import starter.model.Model;
import starter.model.Tile;
import starter.view.DoubleSlidedApp;

public class FlipController extends MouseAdapter {
Model model; // The model
DoubleSlidedApp app; // The application

/**
* The Flip Controller Constructor
*
* @param app: the Double Sided Application
* @param model: the model
*/
public FlipController(DoubleSlidedApp app, Model model) {
this.app = app;
this.model = model;
}

/**
* The mousePressed Event
*
* @param me: a Mouse pressed event
* @param void
*/
public void mousePressed(MouseEvent me) {

// Determine the location of the click
Location loc = whichTilePressed(me);

// Account for if that location exists outside of bounds
if (loc == null) {

} else {
// determine which tile exists in that location
Tile tile = model.whichTile(loc);
if (tile == null) {

} else {

if (model.neighboringEmpty(tile)) {
// move the given tile
if(!model.didLose(model.getTiles()) & !model.didWin(model.getTiles(), model.getEmpty())) {
model.moveTile(tile);
}
// check win/loss
if(model.didLose(model.getTiles())){
// run loss condition stuff
// Is this good coding practice?
JOptionPane.showMessageDialog(null, "You have lost the game!");
}else if(model.didWin(model.getTiles(), model.getEmpty())) {
// run win condition stuff
// Is this good coding practice?
JOptionPane.showMessageDialog(null, "Congratulations! You have won the game in " + model.getMoves() +" moves!");

}
app.numberMovesLabel.setText(""+ model.getMoves());
app.repaint();
//System.out.print("Repainted");
}
}

}

}

/**
* Determines the location of which tile was pressed in location form
*
* @param me: a mouse event
* @return Location: the location of the press
*/
public Location whichTilePressed(MouseEvent me) {

// initialize outside of normal bounds
int row = 5;
int col = 5;

// determine click location
int x = me.getX();
int y = me.getY();

Location loc = new Location(5, 5);

// logic for which area was outside of bounds
if (x > 0 & x < 425 & y > 0 & y < 425) {

if (x > 0 & x < 140) {
col = 0;
} else if (x >= 140 & x < 285) {
col = 1;
} else {
col = 2;
}

if (y > 0 & y < 140) {
row = 0;
} else if (y >= 140 & y < 285) {
row = 1;
} else {
row = 2;
}

loc.setLocation(row, col);

return loc;
}

return null;
}
}
31 changes: 31 additions & 0 deletions src/starter/controller/ResetController.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package starter.controller;

import starter.model.Model;
import starter.view.DoubleSlidedApp;

public class ResetController {
Model model; // The model
DoubleSlidedApp app; // The application

/**
* Constructor for the reset Controller
*
* @param app: the application
* @param model: the model
*/
public ResetController(DoubleSlidedApp app, Model model) {
this.app = app;
this.model = model;
}

/**
* Resets the board
*
* @return void
*/
public void reset() {
model.reset();
app.numberMovesLabel.setText(""+ model.getMoves());
app.repaint();
}
}
Loading

0 comments on commit 86bc56b

Please sign in to comment.