Пример #1
0
        private bool processInitialString(String str)
        {
            if (str.IndexOf("#") != str.Length - 1) {
                return false;
            }
            str = str.Substring(0, str.Length - 1);

            String[] StrSplit = str.Split(':');
            String[] bricks;
            String[] stones;
            String[] water;

            if (StrSplit[0].Equals("I"))
            {
                indexOfHomePlayer = Convert.ToInt32(StrSplit[1].Substring(1, StrSplit[1].Length-1));

                bricks = StrSplit[2].Split(';');
                stones = StrSplit[3].Split(';');
                water = StrSplit[4].Split(';');

                this.numberOfBrickCells = bricks.Length;
                this.numbberOfStoneCells = stones.Length;
                this.numebrOfWataterCells = water.Length;

                this.brick_cell = new Obstacle[numberOfBrickCells];
                this.stone_cell = new Obstacle[numbberOfStoneCells];
                this.water_cell = new Water[numebrOfWataterCells];

                int x = 0, y = 0;

                for (int i = 0; i < brick_cell.Length; i++) {

                    x = Convert.ToInt32(bricks[i].Split(',')[0].ToString());
                    y = Convert.ToInt32(bricks[i].Split(',')[1].ToString());

                    map[x, y] = "B_" + i;
                    brick_cell[i] = new Obstacle('B',x, y, 0);

                }

                x = 0; y = 0;
                for (int i = 0; i < stone_cell.Length; i++) {

                    x = Convert.ToInt32(stones[i].Split(',')[0].ToString());
                    y = Convert.ToInt32(stones[i].Split(',')[1].ToString());

                    map[x, y] = "S_" + i;
                    stone_cell[i] = new Obstacle('S', x, y, 0);

                }

                x = 0; y = 0;
                for (int i = 0; i < water_cell.Length; i++) {
                    x = Convert.ToInt32(water[i].Split(',')[0].ToString());
                    y = Convert.ToInt32(water[i].Split(',')[1].ToString());

                    map[x, y] = "W_" + i;
                    water_cell[i] = new Water('W', x, y);

                }

                return true;

            }
            else {
                return false;
            }
        }
Пример #2
0
        private bool processInitialString(String str)
        {
            if (str.IndexOf("#") != str.Length - 1)
            {
                return(false);
            }
            str = str.Substring(0, str.Length - 1);

            String[] StrSplit = str.Split(':');
            String[] bricks;
            String[] stones;
            String[] water;

            if (StrSplit[0].Equals("I"))
            {
                indexOfHomePlayer = Convert.ToInt32(StrSplit[1].Substring(1, StrSplit[1].Length - 1));

                bricks = StrSplit[2].Split(';');
                stones = StrSplit[3].Split(';');
                water  = StrSplit[4].Split(';');



                this.numberOfBrickCells   = bricks.Length;
                this.numbberOfStoneCells  = stones.Length;
                this.numebrOfWataterCells = water.Length;

                this.brick_cell = new Obstacle[numberOfBrickCells];
                this.stone_cell = new Obstacle[numbberOfStoneCells];
                this.water_cell = new Water[numebrOfWataterCells];

                int x = 0, y = 0;

                for (int i = 0; i < brick_cell.Length; i++)
                {
                    x = Convert.ToInt32(bricks[i].Split(',')[0].ToString());
                    y = Convert.ToInt32(bricks[i].Split(',')[1].ToString());

                    map[x, y]     = "B_" + i;
                    brick_cell[i] = new Obstacle('B', x, y, 0);
                }

                x = 0; y = 0;
                for (int i = 0; i < stone_cell.Length; i++)
                {
                    x = Convert.ToInt32(stones[i].Split(',')[0].ToString());
                    y = Convert.ToInt32(stones[i].Split(',')[1].ToString());

                    map[x, y]     = "S_" + i;
                    stone_cell[i] = new Obstacle('S', x, y, 0);
                }

                x = 0; y = 0;
                for (int i = 0; i < water_cell.Length; i++)
                {
                    x = Convert.ToInt32(water[i].Split(',')[0].ToString());
                    y = Convert.ToInt32(water[i].Split(',')[1].ToString());

                    map[x, y]     = "W_" + i;
                    water_cell[i] = new Water('W', x, y);
                }

                return(true);
            }
            else
            {
                return(false);
            }
        }