Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions .classpath
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path="src"/>
<classpathentry kind="lib" path="lib/hamcrest-core-1.3.jar"/>
<classpathentry kind="lib" path="lib/junit-4.12-javadoc.jar"/>
<classpathentry kind="lib" path="lib/junit-4.12-sources.jar"/>
<classpathentry kind="lib" path="lib/junit-4.12.jar"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
<classpathentry kind="output" path="bin"/>
</classpath>
Binary file added lib/guava-bootstrap-jdk5-16.0.jar
Binary file not shown.
Binary file added lib/guava-jdk5-16.0-javadoc.jar
Binary file not shown.
Binary file added lib/guava-jdk5-16.0-sources.jar
Binary file not shown.
Binary file added lib/guava-jdk5-16.0.jar
Binary file not shown.
Binary file added lib/hamcrest-core-1.3.jar
Binary file not shown.
Binary file added lib/junit-4.12-javadoc.jar
Binary file not shown.
Binary file added lib/junit-4.12-sources.jar
Binary file not shown.
Binary file added lib/junit-4.12.jar
Binary file not shown.
8 changes: 8 additions & 0 deletions src/debug/ContainerArray.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,14 @@ public int size () {
}

public void remove (E objectToRemove) {
for (int i = 0; i < internalArray.length; i++) {
if (internalArray[i] == objectToRemove) {
for (int j = i; j < internalArray.length - 1; j++) {
internalArray[j] = internalArray[j+1];
}
break;
}
}
currentSize--;
}

Expand Down
4 changes: 4 additions & 0 deletions src/debug/ContainerArrayTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,11 @@ public void testObjectIsRemoved () {
String alligator = "Alligator";
myContainer.add("Alligator");
myContainer.add("Bear");
myContainer.add("Tiger");
myContainer.remove("Bear");
assertEquals("Remove should be same reference", alligator, myContainer.get(0));
assertEquals("Objects shoulld be the same", "Tiger", myContainer.get(1));

}

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

import static org.junit.Assert.assertEquals;

import org.junit.Before;
import org.junit.Test;

public class TestTextAreaGameDescriptionEditor {

private TextAreaGameDescriptionEditor editor = null;

@Before
public void setUp () {
editor = new TextAreaGameDescriptionEditor("Hello", "Go", 5, e -> printStuff());
}

public void printStuff() {
System.out.println("Hello");
}

@Test
public void testPromptText() {
assertEquals("Paddings should match", "Hello", editor.getPromptText());
}
}
31 changes: 31 additions & 0 deletions src/stephen_vooga/TextAreaGameDescriptionEditor.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package stephen_vooga;

import java.util.ResourceBundle;

import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.geometry.Insets;

/**
* Creates a VBox containing a Label prompting author to edit the game description, a TextArea in which the author
* can write the game description, and a Button allowing the author to save the text within the TextArea as the
* game's description
*
* @author Stephen
*
*/

public class TextAreaGameDescriptionEditor extends TextAreaParent {

private static final double VBOX_PADDING = 10.0;
private static final String RESOURCE_BUNDLE_KEY = "mainScreenGui";
private ResourceBundle myResources;

public TextAreaGameDescriptionEditor(String promptText, String buttonText, int prefRows, EventHandler<ActionEvent> handler) {
super(promptText, buttonText, prefRows, handler);
myResources = ResourceBundle.getBundle(RESOURCE_BUNDLE_KEY);
setContainerPadding(new Insets(VBOX_PADDING));
setTextAreaPromptText(myResources.getString("enterGameDescription"));
}

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

import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.geometry.Insets;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.control.TextArea;
import javafx.scene.layout.VBox;

/**
*
* Abstract class generating a VBox containing a Label prompting user to do something, a TextArea in which the author
* can enter text, and a Button that can perform any defined action
* game's description
*
* @author Stephen
*
*/

public abstract class TextAreaParent {

private VBox myContainer;
private Label myPrompt;
private TextArea myTextArea;
private Button myButton;

public TextAreaParent(String promptText, String buttonText, int prefRows, EventHandler<ActionEvent> handler) {
myContainer = new VBox();
myPrompt = new Label(promptText);
myPrompt.setWrapText(true);
myTextArea = new TextArea();
myTextArea.setPrefRowCount(prefRows);
myButton = new Button(buttonText);
myButton.setOnAction(handler);
myButton.prefWidthProperty().bind(myContainer.widthProperty());
myContainer.getChildren().addAll(myPrompt, myTextArea, myButton);
}

public void setContainerPadding(Insets insets) {
myContainer.setPadding(insets);
}

public String getPromptText() {
return myPrompt.getText();
}

protected void setTextAreaPromptText(String prompt) {
myTextArea.setPromptText(prompt);
}

public VBox getCoupledNodes() {
return myContainer;
}

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

import org.junit.Test;

import java.util.Arrays;

import static org.junit.Assert.assertEquals;

/**
* Created by rhondusmithwick on 4/7/16.
*
* @author Rhondu Smithwick
*/
public class ChallengePart1 {

@Test
public void testThatCellsAreEmptyByDefault() {
Sheet sheet = new Sheet();
String[] testStrings = new String[]{"A1", "ZX347"};
for (String s: testStrings) {
assertEquals("", sheet.get(s));
}
}

// Implement each test before going to the next one.

@Test
public void testThatTextCellsAreStored() {
Sheet sheet = new Sheet();
String theCell = "A21";

sheet.put(theCell, "A string");
assertEquals("A string", sheet.get(theCell));

sheet.put(theCell, "A different string");
assertEquals("A different string", sheet.get(theCell));

sheet.put(theCell, "");
assertEquals("", sheet.get(theCell));
}

// Implement each test before going to the next one; then refactor.

@Test
public void testThatManyCellsExist() {
Sheet sheet = new Sheet();
sheet.put("A1", "First");
sheet.put("X27", "Second");
sheet.put("ZX901", "Third");

assertEquals("A1", "First", sheet.get("A1"));
assertEquals("X27", "Second", sheet.get("X27"));
assertEquals("ZX901", "Third", sheet.get("ZX901"));

sheet.put("A1", "Fourth");
assertEquals("A1 after", "Fourth", sheet.get("A1"));
assertEquals("X27 same", "Second", sheet.get("X27"));
assertEquals("ZX901 same", "Third", sheet.get("ZX901"));
}


// Implement each test before going to the next one.
// You can split this test case if it helps.

@Test
public void testThatNumericCellsAreIdentifiedAndStored() {
Sheet sheet = new Sheet();
String theCell = "A21";

sheet.put(theCell, "X99"); // "Obvious" string
assertEquals("X99", sheet.get(theCell));

sheet.put(theCell, "14"); // "Obvious" number
assertEquals("14", sheet.get(theCell));

sheet.put(theCell, " 99 X"); // Whole string must be numeric
assertEquals(" 99 X", sheet.get(theCell));

sheet.put(theCell, " 1234 "); // Blanks ignored
assertEquals("1234", sheet.get(theCell));

sheet.put(theCell, " "); // Just a blank
assertEquals(" ", sheet.get(theCell));
}

// Refactor before going to each succeeding test.

public void testThatWeHaveAccessToCellLiteralValuesForEditing() {
Sheet sheet = new Sheet();
String theCell = "A21";

sheet.put(theCell, "Some string");
assertEquals("Some string", sheet.getLiteral(theCell));

sheet.put(theCell, " 1234 ");
assertEquals(" 1234 ", sheet.getLiteral(theCell));

sheet.put(theCell, "=7"); // Foreshadowing formulas:)
assertEquals("=7", sheet.getLiteral(theCell));
}

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

import java.util.HashMap;
import java.util.Map;

/**
* Created by rhondusmithwick on 4/7/16.
*
* @author Rhondu Smithwick
*/
public class Sheet {

private final Map<String, String> sheetMap = new HashMap<>();

public String get(String cell) {
String value = getLiteral(cell);
try {
Double.parseDouble(value);
return value.trim();
} catch (NumberFormatException n) {
return value;
}
}

public void put(String cell, String cellValue) {
sheetMap.put(cell, cellValue);
}

public String getLiteral(String cell) {
if (!containsCell(cell)) {
sheetMap.put(cell, "");
}
return sheetMap.get(cell);
}

private boolean containsCell(String cell) {
return sheetMap.containsKey(cell);
}
}
85 changes: 85 additions & 0 deletions src/voogasalad/rhondu/IComponent.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
package voogasalad.rhondu;

import com.google.common.base.Preconditions;
import javafx.beans.property.SimpleObjectProperty;

import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Optional;
import java.util.function.Predicate;


/**
* This is the interface for all components, which hold data.
*
* @author Rhondu Smithwick, Tom Wu
*/
public interface IComponent {

/**
* Returns if only one of this component is allowed.
*
* @return whether only one of these components is allowed for an Entity
*/
@Deprecated
default boolean unique() {
return false;
}

/**
* Gets any properties this component holds.
*
* @return all the properties this coompoennt holds
*/
default List<SimpleObjectProperty<?>> getProperties() {
return Collections.emptyList();
}

/**
* Gets a specific property with specified value class and with specified name.
* <p>
* Example call for a position:
* SimpleObjectProperty$Double$ x = position.getProperty(Double, "X");
*
* @param propertyClass the class of the property's held value
* @param name the name of property
* @param <T> the type of the property's held value
* @return specific property of specified class and with name
* @throws IllegalArgumentException if incorrect propertyClass or no property with this name is present
*/
@SuppressWarnings({"unchecked", "OptionalGetWithoutIsPresent"})
default <T> SimpleObjectProperty<T> getProperty(Class<T> propertyClass, String name) throws IllegalArgumentException {
Predicate<SimpleObjectProperty<?>> isRight = (s) -> (Objects.equals(s.getName(), name));
Optional<SimpleObjectProperty<?>> rightProperty = getProperties().stream().filter(isRight).findFirst();
boolean hasProperty = rightProperty.isPresent();
Preconditions.checkArgument(hasProperty, "No such property with this name is present");
boolean rightClass = propertyClass.isInstance(rightProperty.get().get());
Preconditions.checkArgument(rightClass, "Incorrect value class");
return (SimpleObjectProperty<T>) rightProperty.get();
}

/**
* Get a map, where each entry is a component name to it's value class.
*
* @return a map, where each entry is a component name to it's value class
*/
default Map<String, Class<?>> getPropertyNamesAndClasses() {
Map<String, Class<?>> nameCLassMap = new HashMap<>();
for (SimpleObjectProperty<?> property : getProperties()) {
nameCLassMap.put(property.getName(), property.get().getClass());
}
return nameCLassMap;
}

/**
* Return the class to put into an entity map.
*
* @return the class to be put into an Entity map
*/
default Class<? extends IComponent> getClassForComponentMap() {
return getClass();
}
}
Loading