[messages] Edit: Re: [Module Design] Custom java class that deals with GamePieces

Mu0n micjuneau at gmail.com
Tue Feb 7 17:48:31 CET 2017


[This message has been edited.]

__New successes:__

I can spawn stuff on the map! I'm using this piece of code but I'm not
sure if I'm following best practices here:


Code:
        

String listOfPieceSlots = "";
PieceSlot biggs = new PieceSlot();
GameModule mod = GameModule.getGameModule();

int counter = 1;
for(PieceSlot slot:
GameModule.getGameModule().getAllDescendantComponentsOf(PieceSlot.class))
{
       listOfPieceSlots += "#:" + Integer.toString(counter) + " gpuId:"
+slot.getGpId() + " " + slot.getConfigureName() + "\n";
       if(slot.getGpId().equals("15")) {
           Point pos = new Point (150, 153);
           GamePiece biggsGP = slot.getPiece();

           List<Map> mapList = Map.getMapList();
           biggsGP.setMap(mapList.get(0)); //this will be less clunky in
a final version
           biggsGP.setPosition(pos);

           JOptionPane.showMessageDialog(null,biggsGP.getName() + " "
                           + biggsGP.getPosition().toString() + " "
                            + biggsGP.getMap().getMapName(),  "Biggs
checks",
                   JOptionPane.PLAIN_MESSAGE);

           Command place = mapList.get(0).placeOrMerge(biggsGP,pos);
//not sure if the earlier setPosition was enough or useless
           place.execute();
           mod.sendAndLog(place);

           break;
       }
       counter++;
       }

Command c = new
Chatter.DisplayText(mod.getChatter(),listOfPieceSlots); //wanted to see
if the detection went well
c.execute();
mod.sendAndLog(c);



_______________________________________________
Read this topic online here:
http://www.vassalengine.org/forum/viewtopic.php?p=53014#p53014


More information about the messages mailing list