Compare commits
3 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| c76a2fba08 | |||
| c6298f9829 | |||
| bbe2ae3be5 |
@@ -1,7 +1,10 @@
|
|||||||
package checamon.games.virtuacards.android;
|
package checamon.games.virtuacards.android;
|
||||||
|
|
||||||
|
import android.annotation.TargetApi;
|
||||||
|
import android.os.Build;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
import android.view.View;
|
||||||
|
|
||||||
import com.badlogic.gdx.backends.android.AndroidApplication;
|
import com.badlogic.gdx.backends.android.AndroidApplication;
|
||||||
import com.badlogic.gdx.backends.android.AndroidApplicationConfiguration;
|
import com.badlogic.gdx.backends.android.AndroidApplicationConfiguration;
|
||||||
@@ -12,9 +15,33 @@ public class AndroidLauncher extends AndroidApplication {
|
|||||||
@Override
|
@Override
|
||||||
protected void onCreate (Bundle savedInstanceState) {
|
protected void onCreate (Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
|
|
||||||
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
|
||||||
|
hideVirtualButtons();
|
||||||
|
}
|
||||||
AndroidApplicationConfiguration config = new AndroidApplicationConfiguration();
|
AndroidApplicationConfiguration config = new AndroidApplicationConfiguration();
|
||||||
initialize(new VirtuaCards(), config);
|
initialize(new VirtuaCards(), config);
|
||||||
|
|
||||||
Log.e("Error", "Error Test");
|
Log.e("Error", "Error Test");
|
||||||
}
|
}
|
||||||
|
@TargetApi(19)
|
||||||
|
private void hideVirtualButtons() {
|
||||||
|
getWindow().getDecorView().setSystemUiVisibility(
|
||||||
|
View.SYSTEM_UI_FLAG_LAYOUT_STABLE
|
||||||
|
| View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
|
||||||
|
| View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
|
||||||
|
| View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY
|
||||||
|
| View.SYSTEM_UI_FLAG_FULLSCREEN
|
||||||
|
| View.SYSTEM_UI_FLAG_HIDE_NAVIGATION);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* @Override
|
||||||
|
public void onWindowFocusChanged(boolean hasFocus) {
|
||||||
|
super.onWindowFocusChanged(hasFocus);
|
||||||
|
if (hasFocus) {
|
||||||
|
// In KITKAT (4.4) and next releases, hide the virtual buttons
|
||||||
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
|
||||||
|
hideVirtualButtons();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}*/
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,9 +14,11 @@ public class Card {
|
|||||||
private TextureRegion card;
|
private TextureRegion card;
|
||||||
private Point position;
|
private Point position;
|
||||||
private Sprite cardSprite;
|
private Sprite cardSprite;
|
||||||
|
private Sprite backSprite;
|
||||||
private float sizeX;
|
private float sizeX;
|
||||||
private float sizeY;
|
private float sizeY;
|
||||||
//private boolean faceUp;
|
private int id;
|
||||||
|
private boolean faceUp;
|
||||||
//private boolean onTable;
|
//private boolean onTable;
|
||||||
//private float orientation;
|
//private float orientation;
|
||||||
|
|
||||||
@@ -42,17 +44,23 @@ public class Card {
|
|||||||
this.position = new Point(100f, 100f);
|
this.position = new Point(100f, 100f);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Card(TextureRegion region) {
|
public Card(TextureRegion region, int id, TextureRegion backRegion) {
|
||||||
|
|
||||||
this.card = region;
|
this.card = region;
|
||||||
this.cardSprite = new Sprite(region);
|
this.sizeX = 150f;
|
||||||
this.sizeX = 100f;
|
this.sizeY = 190f;
|
||||||
this.sizeY = 130f;
|
|
||||||
this.cardSprite.setSize(sizeX, sizeY);
|
|
||||||
this.position = new Point(100f, 100f);
|
this.position = new Point(100f, 100f);
|
||||||
|
this.cardSprite = new Sprite(region);
|
||||||
|
this.cardSprite.setSize(sizeX, sizeY);
|
||||||
this.cardSprite.setPosition(position.getX(), position.getY());
|
this.cardSprite.setPosition(position.getX(), position.getY());
|
||||||
|
this.backSprite = new Sprite(backRegion);
|
||||||
|
this.backSprite.setSize(sizeX, sizeY);
|
||||||
|
this.backSprite.setPosition(position.getX(), position.getY());
|
||||||
|
this.id = id;
|
||||||
|
this.faceUp = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
public void drawCardSprite(SpriteBatch batch,Point point, float sizeX, float sizeY){
|
public void drawCardSprite(SpriteBatch batch,Point point, float sizeX, float sizeY){
|
||||||
this.cardSprite.setPosition(point.getX(), point.getY());
|
this.cardSprite.setPosition(point.getX(), point.getY());
|
||||||
this.cardSprite.setSize(sizeX, sizeY);
|
this.cardSprite.setSize(sizeX, sizeY);
|
||||||
@@ -67,10 +75,14 @@ public class Card {
|
|||||||
//this.sizeX = sizeX;
|
//this.sizeX = sizeX;
|
||||||
//this.sizeY = sizeY;
|
//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);
|
||||||
|
if (faceUp)
|
||||||
this.cardSprite.draw(batch);
|
this.cardSprite.draw(batch);
|
||||||
|
else
|
||||||
|
this.backSprite.draw(batch);
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isTouched(float x, float y){
|
public boolean isTouched(float x, float y){
|
||||||
@@ -89,7 +101,12 @@ public class Card {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public Rectangle getCardRectangle(){
|
public Rectangle getCardRectangle(){
|
||||||
return this.cardSprite.getBoundingRectangle();
|
Rectangle r;
|
||||||
|
if (faceUp)
|
||||||
|
r = this.cardSprite.getBoundingRectangle();
|
||||||
|
else
|
||||||
|
r = this.backSprite.getBoundingRectangle();
|
||||||
|
return r;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setSize(float sizeX, float sizeY){
|
public void setSize(float sizeX, float sizeY){
|
||||||
@@ -107,18 +124,42 @@ public class Card {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void setPosition(Point position) {
|
public void setPosition(Point position) {
|
||||||
|
|
||||||
this.cardSprite.setPosition(position.getX(), position.getY());
|
this.cardSprite.setPosition(position.getX(), position.getY());
|
||||||
|
this.backSprite.setPosition(position.getX(), position.getY());
|
||||||
this.position.setCoordinates(position.getX(),position.getY());
|
this.position.setCoordinates(position.getX(),position.getY());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setCenter(Point position) {
|
public void setCenter(Point position) {
|
||||||
|
|
||||||
this.cardSprite.setCenter(position.getX(), position.getY());
|
this.cardSprite.setCenter(position.getX(), position.getY());
|
||||||
|
this.backSprite.setCenter(position.getX(), position.getY());
|
||||||
this.position.setCoordinates(position.getX(),position.getY());
|
this.position.setCoordinates(position.getX(),position.getY());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void toggleFaceUp(){
|
||||||
|
faceUp = !faceUp;
|
||||||
|
}
|
||||||
|
|
||||||
public Sprite getCardSprite() {
|
public Sprite getCardSprite() {
|
||||||
return this.cardSprite;
|
return this.cardSprite;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public int getId() {
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isFaceUp() {
|
||||||
|
return faceUp;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setFaceUp(boolean faceUp) {
|
||||||
|
this.faceUp = faceUp;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Sprite getBackSprite() {
|
||||||
|
return backSprite;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setBackSprite(Sprite backSprite) {
|
||||||
|
this.backSprite = backSprite;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,11 +1,11 @@
|
|||||||
package checamon.games.virtuacards;
|
package checamon.games.virtuacards;
|
||||||
|
|
||||||
import com.badlogic.gdx.graphics.Texture;
|
import com.badlogic.gdx.graphics.Texture;
|
||||||
import com.badlogic.gdx.graphics.g2d.Sprite;
|
|
||||||
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 java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collections;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
|
||||||
|
|
||||||
@@ -17,7 +17,7 @@ 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 Sprite result;
|
//private ArrayList<Deck> subdecks;
|
||||||
|
|
||||||
public Deck(Texture texture) {
|
public Deck(Texture texture) {
|
||||||
try {
|
try {
|
||||||
@@ -29,7 +29,7 @@ public class Deck {
|
|||||||
int index = 0;
|
int index = 0;
|
||||||
for (int i = 0; i < 5; i++) {
|
for (int i = 0; i < 5; i++) {
|
||||||
for (int j = 0; j < 13; j++){
|
for (int j = 0; j < 13; j++){
|
||||||
this.cards.add(index, new Card(cc[i][j]));
|
this.cards.add(index, new Card(cc[i][j], index, cc[4][2]));
|
||||||
this.drawOrder.put(index, -1);
|
this.drawOrder.put(index, -1);
|
||||||
index++;
|
index++;
|
||||||
}
|
}
|
||||||
@@ -58,20 +58,14 @@ public class Deck {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void drawCards(SpriteBatch batch)
|
public void drawCards(SpriteBatch batch) {
|
||||||
{
|
|
||||||
boolean exit = false;
|
|
||||||
Sprite aux;
|
|
||||||
int i = 0;
|
int i = 0;
|
||||||
while (i < numberOfCards && !exit){
|
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++;
|
||||||
}
|
}
|
||||||
else
|
|
||||||
exit = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isTouchingCard(float x, float y){
|
public boolean isTouchingCard(float x, float y){
|
||||||
@@ -80,16 +74,14 @@ 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;
|
||||||
exit = true;
|
exit = true;
|
||||||
}
|
}
|
||||||
i++;
|
|
||||||
}
|
}
|
||||||
else
|
i++;
|
||||||
exit = true;
|
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
@@ -100,67 +92,138 @@ 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;
|
||||||
exit = true;
|
exit = true;
|
||||||
}
|
}
|
||||||
i++;
|
|
||||||
}
|
}
|
||||||
else
|
i++;
|
||||||
exit = true;
|
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Card getTouchedDraggedCard(float x, float y){
|
public Card getTouchedDraggedCard(float x, float y){
|
||||||
|
|
||||||
boolean exit = false;
|
|
||||||
this.result = null;
|
|
||||||
Card cardResult = null;
|
Card cardResult = null;
|
||||||
int i = 0;
|
int i = numberOfCards;
|
||||||
|
boolean exit = false;
|
||||||
|
|
||||||
while (i < numberOfCards && !exit){
|
while (i >= 0 && !exit){
|
||||||
if (drawOrder.get(i) > -1){
|
|
||||||
if (cards.get(drawOrder.get(i)).isTouchedDragged(x, y)) {
|
if (cards.get(drawOrder.get(i)).isTouchedDragged(x, y)) {
|
||||||
|
|
||||||
this.result = cards.get(drawOrder.get(i)).getCardSprite();
|
|
||||||
cardResult = cards.get(drawOrder.get(i));
|
cardResult = cards.get(drawOrder.get(i));
|
||||||
exit = true;
|
exit = true;
|
||||||
|
}else {
|
||||||
|
i--;
|
||||||
}
|
}
|
||||||
i++;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
exit = true;
|
|
||||||
}
|
}
|
||||||
|
if (i < numberOfCards)
|
||||||
|
setCardDrawOrderOnTop(i);
|
||||||
return cardResult;
|
return cardResult;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Card getTouchedCard(float x, float y){
|
public Card getTouchedCard(float x, float y){
|
||||||
|
|
||||||
boolean exit = false;
|
|
||||||
this.result = null;
|
|
||||||
Card cardResult = null;
|
Card cardResult = null;
|
||||||
int i = 0;
|
int i = numberOfCards;
|
||||||
|
boolean exit = false;
|
||||||
|
|
||||||
while (i < numberOfCards && !exit){
|
while (i >= 0 && !exit){
|
||||||
if (drawOrder.get(i) > -1){
|
if (drawOrder.get(i) > -1 && cards.get(drawOrder.get(i)).isTouched(x, y)) {
|
||||||
if (cards.get(drawOrder.get(i)).isTouched(x, y)) {
|
|
||||||
|
|
||||||
this.result = cards.get(drawOrder.get(i)).getCardSprite();
|
|
||||||
cardResult = cards.get(drawOrder.get(i));
|
cardResult = cards.get(drawOrder.get(i));
|
||||||
exit = true;
|
exit = true;
|
||||||
|
}else{
|
||||||
|
i--;
|
||||||
}
|
}
|
||||||
i++;
|
|
||||||
}
|
}
|
||||||
else
|
if (i < numberOfCards)
|
||||||
|
setCardDrawOrderOnTop(i);
|
||||||
|
|
||||||
|
return cardResult;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Card getTouchedCard(float x, float y, int top){
|
||||||
|
|
||||||
|
Card cardResult = null;
|
||||||
|
int i = top;
|
||||||
|
boolean exit = false;
|
||||||
|
|
||||||
|
while (i >= 0 && !exit){
|
||||||
|
if (drawOrder.get(i) > -1 && cards.get(drawOrder.get(i)).isTouched(x, y)) {
|
||||||
|
cardResult = cards.get(drawOrder.get(i));
|
||||||
exit = true;
|
exit = true;
|
||||||
|
}else{
|
||||||
|
i--;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
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) {
|
||||||
|
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)));
|
||||||
|
if (i < originalOrder.size() - 1)
|
||||||
|
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() {
|
public HashMap<Integer,Integer> getDrawOrder() {
|
||||||
return drawOrder;
|
return drawOrder;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public int getNumberOfCards() {
|
||||||
|
return numberOfCards;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -35,19 +35,19 @@ public class Point {
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean insideRightSquare(float deltaX, float deltaY)
|
public boolean insideRightSquare(float deltaX, float deltaY, float originalY)
|
||||||
{
|
{
|
||||||
boolean result = false;
|
boolean result = false;
|
||||||
if (x <= x + deltaX && y <= y + (deltaY/2) && y > y - (deltaY/2))
|
if (x <= x + deltaX && y <= originalY + (deltaY/2) && y > originalY - (deltaY/2))
|
||||||
result = true;
|
result = true;
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean insideLeftSquare(float deltaX, float deltaY)
|
public boolean insideLeftSquare(float deltaX, float deltaY, float originalY)
|
||||||
{
|
{
|
||||||
boolean result = false;
|
boolean result = false;
|
||||||
if (x >= x - deltaX && y <= y + (deltaY/2) && y > y - (deltaY/2))
|
if (x >= x - deltaX && y <= originalY + (deltaY/2) && y > originalY - (deltaY/2))
|
||||||
result = true;
|
result = true;
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
@@ -69,7 +69,7 @@ public class Point {
|
|||||||
if (direction == 0)
|
if (direction == 0)
|
||||||
direction++; // Always 1 when going to the right
|
direction++; // Always 1 when going to the right
|
||||||
|
|
||||||
if (!p.insideRightSquare(deltaX,deltaY) || direction > 1) //Already changed direction to the left and now has come back to the right or outside the range
|
if (!p.insideRightSquare(deltaX,deltaY, points.get(0).getY()) || direction > 1) //Already changed direction to the left and now has come back to the right or outside the range
|
||||||
{
|
{
|
||||||
result = false;
|
result = false;
|
||||||
break;
|
break;
|
||||||
@@ -79,7 +79,7 @@ public class Point {
|
|||||||
if (direction == 1)
|
if (direction == 1)
|
||||||
direction++; // Always 2 when going to the left
|
direction++; // Always 2 when going to the left
|
||||||
|
|
||||||
if (!p.insideLeftSquare(deltaX, deltaY) || direction == 0 || direction > 2) //Already changed direction several times or has started going left or outside range
|
if (!p.insideLeftSquare(deltaX, deltaY, points.get(0).getY()) || direction == 0 || direction > 2) //Already changed direction several times or has started going left or outside range
|
||||||
{
|
{
|
||||||
result = false;
|
result = false;
|
||||||
break;
|
break;
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
package checamon.games.virtuacards;
|
package checamon.games.virtuacards;
|
||||||
|
|
||||||
|
|
||||||
import com.badlogic.gdx.ApplicationAdapter;
|
import com.badlogic.gdx.Game;
|
||||||
import com.badlogic.gdx.Gdx;
|
import com.badlogic.gdx.Gdx;
|
||||||
import com.badlogic.gdx.InputProcessor;
|
import com.badlogic.gdx.InputProcessor;
|
||||||
import com.badlogic.gdx.graphics.GL20;
|
import com.badlogic.gdx.graphics.GL20;
|
||||||
@@ -10,16 +10,15 @@ import com.badlogic.gdx.graphics.g2d.SpriteBatch;
|
|||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
|
||||||
|
public class VirtuaCards extends Game implements InputProcessor {
|
||||||
public class VirtuaCards extends ApplicationAdapter implements InputProcessor {
|
|
||||||
private SpriteBatch batch;
|
private SpriteBatch batch;
|
||||||
|
|
||||||
private int dragCounter;
|
private int dragCounter;
|
||||||
private int cardCounter;
|
private int cardCounter;
|
||||||
private ArrayList<Point> dragBuffer;
|
private ArrayList<Point> dragBuffer;
|
||||||
|
|
||||||
private Deck fullDeck;
|
private Deck fullDeck;
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void create () {
|
public void create () {
|
||||||
batch = new SpriteBatch();
|
batch = new SpriteBatch();
|
||||||
@@ -30,9 +29,13 @@ public class VirtuaCards extends ApplicationAdapter implements InputProcessor {
|
|||||||
fullDeck = new Deck(new Texture("full_french_deck.png"));
|
fullDeck = new Deck(new Texture("full_french_deck.png"));
|
||||||
|
|
||||||
//init drawn cards
|
//init drawn cards
|
||||||
fullDeck.getDrawOrder().put(0,11);
|
for (int i = 0; i < fullDeck.getNumberOfCards(); i++)
|
||||||
fullDeck.getDrawOrder().put(1,2);
|
fullDeck.getDrawOrder().put(i,i);
|
||||||
fullDeck.getCards().get(2).setPosition(new Point (200f,300f));
|
|
||||||
|
//fullDeck.getCards().get(52).setPosition(new Point(300f,100f));
|
||||||
|
|
||||||
|
fullDeck.shuffle(110f, 110f);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -71,14 +74,13 @@ public class VirtuaCards extends ApplicationAdapter implements InputProcessor {
|
|||||||
|
|
||||||
dragBuffer.add(dragCounter, new Point(screenX, Gdx.graphics.getHeight() - screenY));
|
dragBuffer.add(dragCounter, new Point(screenX, Gdx.graphics.getHeight() - screenY));
|
||||||
dragCounter++;
|
dragCounter++;
|
||||||
cardCounter++;
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
dragCounter = 0;
|
dragCounter = 0;
|
||||||
dragBuffer.clear();
|
dragBuffer.clear();
|
||||||
cardCounter = 0;
|
|
||||||
}
|
}
|
||||||
|
cardCounter = 0;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -125,7 +127,8 @@ public class VirtuaCards extends ApplicationAdapter implements InputProcessor {
|
|||||||
|
|
||||||
dragCounter = 0;
|
dragCounter = 0;
|
||||||
dragBuffer.clear();
|
dragBuffer.clear();
|
||||||
cardCounter = 0;
|
cardCounter = 1;
|
||||||
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -140,8 +143,14 @@ public class VirtuaCards extends ApplicationAdapter implements 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) {
|
||||||
|
|
||||||
//if (Point.pointListInsideDoubleTouchedDrag(dragBuffer, 75, 50) && dragCounter > 0)
|
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;
|
dragCounter = 0;
|
||||||
dragBuffer.clear();
|
dragBuffer.clear();
|
||||||
cardCounter = 0;
|
cardCounter = 0;
|
||||||
|
|||||||
Reference in New Issue
Block a user