RE: [php-objects] collections

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



> A collection of what? 

This is a good question.  I recently did this with a
solitaire game I've been working on as a way of
learning PHP-GTK. I created a class to represent piles
of cards across the bottom of the playing screen.
There are eight piles. I refer to one of them using
$p[$x]->pileMethod(). 

This is what I did...

function create_piles($deck)
	{
	$x=1;
	$piles=array();
	while($x<9)
		{ 
		$piles[$x]=new Pile($x, &$deck); 
		++$x;
		}
	return $piles;	
	}

So, he can create an array of objects, but he's going
to need to pass that object a meaninful name so that
it's easily referred to in the array. Instead of ...

>    $objArray[] = new Object;

perhaps something like...

$objArray[$x] = new Object($x);

This approach would prolly make it easier to manage an
array of instantiated objects, but more of the details
of a mechanism for this sort of thing depends on
exactly what's being done.  The above also assumes
that something in the constructor is taking the passed
$x and treating it as a name of itself and perhaps
doing something else based on what that $x value is.

For the card game, it's no big deal to manage objects
in the array as each clicked on pile has an associated
call back function to the correct pile. Click on pile
8 on the screen and something happens at $p[8] (which
is an object) in the code. 

So, we would need more details to begin to figure out
a good way of managing this array of objects. 

Cheers,
Terrence (BDKR)

__________________________________________________
Do you Yahoo!?
Yahoo! Tax Center - forms, calculators, tips, more
http://taxes.yahoo.com/


------------------------ Yahoo! Groups Sponsor ---------------------~-->
Get 128 Bit SSL Encryption!
http://us.click.yahoo.com/FpY02D/vN2EAA/xGHJAA/saFolB/TM
---------------------------------------------------------------------~->

Look here for Free PHP Classes of objects:
http://phpclasses.UpperDesign.com/
To unsubscribe from this group, send an email to:
php-objects-unsubscribe@egroups.com

 

Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/ 



[Index of Archives]     [PHP Home]     [PHP Users]     [PHP Soap]     [Kernel Newbies]     [Yosemite]     [Yosemite Campsites]

  Powered by Linux