Deck managemement, snapping cards into partial decks and partial decks into cards, or partial decks into other partial decks. Snapping is great!

This commit is contained in:
2015-12-10 22:11:09 +00:00
parent 1f01d26d4a
commit 2f92fc6fdf
6 changed files with 129 additions and 60 deletions

View File

@@ -1,5 +1,5 @@
android { android {
buildToolsVersion "23.0.1" buildToolsVersion '23.0.2'
compileSdkVersion 21 compileSdkVersion 21
sourceSets { sourceSets {
main { main {

View File

@@ -4,7 +4,7 @@ buildscript {
maven { url "https://oss.sonatype.org/content/repositories/snapshots/" } maven { url "https://oss.sonatype.org/content/repositories/snapshots/" }
} }
dependencies { dependencies {
classpath 'com.android.tools.build:gradle:1.2.3' classpath 'com.android.tools.build:gradle:2.0.0-alpha1'
} }
} }

View File

@@ -21,6 +21,8 @@ public class Card {
private boolean faceUp; private boolean faceUp;
private boolean decked; private boolean decked;
private int deckId; private int deckId;
private boolean stacked;
private int stackid;
//private boolean onTable; //private boolean onTable;
//private float orientation; //private float orientation;
@@ -62,6 +64,8 @@ public class Card {
this.faceUp = false; this.faceUp = false;
this.decked = true; this.decked = true;
this.deckId = 1; this.deckId = 1;
this.stacked = false;
this.stackid = 0;
} }
@@ -166,4 +170,23 @@ public class Card {
public void setDeckId(int deckId) { public void setDeckId(int deckId) {
this.deckId = deckId; this.deckId = deckId;
} }
public void setStackid(int stackid) {
this.stackid = stackid;
}
public void setStacked(boolean stacked) {
this.stacked = stacked;
}
public int getStackid() {
return stackid;
}
public boolean isStacked() {
return stacked;
}
} }

View File

@@ -18,6 +18,7 @@ public class Deck {
private HashMap<Integer,Integer> drawOrder; private HashMap<Integer,Integer> drawOrder;
private int numberOfCards; private int numberOfCards;
private int deckCounter; private int deckCounter;
private int stackCounter;
public Deck(Texture texture) { public Deck(Texture texture) {
try { try {
@@ -37,6 +38,7 @@ public class Deck {
this.numberOfCards = 54; this.numberOfCards = 54;
this.deckCounter = 1; this.deckCounter = 1;
this.stackCounter = 0;
}catch (Exception e) }catch (Exception e)
{ {
@@ -190,6 +192,7 @@ public class Deck {
return cardResult; return cardResult;
} }
public Integer getTouchedCardIndex(float x, float y){ public Integer getTouchedCardIndex(float x, float y){
int i = numberOfCards - 1; int i = numberOfCards - 1;
@@ -204,6 +207,22 @@ public class Deck {
} }
return (Integer)i; return (Integer)i;
} }
public Integer getCardIndex(Card c){
int i = numberOfCards - 1;
boolean exit = false;
while (i >= 0 && !exit){
if (drawOrder.get(i) == c.getId()) {
exit = true;
}else{
i--;
}
}
return (Integer)i;
}
public Card getTouchedCard(float x, float y, int top){ public Card getTouchedCard(float x, float y, int top){
Card cardResult = null; Card cardResult = null;
@@ -221,59 +240,7 @@ public class Deck {
return cardResult; return cardResult;
} }
private void setCardDrawOrderOnTop(int index){
int i = index;
int next = 0;
int replace = drawOrder.get(index);;
while (i < numberOfCards){
if (i < numberOfCards-1) {
next = drawOrder.get(i + 1);
drawOrder.put(i,next);
i++;
}else{
drawOrder.put(i,replace);
i++;
}
}
}
//TODO Make sure it orders the cards up to the top
private void setCardDrawOrderOnTopSubDeck(int index, int last){
int i = index;
int next = 0;
int replace = drawOrder.get(index);
while (i < last){
if (i < last - 1) {
next = drawOrder.get(i + 1);
drawOrder.put(i,next);
i++;
}else{
drawOrder.put(i,replace);
i++;
}
}
}
private void setRandomCardDraw(ArrayList<Integer> subDeck){
ArrayList<Integer> originalOrder = (ArrayList<Integer>) subDeck.clone();
Collections.shuffle(subDeck);
Integer replace;
for (int i = 0; i < originalOrder.size(); i++){
replace = drawOrder.get(originalOrder.get(i));
drawOrder.put(originalOrder.get(i),drawOrder.get(subDeck.get(i)));
drawOrder.put(subDeck.get(i),replace);
}
}
public void shuffle(float x, float y){ public void shuffle(float x, float y){
//TODO Change this method, the top may not work when cards already unsorted
ArrayList<Integer> subDeck = new ArrayList<Integer>(); ArrayList<Integer> subDeck = new ArrayList<Integer>();
Card c; Card c;
@@ -374,6 +341,7 @@ public class Deck {
} }
} }
public Card getTouchedCardDifferentDeck(float x, float y, int deckiId){ public Card getTouchedCardDifferentDeck(float x, float y, int deckiId){
Card cardResult = null; Card cardResult = null;
int i = numberOfCards - 1; int i = numberOfCards - 1;
@@ -393,8 +361,6 @@ public class Deck {
return cardResult; return cardResult;
} }
public void autoDeckCard(float x, float y) { public void autoDeckCard(float x, float y) {
Card c = getTouchedCard(x, y); Card c = getTouchedCard(x, y);
Card below; Card below;
@@ -437,6 +403,32 @@ public class Deck {
} }
} }
public void autoStackCard(float x, float y){
}
public void toggleFaceUpDeck(Card c, boolean originalDecked, float x, float y){
int deckId = c.getDeckId();
int i = numberOfCards - 1;
int cardDeck;
boolean exit = false;
Card card;
if (!originalDecked){
c.toggleFaceUp();
}
else{
while (i >= 0 && !exit){
card = cards.get(drawOrder.get(i));
cardDeck = card.getDeckId();
if (cardDeck == deckId) {
card.toggleFaceUp();
}
i--;
}
}
}
public HashMap<Integer,Integer> getDrawOrder() { public HashMap<Integer,Integer> getDrawOrder() {
return drawOrder; return drawOrder;
} }
@@ -452,4 +444,56 @@ public class Deck {
public void setDeckCounter(int deckCounter) { public void setDeckCounter(int deckCounter) {
this.deckCounter = deckCounter; this.deckCounter = deckCounter;
} }
private void setCardDrawOrderOnTop(int index){
int i = index;
int next = 0;
int replace = drawOrder.get(index);;
while (i < numberOfCards){
if (i < numberOfCards-1) {
next = drawOrder.get(i + 1);
drawOrder.put(i,next);
i++;
}else{
drawOrder.put(i,replace);
i++;
}
}
}
private void setCardDrawOrderOnTopSubDeck(int index, int last){
int i = index;
int next = 0;
int replace = drawOrder.get(index);
while (i < last){
if (i < last - 1) {
next = drawOrder.get(i + 1);
drawOrder.put(i,next);
i++;
}else{
drawOrder.put(i,replace);
i++;
}
}
}
private void setRandomCardDraw(ArrayList<Integer> subDeck){
ArrayList<Integer> originalOrder = (ArrayList<Integer>) subDeck.clone();
Collections.shuffle(subDeck);
Integer replace;
for (int i = 0; i < originalOrder.size(); i++){
replace = drawOrder.get(originalOrder.get(i));
drawOrder.put(originalOrder.get(i),drawOrder.get(subDeck.get(i)));
drawOrder.put(subDeck.get(i),replace);
}
}
} }

View File

@@ -162,15 +162,17 @@ public class VirtuaCardsGameScreen implements Screen, InputProcessor {
@Override @Override
public boolean touchUp(int screenX, int screenY, int pointer, int button) { public boolean touchUp(int screenX, int screenY, int pointer, int button) {
Card c; Card c;
boolean decked = false;
Gdx.app.error("VirtuaCardsGameScreen", "TouchUp"); Gdx.app.error("VirtuaCardsGameScreen", "TouchUp");
if (dragCounter > 0) { if (dragCounter > 0) {
c = fullDeck.getTouchedDraggedCard(screenX, Gdx.graphics.getHeight() - screenY); c = fullDeck.getTouchedDraggedCard(screenX, Gdx.graphics.getHeight() - screenY);
if (c != null) { if (c != null) {
decked = c.isDecked();
fullDeck.autoDeckCard(screenX, Gdx.graphics.getHeight() - screenY); fullDeck.autoDeckCard(screenX, Gdx.graphics.getHeight() - screenY);
if (Point.pointListInsideDoubleTouchedDrag(dragBuffer, 75, 150)) { //flip card if (Point.pointListInsideDoubleTouchedDrag(dragBuffer, 75, 150)) { //flip card
//fullDeck.getCards().get(52).setFaceUp(true); fullDeck.toggleFaceUpDeck(c, decked, screenX, Gdx.graphics.getHeight() - screenY);
c.toggleFaceUp(); //c.toggleFaceUp();
} }
if (cardCounter > 0){ if (cardCounter > 0){

View File

@@ -1,6 +1,6 @@
#Sat Sep 21 13:08:26 CEST 2013 #Thu Dec 10 21:15:17 GMT 2015
distributionBase=GRADLE_USER_HOME distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists zipStorePath=wrapper/dists
distributionUrl=http\://services.gradle.org/distributions/gradle-2.4-all.zip distributionUrl=https\://services.gradle.org/distributions/gradle-2.8-all.zip