Java-Gaming.org Hi !
Featured games (81)
games approved by the League of Dukes
Games in Showcase (513)
Games in Android Showcase (119)
games submitted by our members
Games in WIP (576)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  [solved] Selecting a boolean multiple times.  (Read 2228 times)
0 Members and 1 Guest are viewing this topic.
Offline roseslayer

Junior Duke


Medals: 1



« Posted 2012-12-27 21:27:14 »

Hello all,

This is my first post on the forum. I'm coming here for learning more Java, cause I'm kinda new to this. Currently I'm making myself a towerdefence game. It all worked out very good so far. Until I needed to make the upgrade/sell system of towers by pressing on them. At this moment I got all the towers stationed in the class Block. So my question is really much how can I select only 1 tower if there are 10 (as example) on the map and only upgrading/ selling that one. Anyone got a good tutorial/ explenation for letting this work, that would be great

[edit]
Ok, I solved some things. only the problem is, when i remove the // by the store (//store = true;) then the store will always be true, without my script works good only at 1 point it doesn't work good, a big point: you can press evrywhere on the map and the latest "UpgradeScreen" shows up.

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
            for(int y = 0; y<Screen.room.block.length;y++) {
            for(int x = 0; x<Screen.room.block[0].length;x++) {
               if(Screen.room.block[y][x].contains(Screen.mse)){
                  store = false;
                  if(Screen.room.block[y][x].airID == Value.airTowerLaser1) {UpgradeScreen = 1;}
                  if(Screen.room.block[y][x].airID == Value.airTowerLaser2) {UpgradeScreen = 2;}
                  if(Screen.room.block[y][x].airID == Value.airTowerLaser3) {UpgradeScreen = 3;}
               } else {
                  //store = true; It will never turn on again. Disabled for testing
               }
            }
         }
   }

-Roseslayer, my English can be really bad.
Thanks.

Fundamentum W.I.P.
Offline tyeeeee1
« Reply #1 - Posted 2012-12-27 22:08:16 »

The way I'd set it up, which is probably way over-complicated, would be to have a 2D array that stores every tile on the map and then have the towers set to a specific tile when they are built, for example [3][4], and then when you upgrade the tower you'd just tell the program to upgrade the tower at [3][4]. Actually, that doesn't seem to complicated now that I've typed it...
Offline roseslayer

Junior Duke


Medals: 1



« Reply #2 - Posted 2012-12-27 22:10:48 »

Thx for your post and I worked it out in the new code. it goes now with Screen.room.block[y][ x]*(as example 3 and 4). Only 1 problem either when i remove the // by the store (//store = true;) then the store will always be true, without my script works good only at 1 point it doesn't work good, a big point: you can press evrywhere on the map and the latest "UpgradeScreen" shows up.

[EDIT]
I changed the code, I debugged few things with System.out.println(""); and it's running very good! only this part isn't running very good:

1  
2  
3  
4  
5  
}else{
           UpgradeScreen = 0;
           Screen.room.block[y][x].rangeVisible = false;
           if(store == false) {store = true;}
}

It's making my other code:
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
      if(mouseButton == 3) {
         for(int y = 0; y<Screen.room.block.length;y++) {
            for(int x = 0; x<Screen.room.block[0].length;x++) {
               if(!Screen.room.block[y][x].contains(Screen.mse)){
                  Screen.room.block[y][x].rangeVisible = false;
               }
            }
         }
         if(holdsItem == true) {holdsItem = false;}
         if(store == false) {store = true;}
      }

not working anymore, I can tell this because without the Store = true; in the first code it's working good only you will always see the Upgrademenu that's why it needs to be false, and same with UpgradeScreen =0; then you will never see the good stats. Anyone got 1 idea for this? Am I missing some point here? please tell me

Whole Code:
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
25  
26  
27  
28  
29  
30  
31  
32  
33  
34  
35  
36  
37  
38  
39  
40  
41  
42  
43  
44  
45  
46  
47  
48  
49  
50  
51  
52  
53  
54  
55  
56  
57  
58  
59  
60  
public void click(int mouseButton) {
      if(mouseButton == 1) {  
         for(int y = 0; y<Screen.room.block.length;y++) {
            for(int x = 0; x<Screen.room.block[0].length;x++) {
               if(Screen.room.block[y][x].contains(Screen.mse)){
                  Screen.room.block[y][x].rangeVisible = true;
                  store = false;
                  if(Screen.room.block[y][x].airID == 2) {UpgradeScreen = 1;}//airTowerLaser1.
                  if(Screen.room.block[y][x].airID == 3) {UpgradeScreen = 2;}//airTowerLaser2.
                  if(Screen.room.block[y][x].airID == 4) {UpgradeScreen = 3;}//airTowerLaser3.
                  if(Screen.room.block[y][x].airID == 5) {UpgradeScreen = 4;}//airTowerArcher1.
                  if(Screen.room.block[y][x].airID == 6) {UpgradeScreen = 5;}//airTowerArcher2.
                  if(Screen.room.block[y][x].airID == 7) {UpgradeScreen = 6;}//airTowerArcher3.
               }else{
                  UpgradeScreen = 0;
                  Screen.room.block[y][x].rangeVisible = false;
                  //if(store == false) {store = true;}
               }
            }
         }
         for(int i=0;i<button.length;i++) {
            if(button[i].contains(Screen.mse)) {
               if(store == true){
                  if(buttonID[i] != Value.airAir) {
                     if(buttonID[i] == Value.airTrashCan) {
                        holdsItem = false;
                     } else {
                        heldID = buttonID[i];
                        realID = i;
                        holdsItem = true;
                     }
                  }
               }
            }
           
            if(holdsItem) {
               if(Screen.money >= buttonPrice[realID]) {
                  for(int y = 0; y<Screen.room.block.length;y++) {
                     for(int x = 0; x<Screen.room.block[0].length;x++) {
                        if(Screen.room.block[y][x].contains(Screen.mse)){
                           if(Screen.room.block[y][x].groundID == Value.groundRoad){holdsItem = false;}
                           if(Screen.room.block[y][x].groundID != Value.groundRoad && Screen.room.block[y][x].airID == Value.airAir) {
                              Screen.room.block[y][x].airID =  heldID;
                              Screen.money -= buttonPrice[realID];
                              holdsItem = false;
                              Screen.store.store = false;
                              if(Screen.room.block[y][x].airID == 2) {UpgradeScreen = 1;}//airTowerLaser1.
                              if(Screen.room.block[y][x].airID == 3) {UpgradeScreen = 2;}//airTowerLaser2.
                              if(Screen.room.block[y][x].airID == 4) {UpgradeScreen = 3;}//airTowerLaser3.
                              if(Screen.room.block[y][x].airID == 5) {UpgradeScreen = 4;}//airTowerArcher1.
                              if(Screen.room.block[y][x].airID == 6) {UpgradeScreen = 5;}//airTowerArcher2.
                              if(Screen.room.block[y][x].airID == 7) {UpgradeScreen = 6;}//airTowerArcher3.
                           }
                        }
                     }
                  }
               }
            }
         }
      }


-Roseslayer
Thanks already.

Fundamentum W.I.P.
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline tyeeeee1
« Reply #3 - Posted 2012-12-27 23:31:10 »

I don't have too much time to look at the code atm; Could you explain what the store boolean is for and what it does? (I'll be able to help a bit more after that  Cheesy )
Offline roseslayer

Junior Duke


Medals: 1



« Reply #4 - Posted 2012-12-27 23:49:47 »

the store boolean is only for to show if the store is on, I'll post some pictures about it,

Store true;


Store false && UpgradeScreen= 1;


Store draw script:
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
25  
26  
27  
28  
29  
30  
31  
32  
33  
34  
35  
36  
37  
38  
39  
40  
41  
42  
43  
44  
45  
46  
47  
48  
49  
50  
51  
52  
53  
54  
55  
56  
57  
58  
59  
60  
61  
62  
63  
64  
65  
66  
67  
68  
69  
70  
71  
72  
73  
74  
75  
76  
77  
78  
79  
80  
81  
82  
83  
84  
85  
86  
87  
88  
89  
90  
91  
92  
93  
94  
95  
96  
97  
98  
99  
100  
101  
102  
103  
   public void draw (Graphics g) {
      ImageIcon b = new ImageIcon("res/HUD.png");
      image = b.getImage();
      g.drawImage(image, 0, 0, null);
     
      if(store == false){
         //Makes Buttons
         for(int i=0;i<button.length;i++) {
            //Sell
            if(button[i].contains(Screen.mse)) {
               g.setColor(new Color(255,255,255,120));
               g.fillRect(500,  443+6, 52, 52);
            }
            g.drawImage(Screen.tileset_res[0], 500,  443+6, 52, 52, null);
            g.drawImage(Screen.tileset_air[Value.airSell], 500,  443+6, 52, 52, null);
            //Upgrade
            if(button[i].contains(Screen.mse)) {
               g.setColor(new Color(255,255,255,120));
               g.fillRect(440,  443+6, 52, 52);
            }
            g.drawImage(Screen.tileset_res[0], 440,  443+6, 52, 52, null);
            g.drawImage(Screen.tileset_air[Value.airUpgrade], 440 ,  443+6, 52, 52, null);
         }
         //Showing the tower stats.
         g.setFont(new Font("Courier New", Font.BOLD, 18));
         g.setColor(new Color(41,41,41));
         g.drawRect(198, 443, 154, 64);
         g.drawRect(199, 444, 152, 62);
         g.setColor(new Color(98,98,98,120));
         g.fillRect(200, 445, 151, 61);
         g.setColor(new Color(41,41,41));
         g.drawString(" TOWER STATS", 200, 458);
         g.setFont(new Font("Courier New", Font.BOLD, 14));
         if (UpgradeScreen== 1) {
            g.drawString(" Damage:       20", 200, 470);
            g.drawString(" Range:        180", 200, 480);
            g.drawString(" Rate Of Fire: 100", 200, 490);
            g.drawString(" Sell Price:   10", 200, 500);
         }  
         if (UpgradeScreen== 2) {
            g.drawString(" Damage:       35", 200, 470);
            g.drawString(" Range:        140", 200, 480);
            g.drawString(" Rate Of Fire: 150", 200, 490);
            g.drawString(" Sell Price:   30", 200, 500);
         }
         if (UpgradeScreen== 3) {
            g.drawString(" Damage:       60", 200, 470);
            g.drawString(" Range:        100", 200, 480);
            g.drawString(" Rate Of Fire: 175", 200, 490);
            g.drawString(" Sell Price:   60", 200, 500);
         }
         if (UpgradeScreen== 4) {
            g.drawString(" Damage:       10", 200, 470);
            g.drawString(" Range:        150", 200, 480);
            g.drawString(" Rate Of Fire: 300", 200, 490);
            g.drawString(" Sell Price:   20", 200, 500);
         }  
         if (UpgradeScreen== 5) {
            g.drawString(" Damage:       15", 200, 470);
            g.drawString(" Range:        175", 200, 480);
            g.drawString(" Rate Of Fire: 350", 200, 490);
            g.drawString(" Sell Price:   45", 200, 500);
         }
         if (UpgradeScreen== 6) {
            g.drawString(" Damage:       30", 200, 470);
            g.drawString(" Range:        200", 200, 480);
            g.drawString(" Rate Of Fire: 450", 200, 490);
            g.drawString(" Sell Price:   90", 200, 500);
         }
      }
      if(store == true) {
         for(int i=0;i<button.length;i++) {
            if(button[i].contains(Screen.mse)) {
               g.setColor(new Color(255,255,255,120));
               g.fillRect(button[i].x, button[i].y, button[i].width, button[i].height);
            }
           
            g.drawImage(Screen.tileset_res[0], button[i].x, button[i].y, button[i].width, button[i].height, null);
            if(buttonID[i] != Value.airAir)g.drawImage(Screen.tileset_air[buttonID[i]], button[i].x + itemIn, button[i].y + itemIn, button[i].width - (itemIn*2), button[i].height - (itemIn*2), null);
            if(buttonPrice[i] > 0) {
               g.setFont(new Font("Courier New", Font.BOLD, 14));
               g.setColor(new Color(41,41,41));
               g.drawString("€" +buttonPrice[i] + ",-",  button[i].x + itemIn, button[i].y + itemIn + 62);
            }
         }
      }
     
      g.drawImage(Screen.tileset_res[1], buttonHealth.x, buttonHealth.y, buttonHealth.width, buttonHealth.height, null);
      g.drawImage(Screen.tileset_res[2], buttonCoins.x, buttonCoins.y, buttonCoins.width, buttonCoins.height, null);
      g.drawImage(Screen.tileset_res[3], buttonKilled.x, buttonKilled.y, buttonKilled.width, buttonKilled.height, null);
      g.setFont(new Font("Courier New", Font.BOLD, 14));
      g.setColor(new Color(236, 0, 0));
      g.drawString("" + Screen.health +"/" + Screen.maxHealth, buttonHealth.x + buttonHealth.width + iconSpace, buttonHealth.y + iconTextY);
      g.setColor(new Color(255, 205, 6));
      g.drawString("" + Screen.money, buttonCoins.x + buttonCoins.width + iconSpace, buttonCoins.y + iconTextY);
      g.setColor(new Color(190, 189, 187));
      g.drawString("" + Screen.killed, buttonKilled.x + buttonKilled.width + iconSpace, buttonKilled.y + iconTextY);
      g.setColor(new Color(255, 255, 255));
     
      if(holdsItem) {
         g.drawImage(Screen.tileset_air[heldID], Screen.mse.x - ((button[0].width - (itemIn*2) )/2) + itemIn, Screen.mse.y - ((button[0].width - (itemIn*2) )/2) + itemIn, button[0].width - (itemIn*2), button[0].height - (itemIn*2), null);
      }
   }

Fundamentum W.I.P.
Offline HeroesGraveDev

JGO Kernel


Medals: 269
Projects: 11
Exp: 2 years


┬─┬ノ(ಠ_ಠノ)(╯°□°)╯︵ ┻━┻


« Reply #5 - Posted 2012-12-27 23:57:05 »

You should not be doing this

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
25  
26  
27  
28  
29  
30  
31  
32  
33  
34  
35  
36  
if (UpgradeScreen== 1) {
            g.drawString(" Damage:       20", 200, 470);
            g.drawString(" Range:        180", 200, 480);
            g.drawString(" Rate Of Fire: 100", 200, 490);
            g.drawString(" Sell Price:   10", 200, 500);
         }  
         if (UpgradeScreen== 2) {
            g.drawString(" Damage:       35", 200, 470);
            g.drawString(" Range:        140", 200, 480);
            g.drawString(" Rate Of Fire: 150", 200, 490);
            g.drawString(" Sell Price:   30", 200, 500);
         }
         if (UpgradeScreen== 3) {
            g.drawString(" Damage:       60", 200, 470);
            g.drawString(" Range:        100", 200, 480);
            g.drawString(" Rate Of Fire: 175", 200, 490);
            g.drawString(" Sell Price:   60", 200, 500);
         }
         if (UpgradeScreen== 4) {
            g.drawString(" Damage:       10", 200, 470);
            g.drawString(" Range:        150", 200, 480);
            g.drawString(" Rate Of Fire: 300", 200, 490);
            g.drawString(" Sell Price:   20", 200, 500);
         }  
         if (UpgradeScreen== 5) {
            g.drawString(" Damage:       15", 200, 470);
            g.drawString(" Range:        175", 200, 480);
            g.drawString(" Rate Of Fire: 350", 200, 490);
            g.drawString(" Sell Price:   45", 200, 500);
         }
         if (UpgradeScreen== 6) {
            g.drawString(" Damage:       30", 200, 470);
            g.drawString(" Range:        200", 200, 480);
            g.drawString(" Rate Of Fire: 450", 200, 490);
            g.drawString(" Sell Price:   90", 200, 500);
         }


It should be:

1  
2  
3  
4  
5  
6  
7  
8  
9  
int damage = getDamage(UpgradeScreen); // you need to create these methods
int range = getRange(UpgradeScreen);
int rate = getRate(UpgradeScreen);
int price = getPrice(UpgradeScreen);

g.drawString(" Damage:       " + damage, 200, 470);
g.drawString(" Range:        " + range, 200, 480);
g.drawString(" Rate Of Fire: " + rate, 200, 490);
g.drawString(" Sell Price:   " + price, 200, 500);


This will save heaps of time when coding.

Offline HeroesGraveDev

JGO Kernel


Medals: 269
Projects: 11
Exp: 2 years


┬─┬ノ(ಠ_ಠノ)(╯°□°)╯︵ ┻━┻


« Reply #6 - Posted 2012-12-28 00:00:14 »

As an answer to your question, it's a design problem. We can't tell you how to design your game.
You have to do that yourself. It's a part of programming.

As for your other problem, USE THE ELSE-IF STATEMENT!
That will solve a lot of problems.

Offline roseslayer

Junior Duke


Medals: 1



« Reply #7 - Posted 2012-12-28 00:08:42 »

How you mean use the else-if statement? This will not change a thing to
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
                if(Screen.room.block[y][x].contains(Screen.mse)){
                  Screen.room.block[y][x].rangeVisible = true;
                  store = false;
                  if(Screen.room.block[y][x].airID == 2) {UpgradeScreen = 1;}//airTowerLaser1.
                  if(Screen.room.block[y][x].airID == 3) {UpgradeScreen = 2;}//airTowerLaser2.
                  if(Screen.room.block[y][x].airID == 4) {UpgradeScreen = 3;}//airTowerLaser3.
                  if(Screen.room.block[y][x].airID == 5) {UpgradeScreen = 4;}//airTowerArcher1.
                  if(Screen.room.block[y][x].airID == 6) {UpgradeScreen = 5;}//airTowerArcher2.
                  if(Screen.room.block[y][x].airID == 7) {UpgradeScreen = 6;}//airTowerArcher3.
               }else if(!Screen.room.block[y][x].contains(Screen.mse)){
                  UpgradeScreen = 0;
                  Screen.room.block[y][x].rangeVisible = false;
                  if(store == false) {store = true;}
               }

Or am I using it wrong at some point

-Roseslayer
Thanks

Fundamentum W.I.P.
Offline LunaticEdit
« Reply #8 - Posted 2012-12-28 00:29:11 »

And in that code...

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
                if(Screen.room.block[y][x].contains(Screen.mse)){
                  Screen.room.block[y][x].rangeVisible = true;
                  store = false;
                  if((Screen.room.block[y][x].airID >= 2) && (Screen.room.block[y][x].airID <= 7)) {
                         UpdateScreen = Screen.room.block[y][x].airID - 1;
                  }
               } else {
                  UpgradeScreen = 0;
                  Screen.room.block[y][x].rangeVisible = false;
                  if(store == false) {store = true;}
               }


Although that code in general seems odd.

Offline HeroesGraveDev

JGO Kernel


Medals: 269
Projects: 11
Exp: 2 years


┬─┬ノ(ಠ_ಠノ)(╯°□°)╯︵ ┻━┻


« Reply #9 - Posted 2012-12-28 00:38:46 »

It's a performance improvement.

Also this:

1  
if(store == false) {store = true;}


You are taking more CPU time than if you just went
store = true

Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline roseslayer

Junior Duke


Medals: 1



« Reply #10 - Posted 2012-12-28 12:18:02 »

All true, but still my problem isn't fixed the CPU is only faster, thanks for that but still I need help at my "main" problem.

-Roseslayer
Thanks

Fundamentum W.I.P.
Offline matheus23

JGO Kernel


Medals: 109
Projects: 3


You think about my Avatar right now!


« Reply #11 - Posted 2012-12-28 12:56:28 »

It's a performance improvement.

Also this:

1  
if(store == false) {store = true;}


You are taking more CPU time than if you just went
store = true


I'm sure the JVM optimizes this.
It's more a code smell or just senseless to put the if there.
But basically you're right.

See my:
    My development Blog:     | Or look at my RPG | Or simply my coding
http://matheusdev.tumblr.comRuins of Revenge  |      On Github
Offline roseslayer

Junior Duke


Medals: 1



« Reply #12 - Posted 2012-12-28 14:24:46 »

Anyone know how to fix  the main problem? you cant go in upgradeStore cause it will always be 0 and store will always be true if you arent pressing. someone know what I am doing wrong here?

-Roseslayer
Thanks already

Fundamentum W.I.P.
Offline HeroesGraveDev

JGO Kernel


Medals: 269
Projects: 11
Exp: 2 years


┬─┬ノ(ಠ_ಠノ)(╯°□°)╯︵ ┻━┻


« Reply #13 - Posted 2012-12-28 19:27:27 »

Do some debugging and find which values are wrong, and where they go wrong.

Put in a few System.out.println()'s showin whatever values you think might be wrong, then if they are, track them back until you find the source of the problem.

Offline Phibedy

Senior Duke


Medals: 8



« Reply #14 - Posted 2012-12-28 20:42:39 »

In my opinion everybody use Eclipse -> use the debugger
At the beginning it's not that easy, but u will enjoy it afterwards   Smiley
Offline ctomni231

JGO Wizard


Medals: 99
Projects: 1
Exp: 7 years


Not a glitch. Just have a lil' pixelexia...


« Reply #15 - Posted 2012-12-28 21:39:51 »

I know what you want to accomplish. When you click on a tower, it shows an upgrade window for that tower. Well, first off, only one tower can be selected at a time. So, you'll need a way to select only one tower. Since that seems to be the only problem, I'll show you how to get that effect with this simple code.

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
25  
26  
27  
28  
29  
30  
31  
public boolean[][] oneOnly;

public void init(){
       oneOnly = new boolean[10][10];
}

public void update(){
       for(int i = 0; i < oneOnly.length(); i++){
              for(int j = 0; j < oneOnly[i].length; j++){
                     if(!oneOnly[i][j]){
                             // Do the basic tower actions here
                     }
                     else {
                             //Do the menu changes if this button contains a tower
                             //If not, then do the basic actions
                     }    
              }
       }
}

public void click( int button ){
     if( button == 1){
           for(int i = 0; i < oneOnly.length; i++){
                for(int j = 0; j < oneOnly[i].length; j++){
                          oneOnly[i][j] = false;
                }
           }
           //Guarantees that only one object is selected
           oneOnly[mousex][mousey] = true;
     }
}


It isn't exactly like your code, because you are using buttons. But, this example makes sure that one object is selected at all times, so you can mimic it and probably get it to work.

Offline roseslayer

Junior Duke


Medals: 1



« Reply #16 - Posted 2012-12-29 18:58:03 »

Ctomni, sorry for my late reaction, but can you explain your script? If you know what I mean, cause I'm kinda new to java and I don't really know what you're trying to do there.

-Roseslayer
Thanks

Fundamentum W.I.P.
Offline Jimmt
« League of Dukes »

JGO Kernel


Medals: 136
Projects: 4
Exp: 3 years



« Reply #17 - Posted 2012-12-29 19:04:00 »

You're already pretty lucky to get someone to write the code for you, and know you want him to put it in your program too? This just tells me that you don't understand the code. Look at it and understand it and you will naturally know where to put the code.
Offline roseslayer

Junior Duke


Medals: 1



« Reply #18 - Posted 2012-12-29 19:08:21 »

I know where to put this code, but I fully want to understand this code, because I want to know what I am doing in my own programm right?

[EDIT]
The only parts I don't understand are oneOnly.length();
and oneOnly[mousex][mousey] = true;

Fundamentum W.I.P.
Offline matheus23

JGO Kernel


Medals: 109
Projects: 3


You think about my Avatar right now!


« Reply #19 - Posted 2012-12-29 19:21:38 »

[EDIT]
The only parts I don't understand are oneOnly.length();
and oneOnly[mousex][mousey] = true;

You mean, the only parts which give errors are these lines Wink
Okey, sorry for picking around on you Cheesy

I'm sure the first one is supposed to be
oneOnly.length
and the second one: You need to get the mouse position in your window somehow.
There are several ways to do this with java2D. I guess you should google that, because that was answered often.

See my:
    My development Blog:     | Or look at my RPG | Or simply my coding
http://matheusdev.tumblr.comRuins of Revenge  |      On Github
Offline ctomni231

JGO Wizard


Medals: 99
Projects: 1
Exp: 7 years


Not a glitch. Just have a lil' pixelexia...


« Reply #20 - Posted 2012-12-30 02:20:35 »

Yeah, matheus23 is spot on.

In English, what you are trying to do is just make sure one position on the map is selected at a time. So, in the code, you'll want to clear all selections when the user clicks. Then you want to make sure only one position is selected. You are using a field of buttons for each one, so when the user selects a tower button. Clear out all the stores first, and then make sure only one is selected.

That example code was showing you the best places to do it. The
 oneOnly[mousex][mousey] = true 
loosely translates to your code in this
 public void click(int mouseButton) { ... } 
.


Offline roseslayer

Junior Duke


Medals: 1



« Reply #21 - Posted 2012-12-30 15:02:49 »

[EDIT]
The only parts I don't understand are oneOnly.length();
and oneOnly[mousex][mousey] = true;

You mean, the only parts which give errors are these lines Wink
Okey, sorry for picking around on you Cheesy

I'm sure the first one is supposed to be
oneOnly.length
and the second one: You need to get the mouse position in your window somehow.
There are several ways to do this with java2D. I guess you should google that, because that was answered often.
The first one I already knew, cause he didnt made a void, but still posted it without a reason, sometimes I'm kinda useless and ctomni231, I'm going to try that. cause the problem of my code is the else statement with the if
1  
}else if(!Screen.room.block[y][x].contains(Screen.mse)){
this giving me alot of problems but I am trying your idea, I will send how it went.

[edit]
I did it alot more easier, and fixed it. I'm a little bit brainless that I didn't thaught of this:
1  
                      if(Screen.room.block[y][x].airID >= 2 && Screen.room.block[y][x].airID <= 7){UpgradeScreen = Screen.room.block[y][x].airID -1; upgradeStore = true;}else{upgradeStore = false; UpgradeScreen =0;}


1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
25  
26  
27  
28  
29  
30  
31  
32  
33  
34  
35  
36  
37  
38  
39  
40  
41  
42  
43  
44  
45  
46  
47  
48  
49  
50  
51  
52  
53  
54  
55  
56  
57  
58  
59  
60  
61  
62  
63  
   public void click(int mouseButton) {
      if(mouseButton == 3) {
         for(int y = 0; y<Screen.room.block.length;y++) {
            for(int x = 0; x<Screen.room.block[0].length;x++) {
               if(!Screen.room.block[y][x].contains(Screen.mse)){
                      Screen.room.block[y][x].rangeVisible = false;
                      upgradeStore = false;
                   }
            }
         }
      }
      if(mouseButton == 1) {  
         for(int y = 0; y<Screen.room.block.length;y++) {
            for(int x = 0; x<Screen.room.block[0].length;x++) {
               if(Screen.room.block[y][x].contains(Screen.mse)){
                     Screen.room.block[y][x].rangeVisible = true;
                          if(Screen.room.block[y][x].airID >= 2 && Screen.room.block[y][x].airID <= 7){UpgradeScreen = Screen.room.block[y][x].airID -1; upgradeStore = true;}else{upgradeStore = false; UpgradeScreen =0;}
               }else{
                     Screen.room.block[y][x].rangeVisible = false;
               }
            }
         }
         for(int i=0;i<button.length;i++) {
            if(button[i].contains(Screen.mse)) {
               if(store == true){
                  if(buttonID[i] != Value.airAir) {
                     if(buttonID[i] == Value.airTrashCan) {
                        holdsItem = false;
                     } else {
                        heldID = buttonID[i];
                        realID = i;
                        holdsItem = true;
                     }
                  }
               }
            }
               
            if(holdsItem) {
                  if(Screen.money >= buttonPrice[realID]) {
                     for(int y = 0; y<Screen.room.block.length;y++) {
                        for(int x = 0; x<Screen.room.block[0].length;x++) {
                           if(Screen.room.block[y][x].contains(Screen.mse)){
                              if(Screen.room.block[y][x].groundID != Value.groundGrass | Screen.room.block[y][x].airID != Value.airAir) {holdsItem = false;}
                              if(Screen.room.block[y][x].groundID == Value.groundGrass && Screen.room.block[y][x].airID == Value.airAir) {
                                 Screen.room.block[y][x].airID =  heldID;
                                 Screen.money -= buttonPrice[realID];
                                 holdsItem = false;
                                 upgradeStore = true;
                                 if(Screen.room.block[y][x].airID >= 2 && Screen.room.block[y][x].airID <= 7)//2-7 towers in Value.
                                 {UpgradeScreen = Screen.room.block[y][x].airID -1;
                                 }
                              }
                           }
                        }
                     }
                  }
            }
         }
      }
      System.out.println("Store=" + store);
      System.out.println("UpgradeStore=" + upgradeStore);
      System.out.println("UpgradeScreen=" + UpgradeScreen);
   }


Thanks for helping me all, really thanks for that!

-Roseslayer
Thanks

Fundamentum W.I.P.
Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

Longarmx (38 views)
2014-10-17 03:59:02

Norakomi (29 views)
2014-10-16 15:22:06

Norakomi (24 views)
2014-10-16 15:20:20

lcass (28 views)
2014-10-15 16:18:58

TehJavaDev (56 views)
2014-10-14 00:39:48

TehJavaDev (55 views)
2014-10-14 00:35:47

TehJavaDev (46 views)
2014-10-14 00:32:37

BurntPizza (64 views)
2014-10-11 23:24:42

BurntPizza (36 views)
2014-10-11 23:10:45

BurntPizza (78 views)
2014-10-11 22:30:10
Understanding relations between setOrigin, setScale and setPosition in libGdx
by mbabuskov
2014-10-09 22:35:00

Definite guide to supporting multiple device resolutions on Android (2014)
by mbabuskov
2014-10-02 22:36:02

List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50

List of Learning Resources
by SilverTiger
2014-07-31 16:26:06
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!