新的所有对象的循环,以Java的 我要建一个扑克计划,我已经创建了一个播放器类的一些实例变量,包括“toppair”,“highcardst”,等等。我试图使用占位符变量来引用合适的玩家的实例变量,而不是依赖if语句。迭代通过类
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 to determine if hand is a straight -if it is it sets straightval to 1
**if(straightval==1) placeholder.highcardst=straightHigh;**
我在最后一行收到一个错误 - 它看起来像java不接受这种语法。基本上,由于这只手是笔直的,我想在n手牌发出时追加第n个牌手的“highcardst”实例变量的值。
谢谢。
请发布确切的错误。 – Carcigenicate 2015-04-01 10:55:00
你不能使用变量作为对象namae – Burusothman 2015-04-01 10:55:03
似乎你想在Java代码中使用JSON。最接近你想要做的是Map.put(...,...); – ControlAltDel 2015-04-01 10:56:18