Page 1 of 1

Assigning limited player colors

Posted: 24 January 2021, 00:55
by BrianLovesMarvel
Dear gurus,

I have game graphics with red, green, blue, yellow pieces and I want to use just those colors.
I've tried assigning them in setupNewGame() (see below), but I always seem to get blue and red. :?
What's the proper way to assign player colors, if I have a limited, predefined color set to work with? :?:
Also, what happens with the reattributeColorsBasedOnPreferences()?
I tried looking for information about this, but I didn't find any in the doc or the forums.

Thanks, Brian

Code: Select all

	protected function setupNewGame( $players, $options = array() )
	{	
		// Set the colors of the players with HTML color code
		// The default below is red/green/blue/orange/brown
		// The number of colors defined here must correspond to the maximum number of players allowed for the gams
		$gameinfos = self::getGameinfos();
		$default_colors = $gameinfos['player_colors'];
		$my_colors = array( "red", "yellow", "blue", "green" ); // these are my colors
 
		// Create players
		// Note: if you added some extra field on "player" table in the database (dbmodel.sql), you can initialize it there.
		$sql = "INSERT INTO player (player_id, player_color, player_canal, player_name, player_avatar) VALUES ";
		$values = array();
		foreach( $players as $player_id => $player )
		{
			//$color = array_shift( $default_colors );
			$color = array_shift( $my_colors ); // assign from the list of colors available
			$values[] = "('".$player_id."','$color','".$player['player_canal']."','".addslashes( $player['player_name'] )."','".addslashes( $player['player_avatar'] )."')";
		}
		$sql .= implode( $values, ',' );
		self::DbQuery( $sql );
		self::reattributeColorsBasedOnPreferences( $players, $gameinfos['player_colors'] ); // what is happening here?
		self::reloadPlayersBasicInfos();

Re: Assigning limited player colors

Posted: 24 January 2021, 01:26
by Victoria_La
Do not modify the setup code at all, leave the template as it.
The colors have to be in html notation not in english
If you want to modify shades of colors use gameinfo file where color list is defined.
Do not switch this to english, red has to be 'ff0000' (or 'ff5555' but not 'red')

// Colors attributed to players
'player_colors' => array( "ff0000", "008000", "0000ff", "ffa500" ),

If you start game with 2 player it will give you first 2 colors, I am not sure why you expecting 4?
If you want it more random, you can shuffle it

Code: Select all

  $default_colors = $gameinfos['player_colors'];
  shuffle($default_colors); // <-- the only line you add there
  ...
  

Re: Assigning limited player colors

Posted: 24 January 2021, 03:03
by BrianLovesMarvel
Thank you, I see it now!

Only expecting two colors for a two player game :)

Brian