?? class_entity.php
字號:
<?php/*** Netlands World Server is the coordinator of the VR in the Netlands Project* Copyright (C) 2002 Ricard Pillosu* * This program is free software; you can redistribute it and/or* modify it under the terms of the GNU General Public License* as published by the Free Software Foundation; either version 2* of the License, or (at your option) any later version.* * This program is distributed in the hope that it will be useful,* but WITHOUT ANY WARRANTY; without even the implied warranty of* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the* GNU General Public License for more details.* * You should have received a copy of the GNU General Public License* along with this program; if not, write to the Free Software* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.*//* vim: set expandtab tabstop=4 shiftwidth=4 *//*** Base class for any entity in the VR** The first idea and serious attemps in the OOP by the author. Hope it teach* me the so much commented power of this mean of programming. All instances* of this object are only to be used by entity_list class. Thanks to* {@link mailto:supercoco@menta.net Tony Aguilar} for his concept contribution** @see entity_list** @version $Id: class_entity.php,v 1.4 2002/09/29 12:31:59 doneval Exp $* @author Ricard Pillosu <ricardpillosu@dorna.com>* @copyright Ricard Pillosu 2002* @since Thu, 01 Aug 2002 18:07:16 +0200*/class entity { /** * @var string */ var $key; /** * @var object References to my parent */ var $parent; /** * @var array list of references to my children */ var $childs; /** * @var object the class that counstructed me (type entity_class) */ var $entity_list; /** * @var string the name */ var $type; /** * @var array all "game" related vars (picture, live points, etc...) */ var $game_vars; /** * Init vars * @param object $entity_list the reference to the list where I belong * @param string $key The key to be used by this entity */ function __construct(&$entity_list, $key = NULL) { if(get_class($entity_list) !== "entity_list") { return(FALSE); } $this->entity_list = &$entity_list; if($key === NULL) { $key = $entity_list->create_key(); } $this->key = $key; $this->parent = NULL; $this->childs = array(); $this->type = entity_list::T_NDEF; } /** * Return the "public" vars. */ function get_game_vars() { return($this->game_vars); } /** * Update game vars array */ function update_game_vars($vars_to_update) { $this->game_vars = array_merge($this->game_vars, $vars_to_update); return(TRUE); } /** * Set a parent * * @param object $entity A reference to my new parent */ function set_parent(&$entity) { if($this->entity_list->is_entity($entity) !== TRUE) return(FALSE); $this->parent = &$entity; return(TRUE); } /** * Simply add a reference to a new entity * * @param object $entity */ function add_child(&$entity) { if($this->entity_list->is_entity($entity) !== TRUE) return(FALSE); $key = $entity->get_key(); if(isset($this->childs[$key])) { $msg = "Cannot add duplicate childs to entity"; throw new exception($msg, debug_backtrace(), $key); return(FALSE); } $this->childs[$key] = &$entity; return(TRUE); } /** * Delete a reference to an entity * * @param object $entity */ function del_child(&$entity) { if($this->entity_list->is_entity($entity) !== TRUE) return(FALSE); $key = $entity->get_key(); if(!isset($this->childs[$key])) { $msg = "Cannot delete non-existent child"; throw new exception($msg, debug_backtrace(), $this->key, $key); return(FALSE); } unset($this->childs[$key]); return(TRUE); } function get_childs() { return($this->childs); } /** * Checks if $entity is a child of me */ function is_my_child(&$entity, $exception=TRUE) { if($entity->parent->key != $this->key) { if($exception == TRUE) { $msg = "this is not my child"; throw new exception($msg, debug_backtrace(), $this->key); } return(FALSE); } return(TRUE); } /** * Sends a message to all characters of my own * * @param array $msg */ function send_message_to_childs($msg) { foreach(array_keys($this->childs) as $key) { if($this->childs[$key]->type == entity_list::T_CHAR) { $this->childs[$key]->send_message($msg); } } } function get_key() { return($this->key); } function set_key($key) { $this->key = $key; return(TRUE); }}?>
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -