php basics

Saturday, June 17, 2006

Assignment: Knights and Knaves

Create 9 scripts.

Script 1: class.Player.php
  • Defines a player. Must contain the following attributes :

    • public static $teams = array("knight", "knave");
    • public static $names = array("Larry", "Curly", "Moe");
    • private $_name;
    • private $_team;
    • private $_wins;

  • Names must be declared with at least 3 names of your choosing.

  • Provide a constructor that takes a string name and string team as parameters.
    • The constructor should check the validity of the incoming parameters, including ensuring the team paramater matches one within the $teams array.

  • If all incoming data is valid initialize all non static variables appropriately.

  • Provide public accessor methods for $_name, $_team, and $_wins
    • A public accessor method is just a method that retursn info
    • public function getTeamName()
      {
      return $this->_team;
      }

  • provide the following functions:
    • win() //increases the number of $_wins by one
    • play() //returns a randomly generated number from 0-10 (inclusive) simulates rolling a 10 sided die

0 Comments:

Post a Comment

<< Home