Пример #1
0
 public void AddFortToArr(Fort f)
 {
     //add fort to arr:
     //can throw systemOutOfMemoryException if insane sizes chosen at start:
     Array.Resize(ref fortArr, fortArr.Length + 1);
     fortArr[fortArr.Length - 1] = f;
 }
Пример #2
0
        public void AskSize()
        {
            while (true)
            {
                int x        = 0;
                int y        = 0;
                int fortDimX = 0;
                int fortDimY = 0;
                int charPosX = 0;
                int charPosY = 0;
                char[,] charArr;
                Console.WriteLine("Enter X (Greater than 5):");

                try
                {
                    x = int.Parse(Console.ReadLine());
                }
                catch (Exception e) { Console.WriteLine("Wrong input"); continue; }
                Console.WriteLine("Enter Y (Greater than 5):");
                try
                {
                    y = int.Parse(Console.ReadLine());
                }
                catch (Exception e) { Console.WriteLine("Wrong input"); continue; }
                // same thing for fort size:
                Console.WriteLine("Enter Fort Size (Greater than 5):");
                try
                {
                    //fortSpace = int.Parse(Console.ReadLine());
                    //same value for now:
                    fortDimX = int.Parse(Console.ReadLine());
                    fortDimY = fortDimX;
                }
                catch (Exception e) { Console.WriteLine("Wrong input"); continue; }
                //saved locally instead:

                //world.SetLengthXY(x, false);
                //world.SetLengthXY(y, true);
                //lX = x;
                //lY = y;
                //update x and y values of char:
                charPosX = x / 2;
                charPosY = y / 2;
                if (x <= 5 || y <= 5)
                {
                    continue;
                }
                //construct charArr:
                charArr = new char[y, x];
                //WHERE TO DO THIS NEED TO CREATE EVERYTING BEFORE WORLD IS READY???
                Player p = new Player(charPosX, charPosY);
                //construct fort[] (initial size 0, add with method in world.cs:
                Fort[] f = new Fort[0];
                world = new World(charArr, p, f, fortDimX, fortDimY);
                break;
            }
        }
Пример #3
0
        public Fort CreateFort(int x, int y)
        {
            //issue because using the wrong integers when assigning chr[] dimentions:
            char[,] chr = new char[world.GetFortYDim(), world.GetFortXDim()];
            //1.fill with all W:
            for (int j = 0; j < world.GetFortYDim(); j++)
            {
                for (int k = 0; k < world.GetFortXDim(); k++)
                {
                    chr[j, k] = 'W';
                }
            }
            //2. empty space:
            for (int j = 1; j < world.GetFortYDim() - 1; j++)
            {
                for (int k = 1; k < world.GetFortXDim() - 1; k++)
                {
                    chr[j, k] = ' ';
                }
            }
            //3. slab:
            for (int j = 1; j < world.GetFortYDim() - 1; j++)
            {
                for (int k = 1; k < world.GetFortXDim() - 1; k++)
                {
                    //<5 percent chance of tree
                    //once tree decided, then higher chance of trees in spaces arround it
                    //if(j==i)charArr[i, j] = 'T';
                    int num = rand.Next(1, 26);
                    if (num == 1 || num == 2 || num == 3 || num == 4 || num == 5)
                    {
                        //ChooseColor(charArr[i, j]);
                        //Console.ForegroundColor = ConsoleColor.DarkGreen;
                        chr[j, k] = 'S';
                    }
                }
            } //4. fill in character space
            //error on this line causes error on fort f declaration:
            //change to bottom left corner:
            //REMOVE THIS?
            //chr[chr.GetLength(0)-2, 1] = 'C';
            //construct new player for fort constructor:
            //flip x and y?
            //Player p = new Player(chr.GetLength(1) / 2, chr.GetLength(0) / 2);
            //5. exit space:
            //PASS p AS PARAMETER TO f:
            Fort f = new Fort(x, y, chr);

            return(f);
        }