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]); } } }
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; }