4 Commits
0.0.3 ... 0.0.6

8 changed files with 518 additions and 234 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

@@ -3,7 +3,6 @@ package checamon.games.virtuacards.android;
import android.annotation.TargetApi; import android.annotation.TargetApi;
import android.os.Build; import android.os.Build;
import android.os.Bundle; import android.os.Bundle;
import android.util.Log;
import android.view.View; import android.view.View;
import com.badlogic.gdx.backends.android.AndroidApplication; import com.badlogic.gdx.backends.android.AndroidApplication;
@@ -22,7 +21,6 @@ public class AndroidLauncher extends AndroidApplication {
} }
AndroidApplicationConfiguration config = new AndroidApplicationConfiguration(); AndroidApplicationConfiguration config = new AndroidApplicationConfiguration();
initialize(new VirtuaCards(),config); initialize(new VirtuaCards(),config);
Log.e("Error", "Error Test");
} }
@TargetApi(19) @TargetApi(19)
private void hideVirtualButtons() { private void hideVirtualButtons() {

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

@@ -19,6 +19,10 @@ public class Card {
private float sizeY; private float sizeY;
private int id; private int id;
private boolean faceUp; private boolean faceUp;
private boolean decked;
private int deckId;
private boolean stacked;
private int stackid;
//private boolean onTable; //private boolean onTable;
//private float orientation; //private float orientation;
@@ -58,24 +62,12 @@ public class Card {
this.backSprite.setPosition(position.getX(), position.getY()); this.backSprite.setPosition(position.getX(), position.getY());
this.id = id; this.id = id;
this.faceUp = false; this.faceUp = false;
this.decked = true;
this.deckId = 1;
this.stacked = false;
this.stackid = 0;
} }
/*
public void drawCardSprite(SpriteBatch batch,Point point, float sizeX, float sizeY){
this.cardSprite.setPosition(point.getX(), point.getY());
this.cardSprite.setSize(sizeX, sizeY);
this.cardSprite.draw(batch);
//this.position = point;
}
public void drawCardSprite(SpriteBatch batch, float sizeX, float sizeY){
this.cardSprite.setPosition(this.position.getX(), this.position.getY());
this.cardSprite.setSize(sizeX, sizeY);
this.cardSprite.draw(batch);
//this.sizeX = sizeX;
//this.sizeY = sizeY;
}
*/
public void drawCardSprite(SpriteBatch batch){ public void drawCardSprite(SpriteBatch batch){
//this.cardSprite.setCenter(this.cardSprite.getX() + 1, this.cardSprite.getY() + 1); //this.cardSprite.setCenter(this.cardSprite.getX() + 1, this.cardSprite.getY() + 1);
@@ -162,4 +154,39 @@ public class Card {
public void setBackSprite(Sprite backSprite) { public void setBackSprite(Sprite backSprite) {
this.backSprite = backSprite; this.backSprite = backSprite;
} }
public boolean isDecked() {
return decked;
}
public void setDecked(boolean decked) {
this.decked = decked;
}
public int getDeckId() {
return deckId;
}
public void setDeckId(int 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

@@ -3,13 +3,13 @@ package checamon.games.virtuacards;
import com.badlogic.gdx.graphics.Texture; import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.SpriteBatch; import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.graphics.g2d.TextureRegion; import com.badlogic.gdx.graphics.g2d.TextureRegion;
import com.badlogic.gdx.math.Rectangle;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
import java.util.HashMap; import java.util.HashMap;
/** /**
* Created by angelcheca on 17/11/15. * Created by angelcheca on 17/11/15.
*/ */
@@ -17,7 +17,8 @@ public class Deck {
private ArrayList<Card> cards; private ArrayList<Card> cards;
private HashMap<Integer,Integer> drawOrder; private HashMap<Integer,Integer> drawOrder;
private int numberOfCards; private int numberOfCards;
//private ArrayList<Deck> subdecks; private int deckCounter;
private int stackCounter;
public Deck(Texture texture) { public Deck(Texture texture) {
try { try {
@@ -36,6 +37,8 @@ public class Deck {
} }
this.numberOfCards = 54; this.numberOfCards = 54;
this.deckCounter = 1;
this.stackCounter = 0;
}catch (Exception e) }catch (Exception e)
{ {
@@ -61,7 +64,7 @@ public class Deck {
public void drawCards(SpriteBatch batch) { public void drawCards(SpriteBatch batch) {
int i = 0; int i = 0;
while (i <= numberOfCards){ while (i < numberOfCards){
if (drawOrder.get(i) > -1) if (drawOrder.get(i) > -1)
cards.get(drawOrder.get(i)).drawCardSprite(batch); cards.get(drawOrder.get(i)).drawCardSprite(batch);
i++; i++;
@@ -74,7 +77,7 @@ public class Deck {
boolean result = false; boolean result = false;
int i = 0; int i = 0;
while (i <= numberOfCards && !exit){ while (i < numberOfCards && !exit){
if (drawOrder.get(i) > -1){ if (drawOrder.get(i) > -1){
if (cards.get(drawOrder.get(i)).isTouched(x, y)) { if (cards.get(drawOrder.get(i)).isTouched(x, y)) {
result = true; result = true;
@@ -92,7 +95,7 @@ public class Deck {
boolean result = false; boolean result = false;
int i = 0; int i = 0;
while (i <= numberOfCards && !exit){ while (i < numberOfCards && !exit){
if (drawOrder.get(i) > -1){ if (drawOrder.get(i) > -1){
if (cards.get(drawOrder.get(i)).isTouchedDragged(x, y)) { if (cards.get(drawOrder.get(i)).isTouchedDragged(x, y)) {
result = true; result = true;
@@ -104,10 +107,54 @@ public class Deck {
return result; return result;
} }
public boolean isCardTouchedTopOfDeck(float x, float y){
boolean exit = false;
boolean result = false;
int touchCounter = 0;
int i = 0;
while (i < numberOfCards && !exit){
if (drawOrder.get(i) > -1){
if (cards.get(drawOrder.get(i)).isTouched(x, y)) {
if (touchCounter == 0)
touchCounter++;
else if (touchCounter == 1) {
exit = true;
result = true;
}
}
}
i++;
}
return result;
}
public boolean isCardTouchedDraggedTopOfDeck(float x, float y){
boolean exit = false;
boolean result = false;
int touchCounter = 0;
int i = 0;
while (i < numberOfCards && !exit){
if (drawOrder.get(i) > -1){
if (cards.get(drawOrder.get(i)).isTouchedDragged(x, y)) {
if (touchCounter == 0)
touchCounter++;
else if (touchCounter == 1) {
exit = true;
result = true;
}
}
}
i++;
}
return result;
}
public Card getTouchedDraggedCard(float x, float y){ public Card getTouchedDraggedCard(float x, float y){
Card cardResult = null; Card cardResult = null;
int i = numberOfCards; int i = numberOfCards - 1;
boolean exit = false; boolean exit = false;
while (i >= 0 && !exit){ while (i >= 0 && !exit){
@@ -118,7 +165,9 @@ public class Deck {
i--; i--;
} }
} }
if (i < numberOfCards)
//TODO Change this to not move to the top until is sure no other cards need to move
if (i >= 0 && i < numberOfCards - 1)
setCardDrawOrderOnTop(i); setCardDrawOrderOnTop(i);
return cardResult; return cardResult;
} }
@@ -126,7 +175,7 @@ public class Deck {
public Card getTouchedCard(float x, float y){ public Card getTouchedCard(float x, float y){
Card cardResult = null; Card cardResult = null;
int i = numberOfCards; int i = numberOfCards - 1;
boolean exit = false; boolean exit = false;
while (i >= 0 && !exit){ while (i >= 0 && !exit){
@@ -137,12 +186,43 @@ public class Deck {
i--; i--;
} }
} }
if (i < numberOfCards) //TODO Change this to not move to the top until is sure no other cards need to move
if (i >= 0 && i < numberOfCards - 1)
setCardDrawOrderOnTop(i); setCardDrawOrderOnTop(i);
return cardResult; return cardResult;
} }
public Integer getTouchedCardIndex(float x, float y){
int i = numberOfCards - 1;
boolean exit = false;
while (i >= 0 && !exit){
if (drawOrder.get(i) > -1 && cards.get(drawOrder.get(i)).isTouched(x, y)) {
exit = true;
}else{
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;
@@ -160,14 +240,238 @@ public class Deck {
return cardResult; return cardResult;
} }
public void shuffle(float x, float y){
ArrayList<Integer> subDeck = new ArrayList<Integer>();
Card c;
int i = numberOfCards-1;
int index = 0;
boolean exit = false;
while (i >= 0 && !exit){
c = this.getTouchedCard(x, y, i);
if (c == null)
exit = true;
else{
subDeck.add(index,c.getId());
index++;
i--;
}
}
if (!subDeck.isEmpty()){
setRandomCardDraw(subDeck);
}
}
public void moveDeckTouched(float x, float y){
Card card;
int deckId = -1;
int cardDeck = -1;
int lastIndex = -1;
//Move all cards in the deck
int i = getTouchedCardIndex(x,y);
lastIndex = i;
while (i >= 0){
card = cards.get(drawOrder.get(i));
cardDeck = card.getDeckId();
if (cardDeck == deckId) {
card.setCenter(new Point(x, y));
setCardDrawOrderOnTopSubDeck(i, lastIndex);
lastIndex--;
}
else if (deckId == -1){
if (drawOrder.get(i) > -1 && card.isTouched(x, y)) {
deckId = card.getDeckId();
card.setCenter(new Point(x, y));
}
}
i--;
}
}
public void moveDeckTouchedDragged(float x, float y){
Card card;
int deckId = -1;
int cardDeck = -1;
int lastIndex = -1;
//Move all cards in the deck
int i = getTouchedCardIndex(x,y);
lastIndex = i;
while (i >= 0){
card = cards.get(drawOrder.get(i));
cardDeck = card.getDeckId();
if (cardDeck == deckId) {
card.setCenter(new Point(x, y));
setCardDrawOrderOnTopSubDeck(i, lastIndex);
lastIndex--;
}
else if (deckId == -1){
if (drawOrder.get(i) > -1 && card.isTouchedDragged(x, y)) {
deckId = card.getDeckId();
card.setCenter(new Point(x, y));
}
}
i--;
}
}
public void setDeckPosition(int belowDeckId, int aboveDeckId, float x, float y){
Card card;
int cardDeck = -1;
//Move all cards in the deck
int i = numberOfCards - 1;
while (i >= 0){
card = cards.get(drawOrder.get(i));
cardDeck = card.getDeckId();
if (cardDeck == aboveDeckId) {
card.setPosition(new Point(x, y));
card.setDeckId(belowDeckId);
}
i--;
}
}
public Card getTouchedCardDifferentDeck(float x, float y, int deckiId){
Card cardResult = null;
int i = numberOfCards - 1;
boolean exit = false;
while (i >= 0 && !exit){
cardResult = cards.get(drawOrder.get(i));
if (drawOrder.get(i) > -1 && cardResult.isTouched(x, y) && cardResult.getDeckId() != deckiId) {
exit = true;
}else{
i--;
}
}
if (!exit)
cardResult = null;
return cardResult;
}
public void autoDeckCard(float x, float y) {
Card c = getTouchedCard(x, y);
Card below;
if (!c.isDecked()) {
below = getTouchedCard(x, y, numberOfCards - 2);
} else {
below = getTouchedCardDifferentDeck(x, y, c.getDeckId());
}
// Detect if overlapping enough to deck automatically
// by default cards are 150 x 190
if (below != null && !c.isDecked()) {
if (((c.getCardSprite().getX() <= below.getCardSprite().getX() + 35) && (c.getCardSprite().getX() >= below.getCardSprite().getX() - 35)) &&
((c.getCardSprite().getY() <= below.getCardSprite().getY() + 35) && (c.getCardSprite().getY() >= below.getCardSprite().getY() - 35))) {
Rectangle r = below.getCardRectangle();
c.setPosition(new Point(r.getX(), r.getY()));
c.setDecked(true);
if (below.getDeckId() == 0) {
deckCounter++;
below.setDecked(true);
below.setDeckId(deckCounter);
c.setDeckId(deckCounter);
} else {
c.setDeckId(below.getDeckId());
}
}
} else if (below != null && c.isDecked()) {
if (((c.getCardSprite().getX() <= below.getCardSprite().getX() + 35) && (c.getCardSprite().getX() >= below.getCardSprite().getX() - 35)) &&
((c.getCardSprite().getY() <= below.getCardSprite().getY() + 35) && (c.getCardSprite().getY() >= below.getCardSprite().getY() - 35))) {
Rectangle r = below.getCardRectangle();
if (below.getDeckId() == 0) {
below.setDecked(true);
below.setDeckId(c.getDeckId());
setDeckPosition(c.getDeckId(), c.getDeckId(), r.getX(), r.getY());
} else {
setDeckPosition(below.getDeckId(), c.getDeckId(), r.getX(), r.getY());
}
}
//TODO resetDeckIds(); complex to compute... not worth it
}
}
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() {
return drawOrder;
}
public int getNumberOfCards() {
return numberOfCards;
}
public int getDeckCounter() {
return deckCounter;
}
public void setDeckCounter(int deckCounter) {
this.deckCounter = deckCounter;
}
private void setCardDrawOrderOnTop(int index){ private void setCardDrawOrderOnTop(int index){
int i = index; int i = index;
int next = 0; int next = 0;
int replace = drawOrder.get(index);; int replace = drawOrder.get(index);;
while (i <= numberOfCards){ while (i < numberOfCards){
if (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); next = drawOrder.get(i + 1);
drawOrder.put(i,next); drawOrder.put(i,next);
i++; i++;
@@ -187,43 +491,9 @@ public class Deck {
for (int i = 0; i < originalOrder.size(); i++){ for (int i = 0; i < originalOrder.size(); i++){
replace = drawOrder.get(originalOrder.get(i)); replace = drawOrder.get(originalOrder.get(i));
drawOrder.put(originalOrder.get(i),drawOrder.get(subDeck.get(i))); drawOrder.put(originalOrder.get(i),drawOrder.get(subDeck.get(i)));
if (i < originalOrder.size() - 1) drawOrder.put(subDeck.get(i),replace);
drawOrder.put(subDeck.get(i),replace);
} }
} }
public void shuffle(float x, float y){
ArrayList<Integer> subDeck = new ArrayList<Integer>();
Card c;
int top = numberOfCards-1;
int i = numberOfCards-1;
int index = 0;
boolean exit = false;
while (i >= 0 && !exit){
c = this.getTouchedCard(x,y,top);
if (c == null)
exit = true;
else{
subDeck.add(index,c.getId());
top = c.getId() - 1;
index++;
i--;
}
}
if (!subDeck.isEmpty()){
setRandomCardDraw(subDeck);
}
}
public HashMap<Integer,Integer> getDrawOrder() {
return drawOrder;
}
public int getNumberOfCards() {
return numberOfCards;
}
} }

View File

@@ -7,6 +7,7 @@ import com.badlogic.gdx.InputProcessor;
import com.badlogic.gdx.Screen; import com.badlogic.gdx.Screen;
import com.badlogic.gdx.graphics.GL20; import com.badlogic.gdx.graphics.GL20;
import com.badlogic.gdx.graphics.Texture; import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.math.Rectangle;
import java.util.ArrayList; import java.util.ArrayList;
@@ -15,20 +16,24 @@ public class VirtuaCardsGameScreen implements Screen, InputProcessor {
private int dragCounter; private int dragCounter;
private int cardCounter; private int cardCounter;
private ArrayList<Point> dragBuffer; private ArrayList<Point> dragBuffer;
private ArrayList<Integer> cardsTouched;
private VirtuaCards game; private VirtuaCards game;
private Deck fullDeck; private Deck fullDeck;
private int dragTriggered;
private Rectangle lastTouch;
public VirtuaCardsGameScreen (VirtuaCards g) { public VirtuaCardsGameScreen (VirtuaCards g) {
game = g; game = g;
dragBuffer = new ArrayList<Point>(); dragBuffer = new ArrayList<Point>();
cardsTouched = new ArrayList<Integer>();
dragCounter = 0; dragCounter = 0;
cardCounter = 0; cardCounter = 0;
dragTriggered = 0;
lastTouch = new Rectangle(0f, 0f, 0f, 0f);
Gdx.input.setInputProcessor(this);
Gdx.input.setCatchBackKey(true); Gdx.input.setCatchBackKey(true);
//Gdx.app.setLogLevel(Application.LOG_ERROR);
fullDeck = new Deck(new Texture("full_french_deck.png")); fullDeck = new Deck(new Texture("full_french_deck.png"));
@@ -38,7 +43,7 @@ public class VirtuaCardsGameScreen implements Screen, InputProcessor {
//fullDeck.getCards().get(52).setPosition(new Point(300f,100f)); //fullDeck.getCards().get(52).setPosition(new Point(300f,100f));
fullDeck.shuffle(110f, 110f); //fullDeck.shuffle(110f, 110f);
} }
@@ -46,6 +51,7 @@ public class VirtuaCardsGameScreen implements Screen, InputProcessor {
public void render(float delta) { public void render(float delta) {
Gdx.gl.glClearColor(0.2f, 0.6f, 0.2f, 0); Gdx.gl.glClearColor(0.2f, 0.6f, 0.2f, 0);
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT); Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
Gdx.input.setInputProcessor(this);
game.batch.begin(); game.batch.begin();
@@ -55,187 +61,194 @@ public class VirtuaCardsGameScreen implements Screen, InputProcessor {
} }
/**
* Called when a finger or the mouse was dragged.
*
* @param screenX
* @param screenY
* @param pointer the pointer for the event. @return whether the input was processed
*/
@Override
public boolean touchDragged(int screenX, int screenY, int pointer) {
//deck
if (dragCounter == 0) {
if (fullDeck.isTouchingCard(screenX, Gdx.graphics.getHeight() - screenY)) {
fullDeck.getTouchedCard(screenX, Gdx.graphics.getHeight() - screenY).setCenter(new Point(screenX, Gdx.graphics.getHeight() - screenY));
dragBuffer.add(dragCounter, new Point(screenX, Gdx.graphics.getHeight() - screenY)); @Override
dragCounter++; public boolean touchDragged(int screenX, int screenY, int pointer) {
} Card c;
} boolean ignore = false;
else if (fullDeck.isTouchingDraggedCard(screenX, Gdx.graphics.getHeight() - screenY)) { dragTriggered++;
fullDeck.getTouchedDraggedCard(screenX, Gdx.graphics.getHeight() - screenY).setCenter(new Point(screenX, Gdx.graphics.getHeight() - screenY)); Gdx.app.error("VirtuaCardsGameScreen", "TouchDragged");
if (dragTriggered < 5){
ignore = true;
}else if (dragCounter == 0) {
if (fullDeck.isTouchingCard(screenX, Gdx.graphics.getHeight() - screenY)) {
c = fullDeck.getTouchedCard(screenX, Gdx.graphics.getHeight() - screenY);
if (cardCounter == 2) { // Move deck of cards
if (cardsTouched.get(0).equals(cardsTouched.get(1)) && c.isDecked()) {
fullDeck.moveDeckTouched(screenX, Gdx.graphics.getHeight() - screenY);
} else {
c.setCenter(new Point(screenX, Gdx.graphics.getHeight() - screenY));
c.setDecked(false);
c.setDeckId(0);
}
} else {
c.setCenter(new Point(screenX, Gdx.graphics.getHeight() - screenY));
c.setDecked(false);
c.setDeckId(0);
}
dragBuffer.add(dragCounter, new Point(screenX, Gdx.graphics.getHeight() - screenY)); dragBuffer.add(dragCounter, new Point(screenX, Gdx.graphics.getHeight() - screenY));
dragCounter++; dragCounter++;
}
}
else if (fullDeck.isTouchingDraggedCard(screenX, Gdx.graphics.getHeight() - screenY)) {
c = fullDeck.getTouchedDraggedCard(screenX, Gdx.graphics.getHeight() - screenY);
if (cardCounter == 2) { // Move deck of cards
if (cardsTouched.get(0).equals(cardsTouched.get(1)) && c.isDecked()) {
fullDeck.moveDeckTouchedDragged(screenX, Gdx.graphics.getHeight() - screenY);
} else {
c.setCenter(new Point(screenX, Gdx.graphics.getHeight() - screenY));
c.setDecked(false);
c.setDeckId(0);
}
}
else{
c.setCenter(new Point(screenX, Gdx.graphics.getHeight() - screenY));
c.setDecked(false);
c.setDeckId(0);
}
} dragBuffer.add(dragCounter, new Point(screenX, Gdx.graphics.getHeight() - screenY));
else { dragCounter++;
dragCounter = 0; }
dragBuffer.clear(); else {
} dragCounter = 0;
cardCounter = 0; dragBuffer.clear();
return true; cardsTouched.clear();
} cardCounter = 0;
}
return ignore;
}
@Override
/** public boolean keyDown(int keycode) {
* Called when a key was pressed
*
*/
@Override
public boolean keyDown(int keycode) {
if(keycode == Input.Keys.BACK) { if(keycode == Input.Keys.BACK) {
game.setScreen(new VirtuaCardsMainMenu(game)); game.setScreen(new VirtuaCardsMainMenu(game));
dispose(); dispose();
} }
return true; return true;
} }
/** @Override
* Called when a key was released public boolean keyUp(int keycode) {
* return false;
*/ }
@Override
public boolean keyUp(int keycode) {
return false;
}
/** @Override
* Called when a key was typed public boolean keyTyped(char character) {
* return false;
* @param character The character }
* @return whether the input was processed
*/
@Override
public boolean keyTyped(char character) {
return false;
}
/** @Override
* public boolean touchDown(int screenX, int screenY, int pointer, int button) {
* @param screenX The x coordinate, origin is in the upper left corner Card c;
* @param screenY The y coordinate, origin is in the upper left corner dragCounter = 0;
* @param pointer the pointer for the event. dragBuffer.clear();
* @param button the button Gdx.app.error("VirtuaCardsGameScreen", "TouchDown");
* @return whether the input was processed
*/
@Override
public boolean touchDown(int screenX, int screenY, int pointer, int button) {
dragCounter = 0; c = fullDeck.getTouchedCard(screenX, Gdx.graphics.getHeight() - screenY);
dragBuffer.clear(); if (c != null){
cardCounter = 1; cardsTouched.add(cardCounter,c.getId());
cardCounter++;
lastTouch = c.getCardRectangle();
}else{
cardsTouched.clear();
cardCounter = 0;
}
return true;
}
@Override
public boolean touchUp(int screenX, int screenY, int pointer, int button) {
Card c;
boolean decked = false;
Gdx.app.error("VirtuaCardsGameScreen", "TouchUp");
if (dragCounter > 0) {
c = fullDeck.getTouchedDraggedCard(screenX, Gdx.graphics.getHeight() - screenY);
if (c != null) {
decked = c.isDecked();
fullDeck.autoDeckCard(screenX, Gdx.graphics.getHeight() - screenY);
if (Point.pointListInsideDoubleTouchedDrag(dragBuffer, 75, 150)) { //flip card
fullDeck.toggleFaceUpDeck(c, decked, screenX, Gdx.graphics.getHeight() - screenY);
//c.toggleFaceUp();
}
if (cardCounter > 0){
cardCounter = 0;
cardsTouched.clear();
}
}
}else{
c = fullDeck.getTouchedCard(screenX, Gdx.graphics.getHeight() - screenY);
if (c != null){
if (cardCounter == 3){ // three touches on the same card shuffles the sub deck
if (cardsTouched.get(0) == cardsTouched.get(1) && cardsTouched.get(1) == cardsTouched.get(2)){
fullDeck.shuffle(screenX, Gdx.graphics.getHeight() - screenY);
}
cardCounter = 0;
cardsTouched.clear();
}
}
}
if (cardCounter == 3){
cardCounter = 0;
cardsTouched.clear();
}
if (dragCounter > 0){
dragCounter = 0;
dragBuffer.clear();
}
if (dragTriggered > 0)
dragTriggered = 0;
return true;
}
@Override
public boolean mouseMoved(int screenX, int screenY) {
return false;
}
return true; @Override
}
/**
*
* @param screenX
* @param screenY
* @param pointer the pointer for the event.
* @param button the button @return whether the input was processed
*/
@Override
public boolean touchUp(int screenX, int screenY, int pointer, int button) {
if (Point.pointListInsideDoubleTouchedDrag(dragBuffer, 75, 150) && dragCounter > 0) { //flip card
//fullDeck.getCards().get(52).setFaceUp(true);
fullDeck.getTouchedDraggedCard(screenX, Gdx.graphics.getHeight() - screenY).toggleFaceUp();
}
/*else// if (cardCounter == 1)
{
fullDeck.shuffle(screenX, Gdx.graphics.getHeight() - screenY);
}*/
dragCounter = 0;
dragBuffer.clear();
cardCounter = 0;
return true;
}
/**
* Called when the mouse was moved without any buttons being pressed. Will not be called on iOS.
*
* @param screenX
* @param screenY
* @return whether the input was processed
*/
@Override
public boolean mouseMoved(int screenX, int screenY) {
return false;
}
/**
* Called when the mouse wheel was scrolled. Will not be called on iOS.
*
* @param amount the scroll amount, -1 or 1 depending on the direction the wheel was scrolled.
* @return whether the input was processed.
*/
@Override
public boolean scrolled(int amount) { public boolean scrolled(int amount) {
return false; return false;
} }
/**
* Called when this screen becomes the current screen for a {@link Game}.
*/
@Override @Override
public void show() { public void show() {
} }
/**
* @param width
* @param height
* @see ApplicationListener#resize(int, int)
*/
@Override @Override
public void resize(int width, int height) { public void resize(int width, int height) {
} }
/**
* @see ApplicationListener#pause()
*/
@Override @Override
public void pause() { public void pause() {
} }
/**
* @see ApplicationListener#resume()
*/
@Override @Override
public void resume() { public void resume() {
} }
/**
* Called when this screen is no longer the current screen for a {@link Game}.
*/
@Override @Override
public void hide() { public void hide() {
} }
/**
* Called when this screen should release all resources.
*/
@Override @Override
public void dispose() { public void dispose() {
} }
} }

View File

@@ -9,19 +9,15 @@ import com.badlogic.gdx.graphics.Pixmap;
import com.badlogic.gdx.graphics.Texture; import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.BitmapFont; import com.badlogic.gdx.graphics.g2d.BitmapFont;
import com.badlogic.gdx.math.Rectangle; import com.badlogic.gdx.math.Rectangle;
import com.badlogic.gdx.scenes.scene2d.Stage;
import com.badlogic.gdx.scenes.scene2d.Touchable;
import com.badlogic.gdx.scenes.scene2d.ui.Skin; import com.badlogic.gdx.scenes.scene2d.ui.Skin;
import com.badlogic.gdx.scenes.scene2d.ui.TextButton; import com.badlogic.gdx.scenes.scene2d.ui.TextButton;
import com.badlogic.gdx.scenes.scene2d.ui.TextButton.TextButtonStyle; import com.badlogic.gdx.scenes.scene2d.ui.TextButton.TextButtonStyle;
import com.badlogic.gdx.scenes.scene2d.utils.ClickListener;
/** /**
* Created by angelcheca on 28/11/15. * Created by angelcheca on 28/11/15.
*/ */
public class VirtuaCardsMainMenu implements Screen, InputProcessor { public class VirtuaCardsMainMenu implements Screen, InputProcessor {
final VirtuaCards game; final VirtuaCards game;
private boolean exitScreen;
private Skin skin; private Skin skin;
private TextButton playButton; private TextButton playButton;
@@ -31,12 +27,10 @@ public class VirtuaCardsMainMenu implements Screen, InputProcessor {
public VirtuaCardsMainMenu (final VirtuaCards g){ public VirtuaCardsMainMenu (final VirtuaCards g){
game = g; game = g;
exitScreen = false;
skin = new Skin(); skin = new Skin();
Gdx.input.setInputProcessor(this); Gdx.input.setInputProcessor(this);
Pixmap pixmap = new Pixmap(400, 100, Pixmap.Format.RGBA8888); Pixmap pixmap = new Pixmap(400, 100, Pixmap.Format.RGBA8888);
pixmap.setColor(Color.GREEN); pixmap.setColor(Color.GREEN);
pixmap.fill(); pixmap.fill();
@@ -99,47 +93,29 @@ public class VirtuaCardsMainMenu implements Screen, InputProcessor {
} }
game.batch.end(); game.batch.end();
if (exitScreen)
dispose();
} }
/**
* @param width
* @param height
* @see ApplicationListener#resize(int, int)
*/
@Override @Override
public void resize(int width, int height) { public void resize(int width, int height) {
} }
/**
* @see ApplicationListener#pause()
*/
@Override @Override
public void pause() { public void pause() {
} }
/**
* @see ApplicationListener#resume()
*/
@Override @Override
public void resume() { public void resume() {
} }
/**
* Called when this screen is no longer the current screen for a {@link Game}.
*/
@Override @Override
public void hide() { public void hide() {
} }
/**
* Called when this screen should release all resources.
*/
@Override @Override
public void dispose() { public void dispose() {
} }
@@ -172,7 +148,7 @@ public class VirtuaCardsMainMenu implements Screen, InputProcessor {
if (buttonClicked) // play button clicked if (buttonClicked) // play button clicked
{ {
game.setScreen(new VirtuaCardsGameScreen(game)); game.setScreen(new VirtuaCardsGameScreen(game));
exitScreen = true; dispose();
} }
else { // exit button clicked else { // exit button clicked
r.set(exitButton.getX(), exitButton.getY(), exitButton.getWidth(), exitButton.getHeight()); r.set(exitButton.getX(), exitButton.getY(), exitButton.getWidth(), exitButton.getHeight());

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