Example #1
0
  public GUILogi5Board(Game game) {

    this.game = game;
    dim = game.getDimensions()[0];

    setLayout(new GridLayout(dim, dim));
    spaces = new JButton[dim][dim];

    for (int i = 0; i < spaces.length; i++) {
      for (int j = 0; j < spaces[i].length; j++) {

        Space otherSpace = game.getSpaceAt(i, j);

        GUILogi5Space spacey = new GUILogi5Space(i, j, spaceSize);
        int[] loc = spacey.getDims();
        spacey.setSpace(game.getSpaceAt(loc[0], loc[1]));
        spaces[i][j] = spacey;
        add(spacey);
      }
    }
    setBorder(BorderFactory.createLineBorder(Color.black));
    setPreferredSize(new Dimension(spaceSize * spaces.length, spaceSize * spaces[0].length));
    setMaximumSize(new Dimension(spaceSize * spaces.length, spaceSize * spaces[0].length));

    int num = 255;
    Color[] colors = new Color[6];
    for (int i = 0; i < colors.length; i++) {
      colors[i] = new Color(num, num, num, 220);
      num -= 30;
    }

    possibleColors = colors;
  }
Example #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()]);
 }