Reputation: 43
Okay so.. i have a method that basically checks if the player can buy the field and if he can then sets him as the owner and return true. the method i am referring to is buyFieldFromBank in the if statement.
But i want to check if my method returns true, and if it do, ask the user if he wants to buy it. can i actually do it like this? or will the code allready have set him as owner in the if statement? Or does it only "check" if it turns true, without actually executing the code?
if(landRegistry.buyFieldFromBank(currentPlayer, newPosID)==true){
if(GUI.getUserButtonPressed(currentPlayer.getName() + ", vil du købe " + newPosition.getFieldName() + "Ja", "Nej")=="Ja"){
landRegistry.buyFieldFromBank(currentPlayer, newPosID);
Upvotes: 2
Views: 89
Reputation: 41117
If you call a method with .
you're executing that method always. How else can it work? You should change your design.
Upvotes: 1
Reputation: 5663
Couple of obvious issues:
1) You're using ==
instead .equals
to compare Strings in the 2nd if, well tread debate covering that issue here: Link
2) By calling landRegistry.buyFieldFromBank
you are executing that method, so it will already be done. You need a method like landRegistry.isUserEligible(currentPlayer,newPosId)
to check in that first if statement. Then if it passes both the first & secondary conditions it should call the buyFieldFromBank
method. Also it may be worth considering if that 2nd if should belong in the isUserEligible
method call; if it's part of the logic of determining eligibility it might fit best there.
3) The == true
part of the first if is redundant if the method you're calling returns a boolean. So you can drop that part and just have the method call itself.
Upvotes: 3