/*
Tiamat - a role-playing game framework
BaseGameState.java - base game state
    
 Copyright  (C) 2006 Hugues Johnson
 
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.
*/

package com.huguesjohnson.tiamat;

import com.huguesjohnson.serialization.Storable;
import java.util.ArrayList;

/** BaseGameState - base game state
 * @author Hugues Johnson
 */
public abstract class BaseGameState implements Storable{

/* begin private properties */
    //conditions is a list of things that have happened in the game
    private ArrayList<String> conditions;
/* end private properties */
    
/* begin constructors */
    /** Creates an empty BaseGameState.
     */
    public BaseGameState(){ 
        this.conditions=new ArrayList<String>();
    }
    /** Creates a BaseGameState with conditions.
     * @param conditions The initial conditions for this BaseGameState.
     */
    public BaseGameState(String[] conditions){ 
        this.conditions=new ArrayList<String>();
        int length=conditions.length;
        for(int index=0;index<length;index++){
            this.addCondition(conditions[index]);
        }
    }
/* end constructors */
    
/* begin public methods */
    /** Add a condition (something that has happened in the game).
     * @param condition The condition to add.
     */
    public void addCondition(String condition){
        this.conditions.add(condition);
    }
    /** Returns all conditions (things that have happened in the game).
     * @return A string array of all conditions (things that have happened in the game).
     */
    public String[] getConditions(){
        return(this.conditions.toArray(new String[0]));
    }
    /** Tests if a specific condition has occured.
     * @param condition The condition to search for.
     * @return True if the specified condition has occured.
     */
    public boolean hasCondition(String condition){
        boolean hascondition=false;
        String[] allConditions=this.getConditions();
        int length=allConditions.length;
        int count=0;
        while((count<length)&&(!hascondition)){
            if(condition.equals(allConditions[count])){
                hascondition=true;
            } else{
                count++;
            }
        }
        return(hascondition);
    }
/* end public methods */ 
}