using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.IO;
using Microsoft.DirectX;
using Microsoft.DirectX.DirectDraw;
using Microsoft.DirectX.DirectSound;

namespace StarGame
{
	/// <summary>
	/// Summary description for GameForm.
	/// </summary>
	public class GameForm : System.Windows.Forms.Form
	{
		private System.Windows.Forms.Panel panelgame;
		/// <summary>
		/// Required designer variable.
		/// </summary>
		private System.ComponentModel.Container components = null;
		public bool bButtonClicked = false;
		public string strButtonClicked = string.Empty;
		public delegate void ButtonEventHandler(object sender, EventArgs e);
		public delegate void KeyEventHandler(object sender, KeyPressEventArgs e);
		public event ButtonEventHandler ButtonEvt;
		public event KeyEventHandler KeyEvt;
		private int nPoints=0;
		public bool bSingleScreen = false;		
		public bool ShowPoints = true;
		public int iRepeatCount=0;
		private string strLastButton="";
		public string ParentGame="";
		private System.Windows.Forms.ProgressBar gameProgress;
        public int indexToNotDisplay;
		public Game game;
		public GameForm(bool SingleScreen)
		{
			//
			// Required for Windows Form Designer support
			//


			bSingleScreen = SingleScreen;
            Screen[] screens = Screen.AllScreens;
              if (screens.Length > 1)
            {

                if (bSingleScreen == true)
                {
                    this.Location = new Point(Screen.PrimaryScreen.Bounds.Width + 3, 0);
                    this.WindowState = FormWindowState.Maximized;
                }
                else
                {

                    int DisplayIndex = 0;
                    int upperBound = screens.GetUpperBound(0);
                    for (DisplayIndex = 0; DisplayIndex < upperBound; DisplayIndex++)
                    {
                        if (screens[DisplayIndex] != Screen.PrimaryScreen)
                            break;
                     
                    }

                    this.Location = new Point(Screen.AllScreens[DisplayIndex].Bounds.Left, Screen.AllScreens[DisplayIndex].Bounds.Top);
                    this.WindowState = FormWindowState.Maximized;
                }
            }
            else
            {
                this.Location = new Point(100, 100);
                this.WindowState = FormWindowState.Maximized;
            }
		
			this.KeyPress += new KeyPressEventHandler(GameForm_KeyPress);
			
			InitializeComponent();
			panelgame.Width = (int)(this.Width ); //80% of window is pic
			panelgame.Height= (int)(this.Height); 
			panelgame.Left = 0;//(int)(this.Width * .28);
			panelgame.Top = 4;
		}
		/// <summary>
		/// Set feedback form
		/// </summary>
		/// <param name="SingleScreen">Display feedback on primary monitor ?</param>
		/// <param name="xy">feedback pic's (x,y)in screen coordinates</param>
		/// <param name="wh">feedback pic's width,height in screen coordinates</param>
		public GameForm (bool SingleScreen,Point xy,Point wh):this (SingleScreen) {
			panelgame.Dock= DockStyle.None;
			panelgame.Width = wh.X; 
			panelgame.Height= wh.Y; 
			panelgame.Left = xy.X;
			panelgame.Top = xy.Y;

		}
		/// <summary>
		/// Clean up any resources being used.
		/// </summary>
		protected override void Dispose( bool disposing )
		{
			if( disposing )
			{
				if(components != null)
				{
					components.Dispose();
				}
			}
			base.Dispose( disposing );
		}

		#region Windows Form Designer generated code
		/// <summary>
		/// Required method for Designer support - do not modify
		/// the contents of this method with the code editor.
		/// </summary>
		private void InitializeComponent()
		{
			this.panelgame = new System.Windows.Forms.Panel();
			this.gameProgress = new System.Windows.Forms.ProgressBar();
			this.SuspendLayout();
			// 
			// panelgame
			// 
			this.panelgame.BackColor = System.Drawing.SystemColors.ControlDarkDark;
			this.panelgame.Dock = System.Windows.Forms.DockStyle.Fill;
			this.panelgame.Location = new System.Drawing.Point(0, 0);
			this.panelgame.Name = "panelgame";
			this.panelgame.Size = new System.Drawing.Size(856, 702);
			this.panelgame.TabIndex = 1;
			// 
			// gameProgress
			// 
			this.gameProgress.Dock = System.Windows.Forms.DockStyle.Top;
			this.gameProgress.Location = new System.Drawing.Point(0, 0);
			this.gameProgress.Name = "gameProgress";
			this.gameProgress.Size = new System.Drawing.Size(856, 16);
			this.gameProgress.TabIndex = 2;
			this.gameProgress.Visible = false;
			// 
			// GameForm
			// 
			this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
			this.ClientSize = new System.Drawing.Size(856, 702);
			this.ControlBox = false;
			this.Controls.Add(this.gameProgress);
			this.Controls.Add(this.panelgame);
			this.Name = "GameForm";
			this.StartPosition = System.Windows.Forms.FormStartPosition.Manual;
			this.Text = "Star";
			this.ResumeLayout(false);

		}
		#endregion
		
		private void Draw()
		{
			if(game!=null)
				game.Draw(PointToScreen(panelgame.Location));
		}

		protected override void OnPaint(PaintEventArgs e)
		{
			base.OnPaint (e);
			if(ParentGame.Equals("PAIRED_COMPARISON"))
				game.ShowOffscreen();
			else Draw();
			
		}
		public void SetTotalGames( int numGames)
		{
			if(numGames <=0)
			{
				gameProgress.Visible = false;
				gameProgress.Maximum = 200;
			}
			gameProgress.Minimum=0;
			gameProgress.Maximum = numGames;
			gameProgress.Step = 1;
			gameProgress.Visible = true;
		}
		public void SetProgressBar ( int val)
		{
			try
			{	gameProgress.Visible = true;
				gameProgress.Value = val;
			}
			catch (Exception ){}
		}
		public void SetupGame(string strDir,string strGame,bool bRandomizeFeedback)
		{
			game = new StarGame.Game();
			game.SetPanel(this.panelgame);
			game.SetSize(panelgame.Size);
			game.LoadGame(strDir,strGame,bRandomizeFeedback);
			gameProgress.Value = 0;
			Draw();
			panelgame.Focus();
		}
		public void SetupGame(string strDir, string strGame)
		{
			game = new StarGame.Game();
			game.SetPanel(this.panelgame);
			game.SetSize(panelgame.Size);
			game.LoadGame(strDir,strGame);
			gameProgress.Value = 0;
			Draw();
			panelgame.Focus();
		}
		public bool Step(bool bPairedComparison)
		{			
			if (bPairedComparison)
			{
				if(game.StepGame(PointToScreen(panelgame.Location),true)==false)
				
				{
					game.Reset();
					return true;
				}
				
				else 
					return true;
				
			}
			return true;
		}
		public bool Step()
		{
			
			if(game.StepGame(PointToScreen(panelgame.Location))==false)
			{
				if(ShowPoints)
				{
					nPoints += game.GetPoints();
					string str = string.Format("You have {0} points! Click Yes to move to next game, or No to play this one again.",nPoints);
					DialogResult r = MessageBox.Show(str,"Game Complete",MessageBoxButtons.YesNo,MessageBoxIcon.Exclamation);
					if(r==DialogResult.Yes)
						return false;
					else
					{
						game.Reset();
						return true;
					}
				}
				else
					return false;
			}			
			else 
				return true;
		}

		public void Finish()
		{
			if(game.Type == GameType.DotToDot || game.Type == GameType.Reveal)
			{
				while(game.StepGame(PointToScreen(panelgame.Location))==true);
			}
		}
		public void DrawButtons(ArrayList Buttons)
		{
			int n=1;
			foreach(Button b in Buttons)
			{
				if(b.Location.X==0&&b.Location.Y==0)
					b.Location = new Point(n*b.Width+n*8,510);
				b.Click += new EventHandler(Button_Click);
				b.KeyPress += new KeyPressEventHandler(b_KeyPress);
				this.Controls.Add(b);
				n++;
			}
			Control c = (Control) panelgame;
			c.KeyPress += new KeyPressEventHandler(b_KeyPress);
		}
		private void Button_Click(object sender, EventArgs e)
		{
			Button b = (Button) sender;
			ButtonTag bt = (ButtonTag) b.Tag;

			strButtonClicked = (string) bt.strCat; 			
		    if(strButtonClicked.ToLower().Equals("repeat"))
				if(strLastButton.ToLower().Equals("repeat"))return; //if previous buttonclicked was also repeat

			strLastButton = strButtonClicked;
		//	if(strButtonClicked.ToLower() == "repeat") iRepeatCount++;
			//else iRepeatCount = 0;
			if(iRepeatCount >= 1) return; // dont allow repetitions more than once
			bButtonClicked = true;
			ButtonEvt(sender, e);
		
			//	panelgame.Focus();
			
		}
		
		private void b_KeyPress(object sender, KeyPressEventArgs e)
		{
			KeyEvt(sender,e);
		}

		private void GameForm_KeyPress(object sender, KeyPressEventArgs e)
		{
			e.Handled = true;
			KeyEvt(sender,e);
		}
		public void LightNextButton()
		{
			foreach(Control c in this.Controls)
			{
				if(c is Button)
				{
					Button b = (Button) c;
					ButtonTag bt = (ButtonTag) b.Tag;
					if(bt.strCat=="next")
						b.BackColor = Color.White;
				}
			}
		}
		public void DarkNextButton()
		{
			foreach(Control c in this.Controls)
			{
				if(c is Button)
				{
					Button b = (Button) c;
					ButtonTag bt = (ButtonTag) b.Tag;
					if(bt.strCat=="next")
						b.BackColor = this.BackColor;
				}
			}
		}
	
		public void SetButtonShade(string btnID,bool on )
		{
			foreach(Control c in this.Controls)
			{
				if(c is Button)
				{
					Button b = (Button) c;
					ButtonTag bt = (ButtonTag) b.Tag;
					if(bt.strCat.Equals(btnID))
					{
						if(on)b.BackColor = Color.Green;
						else b.BackColor=this.BackColor;
					}
					else b.BackColor = this.BackColor;
				}
			}
		}


	
	}
	/// <summary>
	/// Summary description for GameType.
	/// </summary>
	public enum GameType { None, DotToDot, Zap, Reveal, Slideshow };
	/// <summary>
	/// Summary description for Game.
	/// </summary>
	public class Game : object
	{
		private Microsoft.DirectX.DirectDraw.Device draw = null; // Holds the DrawDevice object.
		private SurfaceDescription description;
		private SurfaceDescription description2;
		private Surface primary = null; // Holds the primary destination surface.
		private Surface offscreen = null; // Holds the offscreen surface that the bitmap will be loaded on.
		private Clipper clip = null; // Holds the clipper object.
		private Rectangle destination = new Rectangle();
		private Font font = null;//screen text font;
		private Panel panel;
		public GameType Type;
		private Size size;
		private string strCurrentPic;
		private string strEndPic;
		private ArrayList lstPts;
		private ArrayList MasterList;
		private int nCount;
		private Point lastOrigin;
		private System.Windows.Forms.Timer timer;
		private Color c = Color.Black;

		public Color BackgroundColor;
		public Color ForeColor;
		public Game()
		{
			panel = null;
			BackgroundColor = Color.Black;
			ForeColor = Color.Red;
			Type = 0;

			strCurrentPic = string.Empty;
			Type = GameType.None;
			strEndPic = string.Empty;
			lstPts = new ArrayList();
			nCount=0;

			timer = new Timer();
			timer.Interval = 500;
			timer.Tick += new EventHandler(timer_Tick);
		}
		public int Max(){return lstPts.Count;}
		
		private void SetDescriptions()
		{
			description = new SurfaceDescription(); // Create a new SurfaceDescription struct.
			description.SurfaceCaps.PrimarySurface = true; // The caps for this surface is simply primary.
			description2 = new SurfaceDescription();
			description2.SurfaceCaps.OffScreenPlain = true;
			description2.Height = panel.Height;
			description2.Width = panel.Width;
		}
		private void CreateSurfaces()
		{
			if(primary!=null)
				primary.Dispose();
			primary = new Surface(description, draw); // Create the primary surface.
			clip = new Clipper(draw); // Create a new clipper.
			clip.Window = panel; // The clipper will use the main window handle.
			primary.Clipper = clip; // Assign this clipper to the primary surface.
			
			if(strCurrentPic.Length>0)
			{
				offscreen = new Surface(strCurrentPic,description2, draw); // Create the surface using the specified file.
			}
			else
				offscreen = new Surface(description2, draw); // Create the surface using the specified file.
		}

		public void DisplayWait(int TOT_DELAY)
		{
			TimerForm WaitDisplay = new TimerForm();
		 	WaitDisplay.Location = new Point((size.Width-WaitDisplay.Width)/2,(size.Height-WaitDisplay.Height)/2);
			WaitDisplay.Show();
			WaitDisplay.StopWatch(TOT_DELAY);
			WaitDisplay.Close();
		}
	
		public void BlinkScreen(int TOT_DELAY)
		{	
			try
			{
				Surface tempSurface = new Surface(description2, draw);
				tempSurface.FillColor=Color.DimGray ;
				tempSurface.DrawBox(0,0,size.Width,size.Height);
				primary.Draw(destination, tempSurface, DrawFlags.Wait);
				DisplayWait(TOT_DELAY);
				primary.Draw(destination,offscreen,DrawFlags.Wait);
				tempSurface.Dispose();
				System.Threading.Thread.Sleep(TOT_DELAY/4);
			}
			catch(Exception ){}
		}
		public void BlankScreen(bool blank)
		{
			try
			{
				if(blank)
				{
					offscreen = new Surface(description2,draw);
					offscreen.FillColor=Color.DimGray;
					offscreen.DrawBox(0,0,size.Width,size.Height);
				}
				else offscreen = new Surface(strCurrentPic,description2,draw);
				primary.Draw(destination,offscreen,DrawFlags.Wait);
				Application.DoEvents();
			}
			catch(Exception){}
		}
		public void ShowOffscreen()
		{
			if(offscreen != null) primary.Draw(destination,offscreen,DrawFlags.Wait);
		}
		public void FadeScreen()
		{
			try
			{
				Surface tempSurface = new Surface(description2, draw);
				tempSurface.FillColor=Color.DimGray ;
				tempSurface.DrawBox(0,0,size.Width,size.Height);
				primary.Draw(destination, tempSurface, DrawFlags.Wait);
				tempSurface.Dispose();
			}
			catch(Exception){}
		}
		public void Draw(Point p)
		{
			lastOrigin = p;
			Draw(0);
		}
		public void Draw(int nType)
		{
			try
			{
			if (null == primary)
				return;
			// Get the new client size to Draw to.
			destination = new Rectangle(lastOrigin,size);
			if(description!=null)
			{
				offscreen.ForeColor = Color.Black;
				offscreen.FillColor = Color.White;
				IntPtr ptr;
				ptr = font.ToHfont();
				offscreen.FontHandle = ptr;
				offscreen.DrawWidth = 5;
			
				int x = size.Width;
				int y = size.Height;
				int n = 0;
				//draw points
				if(Type==GameType.Slideshow)
				{ 
					FileInfo f = new FileInfo(strCurrentPic);
					if(f.Exists==false)
					{
						MessageBox.Show("Unable to find picture: " + strCurrentPic);
						return;
					}
					offscreen = new Surface(strCurrentPic,description2, draw);
				}
				else if(Type==GameType.Reveal)
				{
					offscreen.Dispose();
					offscreen = new Surface(strCurrentPic,description2, draw);
					offscreen.ForeColor = Color.White;
					offscreen.FillColor = Color.White;
					foreach(PicPt a in lstPts)
					{
						int X = (int) (x*a.x);
						int Y = (int) (y*a.y);
						int W = (int) (x*(a.x+0.2));
						int H = (int) (y*(a.y+0.2));
						offscreen.DrawBox(X,Y,W,H);
					}
				}
				else
				{
					if(Type==GameType.Zap)
						offscreen.ForeColor = c;
					foreach(PicPt p in lstPts)
					{
						n++;
						if(n==1&&Type==GameType.Zap)
							continue;
						else if(Type==GameType.Zap)
							offscreen.DrawText((int)(x*p.x),(int)(y*p.y),"*",false);
						if(Type==GameType.DotToDot)
							offscreen.DrawText((int)(x*p.x),(int)(y*p.y),"*"+n.ToString(),false);
					}
				
					offscreen.ForeColor = Color.Red;
					//draw line
					if(lstPts.Count>0)
					{
						if(Type==GameType.DotToDot)
						{
							for(int i=0;i<nCount;i++)
							{
								PicPt a,b;
								a = (PicPt)lstPts[i];
								b = (PicPt)lstPts[i+1];
								offscreen.DrawLine((int)(x*a.x),(int)(y*a.y),(int)(x*b.x),(int)(y*b.y));
							}
						}
						
						if(nType==1)//drawing a zap line
						{
							PicPt a,b;
							a = (PicPt)lstPts[0];
							b = (PicPt)lstPts[1];
							//offscreen.DrawLine((int)(x*a.x),(int)(y*a.y),(int)(x*b.x),(int)(y*b.y+5));
							offscreen.DrawLine((int)(x*b.x),(int)(y*b.y+5),(int)(x*a.x),(int)(y*a.y));
						}
					}
				}
			}
				// Try and Draw the offscreen surface on to the primary surface.
				primary.Draw(destination, offscreen, DrawFlags.Wait);
			
			}
			catch(SurfaceLostException)
			{
				// The surface can be lost if power saving
				// mode kicks in, or any other number of
				// reasons.
				CreateSurfaces(); // Surface was lost. Recreate them.
			}
			catch(Exception)
			{
				CreateSurfaces();
			}
			
		}
		public void SetPanel(System.Windows.Forms.Panel panelDraw)
		{
			panel = panelDraw;
			draw = new Microsoft.DirectX.DirectDraw.Device(); // Create a new DrawDevice, using the default device.
			draw.SetCooperativeLevel(panel, CooperativeLevelFlags.Normal); // Set the coop level to normal windowed mode.
			SetDescriptions();
			CreateSurfaces();

		}
		public void SetSize(Size s){size = s;}
		public void LoadGame(string strDir,string strFile,bool bRandomizeFeedback)
		{
			LoadGame(strDir,strFile);
			if(bRandomizeFeedback && Type==GameType.Slideshow)
			{	Random r = new Random(DateTime.Now.Millisecond);
				ArrayList temp = (ArrayList)lstPts.Clone();
				int rand ;
				lstPts.Clear();
				while(temp.Count>0)
				{	rand= r.Next(temp.Count);
					lstPts.Add((string)temp[rand]);
					temp.RemoveAt(rand);
				}	
			}
		}
		public void LoadGame(string strDir, string strFile)
		{
			//assemble txt file name

			string strTxt,strGameFile,strLine= null,strType;
			strTxt = string.Empty;
			if(strFile.IndexOf(".txt")<=0)
				strTxt = strDir + strFile + ".txt";
			else
				strTxt = strDir + strFile;
			//strTxt = strDir + strFile + ".txt";
			StreamReader input = new StreamReader(strTxt);
			//read and parse txt file
			while(input.Peek()>0)
			{
				strLine = input.ReadLine(); //game type
				if(strLine != null)
					break;
			}
			strType = GameParse(strLine);
			strType = strType.ToUpper();
			if(strType=="DOT_TO_DOT")
				Type = GameType.DotToDot;
			else if(strType=="ZAP")
				Type = GameType.Zap;
			else if(strType=="REVEAL")
				Type = GameType.Reveal;
			else if(strType=="SLIDESHOW")
				Type = GameType.Slideshow;

			while(input.Peek()>0)
			{
				strLine = input.ReadLine(); //picture file
				if(!strLine.Equals(String.Empty))break;
			}
			strCurrentPic = GameParse(strLine);
			nCount=0;
			if(Type==GameType.Reveal)
			{
				InitReveal();
				nCount = lstPts.Count;
			}
			else if(Type==GameType.Slideshow)
			{
				FileInfo f = new FileInfo(strLine);
				
                //string []sfiles = Directory.GetFiles(f.DirectoryName);
                //foreach(string s in sfiles)
                //AddPic(s);

                AddPic(strLine);
                while(input.Peek()>0 )
                {
                    strLine = input.ReadLine();
                    AddPic(strLine);
                }
				nCount = 0;
			}
			else
			{
				if(Type==GameType.DotToDot)
				{
					strEndPic = GameParse(input.ReadLine());
				}
				else if(Type==GameType.Zap)
				{
					strLine = input.ReadLine();
					strLine = strLine.Substring(0,strLine.Length-1);
					c = Color.FromName(strLine);
				}
			
				//setup picture
				strGameFile = strDir + strFile;
				//read points
				strLine = input.ReadLine();
				while(strLine != null)
				{
					AddPoints(strLine);
					strLine = input.ReadLine();
				}
			}
			

			if(Type==GameType.Zap)
				font = new Font("Arial",18);
			else
				font = new Font("Arial",7);
			offscreen = new Surface(strCurrentPic,description2, draw);
			MasterList = (ArrayList) lstPts.Clone();
			Draw(0);
		}
		private string GameParse(string str)
		{
			int n;
			n = str.IndexOf(';');
			if(n>0)
				str = str.Substring(0,n);
			str = str.Replace(';',' ');
			str = str.Trim();
			return str;
		}

		private void InitReveal()
		{
			double x = 0.0;
			double y = 0.0;
			for(int i=0;i<5;i++)
			{
				x = 0.0;
				for(int j=0;j<5;j++)
				{
					lstPts.Add(new PicPt(x,y));
					x+=0.2;
				}
				y+=0.2;
			}
		}
		private void AddPoints(string str)
		{
			str = str.Trim();
			if(str.IndexOf("%")==0)
				return;
			int n = str.IndexOf(';');
			if(n>0)
				str = str.Substring(0,n);
			n = str.IndexOf(' ');
			if(n<0)
				return;
			string str1, str2;
			str1 = str.Substring(0,n);
			str2 = str.Substring(n+1);
			lstPts.Add(new PicPt(double.Parse(str1.Trim()),1-double.Parse(str2.Trim())));
		}
		private void AddPic(string str)
		{
			str = str.Trim();
			if(str.IndexOf("%")==0)
				return;
			int n = str.IndexOf(';');
			if(n>0)
				str = str.Substring(0,n);
			str = str.Trim();
			if(str.Length>0)
				lstPts.Add(str);
		}
		public bool StepGame(Point p,bool bPairedComp)
		{
			lastOrigin = p;
			if(bPairedComp)
			{  
				nCount++;
				if(nCount >= lstPts.Count -1)return false;
				strCurrentPic = (string)lstPts[nCount];
				return true;
			}
			else return false;
		}
		public bool StepGame(Point p)
		{
			lastOrigin = p;
			if(Type==GameType.Slideshow)
			{
				nCount++;
				if(nCount>=lstPts.Count-1)
					return false;
				strCurrentPic = (string)lstPts[nCount];
				this.Draw(0);
				return true;
			}
			else if((Type!=GameType.Reveal&&nCount<Max()-1) ||
				(Type==GameType.Reveal&&lstPts.Count>0))
			{
				if(Type==GameType.DotToDot)
				{
					nCount++;
					this.Draw(0);
				}
				else if(Type==GameType.Zap)
				{
					//Show Red Line
					this.Draw(1);
					//Wait
					timer.Start();
				}
				else if(Type==GameType.Reveal)
				{
					Random r = new Random(DateTime.Now.Millisecond);
					int x = r.Next(lstPts.Count-1);
					PicPt pic = (PicPt) lstPts[x];
					lstPts.RemoveAt(x);
					
					int Count = 0;
					PicPt a = null;
					PicPt b = null;

					for(int i=0;i<lstPts.Count;i++)
					{
						PicPt pt = (PicPt) lstPts[i];
						if(a==null)
						{
							if(pt.y==pic.y)
							{
								if(pt.x==pic.x+0.1)//one to the right
								{
									if(r.Next(2)==1)
										continue;
									Count++;
									a = pt;
								}
								else if(pt.x==pic.x-0.1)//one to the left
								{
									Count++;
									a = pt;
								}
							}
						}
						if(b==null)
						{
							if(pt.x==pic.x)
							{
								if(pt.y==pic.y+0.1)//one to the right
								{
									if(r.Next(2)==1)
										continue;
									Count++;
									b = pt;
								}
								else if(pt.y==pic.y-0.1)//one to the right
								{
									Count++;
									b = pt;
								}
							}
						}
					}//for
					if(a!=null)
					{
						lstPts.Remove(a);
					}
					if(b!=null)
					{
						lstPts.Remove(b);
					}
					this.Draw(0);
				}
			}
			if(Type!=GameType.Reveal)
			{
				if(nCount>=Max()-1)
				{
					//Get next Game
					if(Type==GameType.DotToDot)
						ShowDotPic();
					return false;
				}
			}
			else
			{
				if(lstPts.Count==0)
				{
					this.Draw(0);
					return false;
				}
			}
			return true;
		}
		public void Reset()
		{
			nCount=0;
			lstPts = (ArrayList)MasterList.Clone();
			strCurrentPic = (string)lstPts[nCount];
			this.Draw(0);
		}

		private void ShowDotPic()
		{
			//Show Full Pic
			description.Clear(); // Clear the SurfaceDescription struct.
			offscreen = new Surface(strEndPic, description, draw);
			lstPts.Clear();
			this.Draw(2);
			//Wait
			System.DateTime dt = System.DateTime.Now;
			System.DateTime d2;
			do
			{
				d2 = System.DateTime.Now;
			}while(d2.Minute==dt.Minute&&d2.Second-dt.Second<2);
			//wait 1-2 seconds
			//go to next game
			//this.Draw(2);*/

		}
		public int GetPoints()
		{
			return MasterList.Count;
		}

		private void timer_Tick(object sender, EventArgs e)
		{
			timer.Stop();
			lstPts.RemoveAt(1);
			offscreen = new Surface(strCurrentPic, description2, draw); // Create the surface using the specified file.
			this.Draw(2);
		}
	}
	/// <summary>
	/// Summary description for PicPt.
	/// </summary>
	public class PicPt : object
	{
		public double x;
		public double y;
		public bool bDraw;
		public PicPt(double a, double b)
		{
			x = a;
			y = b;
			bDraw = true;
			
		}
		
	}
	
}
