java - Iterating a loop through all objects of a class -
new java- i'm building poker program , i've created player class instance variables including "toppair", "highcardst",etc... tried use placeholder variable refer appropriate player's instance variable rather relying on if statements.
int handsdealt=0; int straightval=0; string placeholder="blank"; player playerone = new player("richard"); player playertwo = new player("negreanu"); //code omitted if (handsdealt==1) placeholder="playerone"; else placeholder="playertwo"; //code determine if hand straight -if sets straightval 1 **if(straightval==1) placeholder.highcardst=straighthigh;**
i receive error on last line- looks java doesn't accept syntax. essentially, since hand straight want append value of "highcardst" instance variable of "n" th player n hands have been dealt.
thank you.
you make list of players , instance of player list required.
list<player> players = new arraylist<player>(); players.add(new player("richard")); players.add(new player("negreanu")); if(straightval==1) { players.get(handsdealt).highcardst=straighthigh; }
or that.
Comments
Post a Comment