Esempio n. 1
0
  public void setUpGroups() {

    this.groups = game.getGroups();
    Color[] groupToColor = new Color[groups.length];
    for (int i = 0; i < groupToColor.length; i++) {
      groupToColor[i] = possibleColors[i % possibleColors.length];
    }

    for (int i = 0; i < groupToColor.length; i++) {
      Group[] conflictingGroups;
      conflictingGroups = conflicting(i, groupToColor);

      int noOfTimes = 0;

      while (conflictingGroups.length != 0) {
        int offset;
        if (noOfTimes > 5) offset = 3;
        else offset = 2;

        groupToColor[conflictingGroups[0].groupIDX] =
            possibleColors[(conflictingGroups[0].groupIDX + offset) % possibleColors.length];
        conflictingGroups = conflicting(i, groupToColor);
        noOfTimes++;
      }
    }

    for (int i = 0; i < groups.length; i++) {
      Space[] groupSpaces = groups[i].getSpaces();
      for (int j = 0; j < groupSpaces.length; j++) {
        Space current = groupSpaces[j];
        GUILogi5Space currentSpace = (GUILogi5Space) (spaces[current.getX()][current.getY()]);
        currentSpace.setColor(groupToColor[i]);
      }
    }
  }
Esempio n. 2
0
 private Group[] conflicting(int ish, Color[] groupToColor) {
   ArrayList<Group> touchers = new ArrayList<Group>();
   Group g = groups[ish];
   Space[] gSpaces = g.getSpaces();
   for (int i = 0; i < gSpaces.length; i++) {
     Space current = gSpaces[i];
     for (int k = -1; k < 2; k++) {
       int curSX = current.getX();
       int curSY = current.getY();
       curSX += k;
       curSY += k;
       if (curSX < 0) {
         curSX = 0;
       }
       if (curSX > spaces.length - 1) {
         curSX = spaces.length - 1;
       }
       if (curSY < 0) {
         curSY = 0;
       }
       if (curSY > spaces.length - 1) {
         curSY = spaces.length - 1;
       }
       Space[] comparison = new Space[2];
       comparison[0] = game.getSpaceAt(curSX, current.getY());
       comparison[1] = game.getSpaceAt(current.getX(), curSY);
       int mod = groupToColor.length;
       for (int j = 0; j < comparison.length; j++) {
         if ((comparison[j].getGroup().groupIDX != g.groupIDX)
             && groupToColor[comparison[j].getGroup().groupIDX % mod]
                 == groupToColor[current.getGroup().groupIDX % mod]
             && !touchers.contains(comparison[j].getGroup())) {
           touchers.add(comparison[j].getGroup());
         }
       }
     }
   }
   return touchers.toArray(new Group[touchers.size()]);
 }