Example #1
0
        /* Read in guards from text file. Each line contains the patrol
         * points for a guard and a single integer at the end of the line for speed.
         * */
        public void loadGuards()
        {
            guards = new ArrayList();
            Texture2D guardTexture = Content.Load<Texture2D>("guard");
            TextReader gr = new StreamReader("guardData.csv");
            TextReader nr = new StreamReader("guardData.csv");
            String line;
            int numGuards = nr.ReadToEnd().Split('\n').Length - 1;
            for (int i = 0; i < numGuards; i++)
            {
                line = gr.ReadLine();
                int speed = Convert.ToInt32(line.Split('>')[line.Split('>').Length - 1]);
                int numPoints = Convert.ToInt32(line.Split(';').Length - 1);
                String[] points = line.Split(';'); //last part will be speed, not used
                Point[] patrolPoints = new Point[numPoints];
                for (int j = 0; j < numPoints; j++)
                {
                    String[] point = points[j].Split(',');
                    int posX = Convert.ToInt32(point[0]);
                    int posy = Convert.ToInt32(point[1]);
                    patrolPoints[j] = new Point(posX, posy);

                }
                Npc guard = new Npc(this);
                guard.initialize(myMap, patrolPoints[0].X, patrolPoints[0].Y, 0, 0, guardTexture, "guard" + i, patrolPoints, speed);
                guards.Add(guard);

            }
            gr.Close();
            nr.Close();
        }
Example #2
0
        /* Read in guards from text file. Each line contains the patrol
         * points for a guard and a single integer at the end of the line for speed.
         * */
        public void loadGuards(string csv)
        {
            currentLevel.initiailizeGuards(new List<Npc>());
            Texture2D guardTexture = Content.Load<Texture2D>("guard");
            TextReader gr = new StreamReader(csv);
            TextReader nr = new StreamReader(csv);
            String line;
            int numGuards = nr.ReadToEnd().Split('\n').Length - 1;
            for (int i = 0; i < numGuards; i++)
            {
                line = gr.ReadLine();
                int speed = Convert.ToInt32(line.Split('>')[line.Split('>').Length - 1]);
                int numPoints = Convert.ToInt32(line.Split(';').Length - 1);
                String[] points = line.Split(';'); //last part will be speed, not used
                Point[] patrolPoints = new Point[numPoints];
                int[] directions = new int[numPoints];

                for (int j = 0; j < numPoints; j++)
                {
                    String[] point = points[j].Split(',');
                    int posX = Convert.ToInt32(point[0]);
                    int posy = Convert.ToInt32(point[1]);
                    int direction = Convert.ToInt32(point[2]);
                    patrolPoints[j] = new Point(posX, posy);
                    directions[j] = direction;

                }

                Npc guard = new Npc(this);
                guard.initialize(currentLevel.currentMap, patrolPoints[0].X, patrolPoints[0].Y, 0, 0, guardTexture, "guard" + i, patrolPoints, directions, speed);
                currentLevel.guards[currentLevel.currentMapIndex].Add(guard);

            }
            gr.Close();
            nr.Close();
        }