Exemple #1
0
        static void Main(string[] args)
        {
            DrawingPanel panel = new DrawingPanel(800, 500);
            Graphics     g     = panel.GetGraphics();
            int          a     = 0;

            while (a == 0)
            {
                MovingSnake(g, panel, x, y, keyData, fruitX, fruitY);
            }

            DrawingPanel.Pause();
        }
Exemple #2
0
 /// <summary>
 /// Constructs a DrawPanel object that creates a window,
 /// which shows the AI's training progress on a graph.
 /// </summary>
 /// <param name="sticks">number of sticks the user choose</param>
 /// <param name="chips">number of sticks the user can choose</param>
 /// <param name="name">Name of the AI</param>
 public DrawPanel(int sticks, int chips, string name)
 {
     this.sticks = sticks;
     this.chips  = chips;
     this.name   = name;
     this.margin = this.subMargin * this.chips;
     this.width  = this.margin * this.sticks;
     // Makes a canvas with set width and height based on calculations above
     this.p = new DrawingPanel(this.width, this.height);
     this.g = p.GetGraphics();
     FixedGraphics();
     Labels();
 }
Exemple #3
0
 /// <summary>
 /// Reads the appropriate state file and converts the
 /// coordinate information into an array to be drawn.
 /// </summary>
 /// <param name="stateName">state name</param>
 /// <param name="electionYear">election year</param>
 static void Region(string stateName, int electionYear)
 {
     using (StreamReader sr = new StreamReader(FilePath + stateName + ".txt"))
     {
         string[] min = sr.ReadLine().Split
                            (new char[0], StringSplitOptions.RemoveEmptyEntries);      // removes empty spaces
         float    minLong = float.Parse(min[0]);
         float    minLat  = float.Parse(min[1]);
         string[] max     = sr.ReadLine().Split
                                (new char[0], StringSplitOptions.RemoveEmptyEntries);
         float maxLong = float.Parse(max[0]);
         float maxLat  = float.Parse(max[1]);
         // min is scaled down to coordinate (0,0),
         // and max is scaled down to an appropriate size
         int width  = (int)(Scale * (maxLong - minLong));
         int height = (int)(Scale * (maxLat - minLat));
         // initializes the drawing panel according to the scaled size
         DrawingPanel dp          = new DrawingPanel(width, height);
         Graphics     g           = dp.GetGraphics();
         int          numPolygons = int.Parse(sr.ReadLine());
         sr.ReadLine();
         while (!sr.EndOfStream)
         {
             string   subregionName = sr.ReadLine();
             string   regionName    = sr.ReadLine();
             PointF[] pts           = new PointF[int.Parse(sr.ReadLine())];
             for (int i = 0; i < pts.Length; i++)
             {
                 string[] loc = sr.ReadLine().Split
                                    (new char[0], StringSplitOptions.RemoveEmptyEntries);
                 // scale algorithm
                 float x = Scale * (float.Parse(loc[0]) - minLong);
                 float y = Scale * (float.Parse(loc[1]) - minLat);
                 pts[i].X = x;
                 pts[i].Y = height - y;
             }
             // Initilizes the Region class to the get the fill color
             // based on the election result the user-specified year;
             // gets the color for each subregion at a time until
             // all data for the subregions of the region are read
             Region region = new Region(regionName, subregionName, electionYear);
             Draw(dp, g, region, pts);
             sr.ReadLine();
         }
         dp.RefreshDisplay();                 // updates the drawing panel
     }
 }