First off I'm using Jpanel to create a game with an interface and playing field with around 30 - 40 hexes. Each hex is a label / image and has a 3 methods that are listeners for exit / press / click.
The problem is that each hex needs to use a ton of variables and I don't want to code an individual set of variables for each hex.
example:
lumberHex1, lumberHex2, lumberHex3
as an example I want to set 'boolean lumber' and 'boolean discovered' to be true only inside that method.
Local variables aren't working...
I'm afraid I don't quite understand an easy way of doing this. 'boolean discovered' and 'boolean lumber' are declared at the top of the class, I need a variable that can be named the same but hold different values for each method?
Hopefully I am making some sense, and there is just a flaw in my logic - or there is another way of doing this - any help would be greatly appreciated.
The problem is that each hex needs to use a ton of variables and I don't want to code an individual set of variables for each hex.
example:
as an example I want to set 'boolean lumber' and 'boolean discovered' to be true only inside that method.
Local variables aren't working...
I'm afraid I don't quite understand an easy way of doing this. 'boolean discovered' and 'boolean lumber' are declared at the top of the class, I need a variable that can be named the same but hold different values for each method?
Hopefully I am making some sense, and there is just a flaw in my logic - or there is another way of doing this - any help would be greatly appreciated.
private void jLabel57MouseClicked(java.awt.event.MouseEvent evt) { randomResource rg = new randomResource(); rg.setResource(lumber, brick, coin , grain); //boolean discovered; if (clicked == false) { rg.genNum(); System.out.println(rg.resourceValue); if (rg.resourceValue.equals("lumber")) { jLabel57.setIcon(new ImageIcon("src/hexTree.png")); System.out.println("Lumber has been placed here? = " + rg.isLumber); discovered = true; // right here lumber = true; // right here rg.setAll(clicked = true); rg.returnLumber(lumber); if(villagerAmount <= 0 ) { jLabel57.setIcon(new ImageIcon("src/hexTreeRedFull.png")); } if(villagerAmount >= 1) { jLabel57.setIcon(new ImageIcon("src/hexTreeCutting.png")); harvestReady = true; ActionListener taskPerformer5 = new ActionListener() { public void actionPerformed(ActionEvent evt) { while(buffRemaining >= 0) { resource1Amount++; buffRemaining--; } if (buffRemaining <= 0) { harvesting = false; } } }; new Timer(delayThreeTwo, taskPerformer5).start(); villagerAmount--; villagers.setText("Villagers: " + villagerAmount); } }