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
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="src" path="src"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
<classpathentry kind="con" path="org.eclipse.jdt.junit.JUNIT_CONTAINER/4"/>
<classpathentry kind="output" path="bin"/>
</classpath>
22 changes: 20 additions & 2 deletions src/debug/ContainerArray.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package debug;

import java.util.Arrays;


public class ContainerArray<E> {
private int initialCapacity = 10;
private int limit = 10;
private int currentSize = 0;
private Object[] internalArray;

Expand All @@ -23,7 +25,23 @@ public int size () {
}

public void remove (E objectToRemove) {
currentSize--;
int toBeRemoved = 0;

if (objectToRemove instanceof String) {
int n = 0;
while (internalArray[n] != null){
if (((String)internalArray[n]).equals((String) objectToRemove)){
internalArray[n] = null;
toBeRemoved++;
}
n++;
}
internalArray = Arrays.stream(internalArray)
.filter(s -> (s != null))
.toArray(Object[]::new);

currentSize -= toBeRemoved;
}
}

@SuppressWarnings("unchecked")
Expand Down
15 changes: 15 additions & 0 deletions src/debug/ContainerArrayTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,19 @@ public void testObjectIsRemoved () {
myContainer.remove("Bear");
assertEquals("Remove should be same reference", alligator, myContainer.get(0));
}

/**
* Just wrote this one test, we understand the idea and will
* now go play with VoogaSalad
*/
@Test
public void testRemovesCorrectElement(){
System.out.println("START");
String falcon = "Falcon";
myContainer.add("Alligator");
myContainer.add("Bear");
myContainer.add(falcon);
myContainer.remove("Bear");
assertEquals("Remove should be of correct index", falcon, myContainer.get(1));
}
}
35 changes: 35 additions & 0 deletions src/tdd/Sheet.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package tdd;

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

public class Sheet {

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

public String get(String in){
if (sheetMap.containsKey(in)){
String temp = sheetMap.get(in);
temp = temp.replaceAll(" +", "");
if (isNumeric(temp)){
return temp;
}
else
return sheetMap.get(in);
}
else
return "";
}

public boolean isNumeric(String s) {
return s.matches("[-+]?\\d*\\.?\\d+");
}

public void put(String key, String mapping){
sheetMap.put(key, mapping);
}

public String getLiteral(String in){
return sheetMap.get(in);
}
}
79 changes: 79 additions & 0 deletions src/tdd/testSheet.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
package tdd;

import static org.junit.Assert.*;

import org.junit.Test;

public class testSheet {

@Test
public void testThatCellsAreEmptyByDefault() {
Sheet sheet = new Sheet();
assertEquals("", sheet.get("A1"));
assertEquals("", sheet.get("ZX347"));
}
@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));
}
@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"));
}
@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));
}
@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));
}
}
133 changes: 133 additions & 0 deletions src/voogasalad/DisplayScroller.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
package voogasalad;

import java.util.List;
import java.util.stream.Collectors;
import javafx.scene.Node;

/**
* DisplayScroller provides public methods that choose Nodes to display
* in a visible frame
*
* @author Hunter Lee
*
*/
public class DisplayScroller {

private int myScreenSize;
private int myAdjustFactor;
private int myConstantScrollCenter;

/**
* Default constructor that sets the screen size to be used
* in the class and myAdjustFactor which is defined to be
* half of the screen size
*
* @param screensize
*/
public DisplayScroller(int screensize) {

myScreenSize = screensize;
myAdjustFactor = screensize / 2;
myConstantScrollCenter = 0;

}


/**
* Takes in the raw list of all Nodes in the game and mainCharLocation
* returns a new list of Nodes to be displayed in GameDisplay
*
* @param allNodes, rightEdgeLocation
* @return
* @deprecated Generic scroll structure for reference
*/
@Deprecated
public <E> List<Node> scroll(List<E> allNodes, int mainCharLocation) {

// BoundingBox myBoundingBox = new
// List<Node> nodesToDisplay = allNodes.stream()
// .map(n -> (Node) n)
// .filter(n -> n.getL)
//
//
//
// allNodes.forEach(Node node -> {
// if ())
// });
//
//
// List<Entry> updatedEntries =
// entryList.stream()
// .peek(e -> e.setTempId(tempId))
// .collect (Collectors.toList());
//
// return nodesToDisplay;
return null;

}

/**
* Takes in the raw list of all Nodes in the game and Vector
* returns a new list of Nodes to be displayed in GameDisplay
* To be called at every time step
*
* Scrolling type: centered scroll
*
* @param allNodes, rightEdgeLocation
* @return
*/
public <E> List<Node> centerScroll(List<E> allNodes, double mainCharXPos) {

//double mainCharXPos = mainCharLocation.getX();
List<Node> nodesToDisplay;
if (mainCharXPos <= myAdjustFactor) {
nodesToDisplay = allNodes.stream()
.map(n -> (Node) n)
.filter(n -> n.getLayoutX() <= myScreenSize)
.collect(Collectors.toList());
}
else {
nodesToDisplay = allNodes.stream()
.map(n -> (Node) n)
.filter(n -> n.getLayoutX() <= mainCharXPos + myAdjustFactor)
.filter(n -> n.getLayoutX() >= mainCharXPos - myAdjustFactor)
.collect(Collectors.toList());
}
return nodesToDisplay;

}

/**
* Takes in the raw list of all Nodes in the game and Vector
* returns a new list of Nodes to be displayed in GameDisplay
* To be called at every time step
*
* Scrolling type: constant scrolling to the right
*
* @param allNodes, rightEdgeLocatioin
* @return
*/
public <E> List<Node> constantScroll(List<E> allNodes, int speed) {

List<Node> nodesToDisplay;
nodesToDisplay = centerScroll(allNodes, myConstantScrollCenter);
myConstantScrollCenter+=speed;
return nodesToDisplay;

}

/**
* @return the myScreenSize
*/
public int getScreenSize() {
return myScreenSize;
}

/**
* @param myScreenSize the myScreenSize to set
*/
public void setScreenSize(int myScreenSize) {
this.myScreenSize = myScreenSize;
}

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

import static org.junit.Assert.*;

import java.util.ArrayList;
import java.util.List;

import javafx.scene.Node;
import javafx.scene.image.ImageView;

import org.junit.Test;

public class testScroller {

@Test
public void testCenterScroll() {
List<Node> myList = new ArrayList<>();
int screensize = 600;

Node first = new ImageView();
first.setLayoutX(1000);
Node second = new ImageView();
second.setLayoutX(200);
Node third = new ImageView();
third.setLayoutX(500);

myList.add(first);
myList.add(second);
myList.add(third);

DisplayScroller scroll = new DisplayScroller(screensize);
List<Node> newList = scroll.centerScroll(myList, 100);

assertEquals(2, newList.size());
}

}