Äventyrsspel | Visa källkod | XHTML | CSS | How to become a hacker | Hangman | Tärning | HighLow | Sök Kompis

Visa källkod

Nedanstående filer finns i denna katalogen. Klicka på en fil för att visa dess innehåll.

adventure08/highlow

CCard.php
CCardHand.php
CDeck.php
CHighCardLowCard.php
ISessionDestroy.php
card.php
common.php
deck.php
hand.php
highlow.php
session.php
source.php
template.php

CHighCardLowCard.php
<?php
// ===========================================================================================
//
// CHighCardLowCard.php
//
// Description: A class for playing the game of High Card Low Card
//
// Author: Mikael Roos
//

require_once("CDeck.php");
require_once("CCardHand.php");

class CHighCardLowCard {  

    // -------------------------------------------------------------------------------------------
    //
    // Member variables
    //
    //
    private $iDeck;        // An instance of CDeck
    private $iHand;        // An instance of CCardHand


    // -------------------------------------------------------------------------------------------
    //
    // Constructor
    // http://www.php.net/manual/en/language.oop5.decon.php
    //
    function __construct() {
        $this->iDeck = new CDeck(); 
        $this->iHand = new CCardHand();
    }


    // -------------------------------------------------------------------------------------------
    //
    // Destructor
    // http://www.php.net/manual/en/language.oop5.decon.php
    //
    function __destruct() {
        ;
    }


    // -------------------------------------------------------------------------------------------
    //
    // Start the game.
    //
    public function StartGame() {
        $this->iDeck->InitAndShuffle();
        $this->iHand->DropAllCards();
        $card = $this->iDeck->DealFromTop();
        $card->FlipCard();
        $this->iHand->AddCard($card);
        //$this->iHand->AddCard($this->iDeck->DealFromTop()); // Add next card faced down, looks nicer
    }


    // -------------------------------------------------------------------------------------------
    //
    // Guess and pick a card. Check if card value is higher or lower.
    // Take argument to check wether new card is to be higher or lower.
    // Check according to argument and return TRUE or FALSE
    //
    public function GuessAndPickCard($aGuess) {
        $card1 = $this->iHand->GetLastCard();
        $card2 = $this->iDeck->DealFromTop();
        $card2->FlipCard();
        $this->iHand->AddCard($card2);
        
        $value1 = $card1->GetValue();
        $value2 = $card2->GetValue();
        
        if($value1 == 0 || $value2 == 0)
            return TRUE;
        
        $success = FALSE;
        switch($aGuess) {
            case 'high': {
                $success = ($value2 >= $value1);
            }
            break;
            
            case 'low': {
                $success = ($value2 <= $value1);
            }
            break;
        }
        
        return $success;
    }


    // -------------------------------------------------------------------------------------------
    //
    // Return the points which is equal to the number of cards in the cardhand.
    //
    //
    public function GetPoints() {
        return $this->iHand->GetNoCards() - 1;
    }


    // -------------------------------------------------------------------------------------------
    //
    // Show HTML for the current game status.
    //
    //
    public function ShowGameStatus() {
        return $this->iHand->GetCardsAsBox();
    }


} // End of class

?>
 .                        
..:    © Mikael Roos, 2009