2012-05-22 39 views
2

在我的計劃,你可以把圖片上的小程序,如果你有需要的礦物質圖片去礦物質後離開= 0

你開始與400,每一個是100噸的礦物質,所以你把3然後四號它將刪除所有其他

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; 
    } 

而不是將其刪除它們,我想掛架留在屏幕上畫...任何幫助嗎?

+0

也許你忘了它,但'buildPylon'沒有在你的代碼中的任何地方聲明 – mastaH

+0

pylons()中這行if(Minerals> = 100)是做什麼的?另外,'buildPylon'在哪裏設置爲1? –

回答

0

handlePylonPlacement(),您的意思是否

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; 
     }  
    } 

+0

它仍然消失 –