Assigning limited player colors
Posted: 24 January 2021, 00:55
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
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();