コード例 #1
0
ファイル: Grid.cs プロジェクト: FrankSylvia/MobileRobot
        public void dump()
        {
            for (int r = 0; r < this.rows; r++)
            {
                for (int c = 0; c < this.cols; c++)
                {
                    if (array[r, c] != null)
                    {
                        Obstruction ob = (Obstruction)getLocationObject(r, c);


                        Console.WriteLine(r.ToString() + "," + c.ToString() + " " + ob.GetType().ToString());
                    }
                }
            }
        }
コード例 #2
0
ファイル: Grid.cs プロジェクト: FrankSylvia/MobileRobot
        public void populate(String filename)
        {
            StreamReader reader = null;

            try
            {
                reader = new StreamReader(File.OpenRead(filename));
                while (!reader.EndOfStream)
                {
                    var line = reader.ReadLine();
                    if (line.Length < 2)
                    {
                        continue;
                    }
                    var values = line.Split(',');
                    int r      = Convert.ToInt32(values[1]);
                    int c      = Convert.ToInt32(values[2]);

                    if ((r >= this.rows) || (c >= this.cols))
                    {
                        Console.WriteLine("Obstruction location is out of bounds" + line);
                        continue;
                    }

                    Obstruction temp = (Obstruction)getLocationObject(r, c);
                    if (temp != null)
                    {
                        Console.WriteLine("Warning: Overlaying Obstruction at location " + values[1] + "," + values[1]);
                    }

                    if (values[0] == "Rock")
                    {
                        ob = new Rock(values[0], values[1], values[2]);
                        setLocationObject(r, c, ob);
                    }
                    else if (values[0] == "Spinner")
                    {
                        ob = new Spinner(values[0], values[1], values[2], values[3]);
                        setLocationObject(r, c, ob);
                    }
                    else if (values[0] == "Hole")
                    {
                        int endr = Convert.ToInt32(values[4]);
                        int endc = Convert.ToInt32(values[5]);

                        if ((endr >= this.rows) || (endc >= this.cols))
                        {
                            Console.WriteLine("Hole destination location is out of bounds" + line);
                            continue;
                        }
                        ob = new Hole(values[0], values[1], values[2], values[4], values[5]);
                        setLocationObject(r, c, ob);
                    }
                    else
                    {
                        Console.WriteLine("Invalid Obstruction type: " + line);
                    }
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e.ToString());
            }
            finally
            {
                if (reader != null)
                {
                    reader.Close();
                }
            }
        }