playing card classes in php...

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

 





This is my first time trying to use php to do Object Oriented 
programming (not that my OO experience is very extensive as it is)..
I'm trying to write a card game, but I'm running into trouble in 
places I thought OO languages would work..

Of course, to make any card game you need to start with a card, so I 
have:

class card{
  var $value;
  var $suit;
  function card($invalue=0,$insuit=0)  {
    $this->value = $invalue;
	$this->suit = $insuit;
  }
  function display()  {
   echo "<img src=images/";
   echo $this->value;
   echo $this->suit;
   echo ".gif>";
   }
}

and from this I would like to make a deck, but I seem to be running 
into trouble..  is there a way to make a function return an object?
I'd like my deck class to return a card that you draw from it, but 
this basic example doesn't seem to work:
class deck
{
  function draw()
  {
    return new card(a,s);
   }
}

I would have thought from the documentation I've read that these two 
classes would allow me to do:
$mine = new card(5,c);
$mine->display();
$mine2 = d->draw();
$mine2->display();

Can someone give me a little more insight into how objects work in 
PHP or at least point me to a better resource for reading? (I've 
checked the online php documentation at php.net, and I have a php 
book lying around but neither show me what I'm doing wrong)

-Thanks
=Nate








PHP Data object relational mapping generator - http://www.meta-language.net/ 
Yahoo! Groups Links

<*> To visit your group on the web, go to:
    http://groups.yahoo.com/group/php-objects/

<*> To unsubscribe from this group, send an email to:
    php-objects-unsubscribe@xxxxxxxxxxxxxxx

<*> 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