I’m trying to make a trading card game, but it keeps messing up. I got a table with an enemy to see if works then I created 2 creatures, one player, one enemy, so far they can walk towards each other & stop when they reach another unit, but when I try adding stats attack & life for now. It gives me an error.
this my main page
ArrayList<Unit> player = new ArrayList<Unit>();
ArrayList<Unit> enemy = new ArrayList<Unit>();
Control con = new Control();
Table Etable;
TableRow tRow;
int round = 0;
void setup(){
size(1000,600);
player.add(new Unit(0,0));
enemy.add(new Unit(1,0));
Etable = new Table();
Etable.addColumn("attack");
Etable.addColumn("life");
tRow = Etable.addRow();
tRow.setInt("attack",1);
tRow.setInt("life",1);
}
void draw(){
background(0);
fill(255);
textSize(32);
text("Round: " + round, 0, 32);
text("Con num: " + con.num, 0, 64);
for (Unit p: player){
p.show();
p.move();
}
for (Unit e: enemy){
e.show();
e.move();
}
//con.update();
}
void keyPressed(){
if (key == ' '){
if (round == 0){
round = 1;
for (Unit e: enemy){
e.check = false;
e.mov = 1;
}
con.num = 0;
}// round 0
else if (round == 1){
round = 0;
for (Unit e: player){
e.check = false;
e.mov = 1;
}
con.num = 0;
}// round 0
}// space
if (key == 'a'){
if (round == 0){player.add(new Unit(0,0));}
if (round == 1){player.add(new Unit(1,0));}
}
}
this my controler, currently not being used
class Control{
int timer;
int num;
void update(){
if(timer > -1){timer -= 1;}
if (timer <= 0){
if (round == 0){
if (num == player.size()){
round = 1;
num = 0;
for (int i = 0; i < enemy.size(); i++){
Unit e = enemy.get(i);
e.num = 1;
e.check = false;
}
timer = 32;
}
}// 0
if (round == 1){
if (num == enemy.size()){
round = 0;
num = 0;
for (int i = 0; i < player.size(); i++){
Unit p = player.get(i);
p.num = 1;
p.check = false;
}
timer = 32;
}
}// 0
}// timer
}
}
this my unit
class Unit{
PVector pos,stat;
int type;
int num;
int mov = 1;
boolean check = false;
Unit(int t, int num){
stat = new PVector(0,0);
type = t;
this.num = num;
if (t == 0){pos = new PVector(0,300);}
if (t == 1){pos = new PVector(950,300);}
tRow = Etable.getRow(0);
stat.x = tRow.getInt("attack");
stat.y = tRow.getInt("life");
}
void show(){
if (type == 0){fill(255,0,0);}
if (type == 1){fill(0,255,0);}
rect(pos.x,pos.y,50,100);
fill(0);
textSize(16);
text("M: " + mov, pos.x+5, pos.y+16);
}
void check(){
if (type == 0){
for (int i = 0; i < enemy.size(); i++){
Unit e = enemy.get(i);
if (e.pos.x == pos.x + 50){mov = 0;}
}
for (int i = 0; i < player.size(); i++){
Unit e = player.get(i);
if (e.pos.x == pos.x + 50){mov = 0;}
}
}// type 0
if (type == 1){
for (int i = 0; i < player.size(); i++){
Unit e = player.get(i);
if (e.pos.x == pos.x - 50){mov = 0;}
}
for (int i = 0; i < enemy.size(); i++){
Unit e = enemy.get(i);
if (e.pos.x == pos.x - 50){mov = 0;}
}
}// type 0
}
void move(){
check();
if (mov > 0){
if (type == 0 && round == 0){
pos.x += 50;
mov -= 1;
}
if (type == 1 && round == 1){
pos.x -= 50;
mov -= 1;
}
}// mov 0
if (mov == 0 && check == false){
con.num += 1;
check = true;
}
}// move
}