// AP Computer Science Marine Biology Case Study program
// Copyright (C) 2000  College Board and Educational Testing Service

// 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.

// 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.

// fishsim.cpp - copyright statement added 5/31/2000

// Revision history
//     All references to "apxxxxxx.h" changed to <apxxxxxx.h>
//					Tim Corica 12/1/2000

// Lawrenceville Press graphics library support added 2/1/2001
// by Tim Corica

#include <gui_lib.h>
#include <iostream.h>
#include <fstream.h>
#include <apstring.h>
#include "environ.h"
#include "display.h"
#include "simulate.h"



class FishSim: public GuiClass
 	{
	public:
		void paint(Graphics &g);
		FishSim();
		bool timerEvent(TimerEvent e);
		bool mouseClicked(MouseEvent e);

	private:
		ifstream input;
		Environment env;

		Display display;
		apstring s;

		Simulation sim;
		int step;
		int numSteps;
		Timer refreshTimer;
		
};
//--------------------------------------------------------------------------------
FishSim::FishSim():
	input("fish.dat"),
	env(input),
	display("Case Study Fish Simulation", env ),
	refreshTimer(100)  // N millisecond updates
{
  refreshTimer.setEnabled(true);
}

void FishSim::paint(Graphics &g)
{
	g.setFont(Font("Times New Roman", Font::PLAIN, 20));
	g.drawString("Click mouse to stop/start motion", 2*getCanvasWidth()/10, 95*getCanvasHeight()/100);
	display.Show(env,g);
}


bool FishSim::timerEvent(TimerEvent e)
{
	sim.Step(env);
    
	repaint(false);
	return(true);
	
}


bool FishSim::mouseClicked(MouseEvent e)
{
	// toggle refreshTimer (enabled <--> not enabled)
	refreshTimer.setEnabled(!refreshTimer.isEnabled());
	return(true);
}




//--------------------------------------------------------------------------------
int GuiMain()
{
	AddToGuiList(new FishSim());
	return 0;
}	

