Skip to content

Commit

Permalink
Merge pull request #3 from cs361-W16/master
Browse files Browse the repository at this point in the history
update
  • Loading branch information
derekjwong95 committed Feb 19, 2016
2 parents c5db2a5 + aa06054 commit 0fcd18c
Show file tree
Hide file tree
Showing 5 changed files with 112 additions and 4 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
.idea/*
target/*
target/*
*.iml
Assignment1.iml
2 changes: 2 additions & 0 deletions src/main/java/controllers/ApplicationController.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ public Result dealPost(Context context, Game g) {
if(context.getRequestPath().contains("deal")){
g.dealFour();
}
g.error = false;
return Results.json().render(g);
}

Expand All @@ -60,6 +61,7 @@ public Result removeCard(Context context, @PathParam("column") int colNumber, Ga

public Result moveCard(Context context, @PathParam("columnFrom") int colFrom, @PathParam("columnTo") int colTo, Game g){
g.move(colFrom,colTo);
g.error = false;
return Results.json().render(g);
}

Expand Down
66 changes: 66 additions & 0 deletions src/main/java/models/SpanGame.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
package models;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Random;

/**
* Created by Michael on 2/18/2016.
*/
public class SpanGame extends Game{
public SpanGame(){
cols.add(new ArrayList<Card>());
cols.add(new ArrayList<Card>());
cols.add(new ArrayList<Card>());
cols.add(new ArrayList<Card>());
error = false;
}

public void buildDeck() {
for(int i = 1; i < 11; i++){
deck.add(new Card(i,Suit.Clubs));
deck.add(new Card(i,Suit.Hearts));
deck.add(new Card(i,Suit.Diamonds));
deck.add(new Card(i,Suit.Spades));
}
}

private boolean colHasCards(int colNumber) {
if(this.cols.get(colNumber).size()>0){
return true;
}
return false;
}

private Card getTopCard(int columnNumber) {
return this.cols.get(columnNumber).get(this.cols.get(columnNumber).size()-1);
}

/**
The remove looks good. Should work the same way as the english version of the game -Derek
*/
public void remove(int columnNumber) {
if(colHasCards(columnNumber)) {
Card c = getTopCard(columnNumber);
boolean removeCard = false;
for (int i = 0; i < 4; i++) {
if (i != columnNumber) {
if (colHasCards(i)) {
Card compare = getTopCard(i);
if (compare.getSuit() == c.getSuit()) {
if (compare.getValue() > c.getValue()) {
removeCard = true;
}
}
}
}
}
if (removeCard) {
this.cols.get(columnNumber).remove(this.cols.get(columnNumber).size() - 1);
error = false;
}
else
error = true;
}
}
}
4 changes: 1 addition & 3 deletions src/main/java/views/AcesUp/AcesUp.flt.html
Original file line number Diff line number Diff line change
Expand Up @@ -131,12 +131,10 @@ <h1>Aces Up</h1>
div.id = 'Error-div';
var text = document.createElement('h4');
text.style.color = "Red";
text.style.fontSize = "large";
text.style.bottom = "auto";
text.style.fontSize = "xx-large";
text.innerHTML = "Error: Invalid Move";
div.appendChild(text);
document.body.appendChild(div);
//alert("Error: Invalid Move";
}
else{
div.remove();
Expand Down
40 changes: 40 additions & 0 deletions src/test/java/models/testSpanGame.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package models;

import org.junit.Test;
import static org.junit.Assert.*;

/**
* Created by Michael on 2/18/2016.
*/
public class testSpanGame {
@Test
public void testSpanGameBuildDeck(){
SpanGame g = new SpanGame();
g.buildDeck();
assertEquals(40,g.deck.size());
}

@Test
public void testSpanGameCreation(){
SpanGame g = new SpanGame();
assertNotNull(g);
}

@Test
public void testSpanGameInit(){
SpanGame g = new SpanGame();
g.buildDeck();
g.shuffle();
assertEquals(40,g.deck.size());
assertNotEquals(2,g.deck.get(0).getValue());
}

@Test
public void testSpanGameRemove(){
Game g = new Game();
g.buildDeck();
g.customDeal(0,3,6,9);
g.remove(2);
assertEquals(0,g.cols.get(2).size());
}
}

0 comments on commit 0fcd18c

Please sign in to comment.