-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3 from cs361-W16/master
update
- Loading branch information
Showing
5 changed files
with
112 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,4 @@ | ||
.idea/* | ||
target/* | ||
target/* | ||
*.iml | ||
Assignment1.iml |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()); | ||
} | ||
} |