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.

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...

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:

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

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.

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.

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.

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

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

}elseif(!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:

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