project_files/Android-build/SDL-android-project/src/org/hedgewars/hedgeroid/Datastructures/TeamIngameAttributes.java
changeset 7476 2fb781bbdd51
child 7485 0481bd74267c
equal deleted inserted replaced
7473:45b9f25ff611 7476:2fb781bbdd51
       
     1 package org.hedgewars.hedgeroid.Datastructures;
       
     2 
       
     3 import java.util.ArrayList;
       
     4 import java.util.Random;
       
     5 
       
     6 public final class TeamIngameAttributes {
       
     7 	public static final int[] TEAM_COLORS = {
       
     8 		0xd12b42, /* red    */ 
       
     9 		0x4980c1, /* blue   */ 
       
    10 		0x6ab530, /* green  */ 
       
    11 		0xbc64c4, /* purple */ 
       
    12 		0xe76d14, /* orange */ 
       
    13 		0x3fb6e6, /* cyan   */ 
       
    14 		0xe3e90c, /* yellow */ 
       
    15 		0x61d4ac, /* mint   */ 
       
    16 		0xf1c3e1, /* pink   */ 
       
    17 		/* add new colors here */
       
    18 	};
       
    19 	
       
    20 	public final String ownerName;
       
    21 	public final int colorIndex, hogCount;
       
    22 	public final boolean remoteDriven;
       
    23 	
       
    24 	public TeamIngameAttributes(String ownerName, int colorIndex, int hogCount, boolean remoteDriven) {
       
    25 		this.ownerName = ownerName;
       
    26 		this.colorIndex = colorIndex;
       
    27 		this.hogCount = hogCount;
       
    28 		this.remoteDriven = remoteDriven;
       
    29 	}
       
    30 	
       
    31 	public static int randomColorIndex(int[] illegalColors){
       
    32 		Random rnd = new Random();
       
    33 		ArrayList<Integer> legalcolors = new ArrayList<Integer>();
       
    34 		for(int i=0; i<TEAM_COLORS.length; i++) {
       
    35 			legalcolors.add(i);
       
    36 		}
       
    37 		for(int illegalColor : illegalColors) {
       
    38 			legalcolors.remove(Integer.valueOf(illegalColor));
       
    39 		}
       
    40 		if(legalcolors.isEmpty()) {
       
    41 			return rnd.nextInt(TEAM_COLORS.length);
       
    42 		} else {
       
    43 			return legalcolors.get(rnd.nextInt(legalcolors.size()));
       
    44 		}
       
    45 	}
       
    46 	
       
    47 	public TeamIngameAttributes withColorIndex(int colorIndex) {
       
    48 		return new TeamIngameAttributes(ownerName, colorIndex, hogCount, remoteDriven);
       
    49 	}
       
    50 	
       
    51 	public TeamIngameAttributes withHogCount(int hogCount) {
       
    52 		return new TeamIngameAttributes(ownerName, colorIndex, hogCount, remoteDriven);
       
    53 	}
       
    54 
       
    55 	@Override
       
    56 	public String toString() {
       
    57 		return "TeamIngameAttributes [ownerName=" + ownerName + ", colorIndex="
       
    58 				+ colorIndex + ", hogCount=" + hogCount + ", remoteDriven="
       
    59 				+ remoteDriven + "]";
       
    60 	}
       
    61 }