在我的程序中,如果您有所需的矿物质,您可以在小程序上放置图片
你从 400 开始,每个是 100 矿物,所以你放置 3,然后在第 4 天它会删除所有其他矿物
public int Minerals
//Pylons
int xCoord[];
int yCoord[];
int numSquare;
boolean firstPaint;
public void init()
{
Minerals = 400;
pylon = getImage(getDocumentBase(),"image/pylon.png");
//pylons
xCoord = new int[100];
yCoord = new int[100];
numSquare = 0;
firstPaint = true;
}
public void paint(Grapics g)
{
pylons(g);
}
public void pylons(Graphics g)
{
//Building the pylons
if(Minerals >= 100)
{
for (int k = 0; k < numSquare; k++)
{
g.drawImage(pylon,xCoord[k],yCoord[k],85,85,this);
//Makes cursor normal.
setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
}
}
//Checks if buildPylon is 1 if so it will draw the infoScreen and then set the cursor to pylon
if(buildPylon == 1)
{
g.drawImage(pylon,510,820,100,100,this);
//Use the custom cursor
setCursor(cursor);
}
}
private void handlePylonPlacement()
{
//This takes away 100 minerals and will add 9 population and make buildPylon 0 again
if(decrementMinerals(100))
addPopMax(9);
buildPylon = 0;
}
private boolean decrementMinerals(int amount)
{
//This Is where it takes away the minerals
if(Minerals - amount >= 0) // prevent situation where you go into negative minerals
{
Minerals -= amount;
return true;
}
else
return false;
}
private void addPopMax(int amount)
{
//Add the population (9)
if(popMax + amount <= 72) // restrict addition to pop-max to a sane upper bound
popMax += amount;
}
public boolean mouseDown(Event e, int x, int y) {
//Makes the ints xCoord2 to equal x and same for the other
xCoord2 = x;
yCoord2 = y;
repaint();
if (numClicks == 10) {//Title screen
numClicks++;
repaint();
}
//Checks to see if buildPylon == 1 then builds the pylon if its in the correct place.
if(buildPylon == 1)
{
if(x > 1 && x < 1275 && y > 711 && y < 948) // Checks to see if the person clicked in this area
{}
else if(x > 378 && x < 876 && y < 568 && y < 705) // Checks to see if the person clicked in this area
{}else if (Minerals >= 100)
{
xCoord[numSquare] = x;
yCoord[numSquare] = y;
numSquare++;
handlePylonPlacement(); // call your new handler
repaint();
}
}
return true;
}
而不是删除它们,我希望塔继续画在屏幕上......有什么帮助吗?