I’m trying to make a card game, but when I try to get the player’s hand in the correct spot. All 5 cards go to the last spot instead of staying where they suppose to.
here setup
Table enemyT;
TableRow tr;
int s = 75;
ArrayList<Card> deck = new ArrayList<Card>();
ArrayList<Card> hand = new ArrayList<Card>();
int turn = 0;
Feild feild = new Feild();
void setup(){
size(600,600);
enemyT = loadTable("zombies.csv","header");
for (int i = 0; i < 10; i++){
deck.add(new Card(0));
}
}
void draw(){
background(0);
textSize(20);
fill(255);
text("Turn: " + turn, 10, 20);
text("Hand: " + hand.size(), 10, 40);
text("Deck: " + deck.size(), 10, 60);
if (deck.size() > 0){
fill(255);
rect(10,520,s,s);
fill(0);
textSize(80);
text("D",20,585);
}
feild.update();
for (Card c: deck){
c.show();
}
for (Card c: hand){
c.show();
}
}
here is Card
class Card{
PVector pos,tcol,rcol,scol;
String name,type,element;
int rank,attack,defense;
boolean inDeck,inHand,inFeild;
Card(int n){
inDeck = true;
pos = new PVector(10,520);
scol = new PVector(255,255,255);
rcol = new PVector(0,0,0);
tcol = new PVector(255,255,255);
/*
tr = enemyT.getRow(n);
name = tr.getString("name");
type = tr.getString("type");
element = tr.getString("element");
rank = tr.getInt("rank");
attack = tr.getInt("attack");
defense = tr.getInt("defense");
*/
name = "zombie 1";
type = "zombie";
element = "dark";
rank = 6;
attack = 2500;
defense = 1200;
if (element.equals("dark")){
scol = new PVector(255,255,255);
rcol = new PVector(0,0,0);
tcol = scol;
}
}
void show(){
if (inDeck == false){
stroke(scol.x,scol.y,scol.z);
fill(rcol.x,rcol.y,rcol.z);
rect(pos.x,pos.y,s,s);
fill(tcol.x,tcol.y,tcol.z);
textSize(18);
text(type,pos.x+5,pos.y+20);
}
}
}
here is feild. it controls when cards move & place them in correct places
class Feild{
void update(){
if (turn == 0){
if (hand.size() < 5){
Card c = deck.get(0);
hand.add(c);
}// hand 5
if (hand.size() == 5){
turn = 1;
}
}// turn 0
if (turn == 1){
for (int i = 0; i < hand.size(); i++){
Card c = hand.get(i);
c.pos.x = 80 + (80 * i);
c.inHand = true;
c.inDeck = false;
}
}// turn 1
}// update
}// feild