Пример #1
0
        public Map(bool[] newwallMap, int mapwidth, HashSet <Actor> newactors, Dictionary <Node, char> newboxes, GoalList newgoals, Dictionary <char, Color> colorDict)
        {
            id       = Map.nextId++;
            wallMap  = newwallMap;
            mapWidth = mapwidth;
            HashSet <Color> newactorcolors = new HashSet <Color>(); int i = 0;

            foreach (Actor a in newactors)
            {
                newactorcolors.Add(colorDict[i.ToString()[0]]);
                i++;
            }

            actors = new ActorList(newactors, newactorcolors);
            boxes  = new BoxList(newboxes, colorDict);
            goals  = newgoals;
            steps  = 0;

            /*
             * for (int j = 0; j<wallMap.Count(); j++)
             * {
             *  if (j%mapWidth == 0) { Console.Error.WriteLine(""); }
             *  if (isWall(j % mapWidth, j / mapwidth)) { Console.Error.Write("+"); }
             *  else { Console.Error.Write(" "); }
             * }*/
        }
Пример #2
0
        public static void loadMap(StreamReader lines, out Map map)
        {
            List <string> mapLines = new List <string>();

            string l;

            do
            {
                l = lines.ReadLine();
                mapLines.Add(l);
            } while (l != "");

            int colcount = 0, rowcount = 0;

            getfilesize(mapLines, out colcount, out rowcount);
            Dictionary <Node, char> newboxes   = new Dictionary <Node, char>();
            HashSet <Actor>         newactors  = new HashSet <Actor>();
            GoalList newgoals = new GoalList();
            Dictionary <char, Color> colorDict = new Dictionary <char, Color>();

            bool[] newwallmap = new bool[colcount * rowcount];

            Byte j         = 0; // row count
            bool pastSetup = false;

            foreach (string line in mapLines)
            {
                if (line.Contains("+"))
                {
                    pastSetup = true;

                    Byte i = 0; // col count
                    //map construction
                    foreach (char c in line)
                    {
                        if (c == '+')
                        {
                            newwallmap[i + j * colcount] = true;
                        }
                        else if (Char.IsLower(c))
                        {
                            newgoals.Add(i, j, c);
                        } // i,j is goal
                        else if (Char.IsDigit(c))
                        { // i,j is actor
                            if (!colorDict.ContainsKey(c))
                            {
                                colorDict[c] = Color.blue;
                            }
                            newactors.Add(new Actor(i, j, Convert.ToByte(c - '0')));
                        }
                        else if (Char.IsUpper(c))
                        {
                            if (!colorDict.ContainsKey(Char.ToLower(c)))
                            {
                                colorDict[Char.ToLower(c)] = Color.blue;
                            }
                            newboxes.Add(new Node(i, j), Char.ToLower(c));
                        } // i,j is box

                        i++;
                    }
                    j++;
                }
                else if (!pastSetup)
                {
                    string[] splitline  = line.Split(':');
                    string   names      = splitline[1].Remove(0, 1);
                    string[] splitnames = names.Split(',');
                    foreach (string name in splitnames)
                    {
                        colorDict[Char.ToLower(name[0])] = (Color)Enum.Parse(typeof(Color), splitline[0].ToLower());
                    }
                    //do color devision
                }
            }
            map = new Map(newwallmap, colcount, newactors, newboxes, newgoals, colorDict);
        }