I have an Actor subclass called AllCards, an AllCards subclass called Decks and 2 subclasses of Decks which are called SenatorDeck and ActionCardsDeck
The code of class Decks:
The code of class SenatorDeck
The code of class ActionCardsDeck:
import greenfoot.*;
import java.util.List;
import java.util.ArrayList;
public class Decks extends AllActors
{
public int cardsNumber=5; //number of cards each player has on his hand at the beginning of the game
}
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
public class SenatorDeck extends Decks
{
private Label myLabel;
public int count=6-players;
public SenatorDeck(Label label)
{
myLabel=label;
}
public void act()
{
if (Greenfoot.mouseClicked(this) && count!=0)
{
Senator senator = new Senator();
getWorld().addObject(senator, 87+cardsNumber*40, 1680);
count--;
myLabel.setText(""+count);
cardsNumber++; //I wanted to save the value of this variable, to make it global
}
}
}import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
public class ActionCardsDeck extends Decks
{
private Label2 myLabel;
public int count=128;
public ActionCardsDeck(Label2 label2)
{
myLabel=label2;
}
public void thinking()
{
int number = Greenfoot.getRandomNumber(4);
if (number==0)
{
getWorld().addObject(new Cyrk(), 87 + cardsNumber * 40, 1680); //so the value of cardsNumber would be the same as it's in the if of the previous class and vice versa.
}
if (number==1)
{
getWorld().addObject(new Latryna(), 87 + cardsNumber * 40, 1680);
}
if (number==2)
{
getWorld().addObject(new ŁukTryumfalny(), 87 + cardsNumber * 40, 1680);
}
if (number==3)
{
getWorld().addObject(new Ogród(), 87 + cardsNumber * 40, 1680);
}
count--;
myLabel.setText(""+count);
cardsNumber++;
if (count==0)
{
Greenfoot.stop();
}
}
public void act()
{
if (Greenfoot.mouseClicked(this))
{
if (cardsNumber>=5)
{
thinking();
}
else
{
for (int i=cardsNumber; i<5; i++)
{
thinking();
}
}
}
}
}

