Пример #1
0
        protected Shape GenerateRandomTier1Shape(int[] cases, int index)
        {
            //this is an overloaded function from the level class, the only thing different about this function is that it assigns the shape based on the unique numbers generated in "cases"
            //instead of generating a shape type on a random number assigned in here
            Shape Temp = null;

            switch (cases[index])
            {
            case 0:
                Temp = new OklahomaShape();
                break;

            case 1:
                Temp = new HockeyStickShape();
                break;

            case 2:
                Temp = new EasyDiagonalShape();
                break;

            case 3:
                Temp = new ReverseHockeyStickShape();
                break;

            case 4:
                Temp = new CornerShape();
                break;
            }

            return(Temp);
        }
Пример #2
0
        public static Shape ConvertToShape(string s)
        {
            Shape  shape = null;
            string name  = "";

            string[] ss = new string[0];        //array of all the data parts
            int      numBlocks;                 //counting variables
            bool     extraData = false;         //Grab extra data from the string for shape shifting shape

            try
            {
                //Get name
                ss = s.Split('[');
                for (int i = 0; i < ss.Length; i++)
                {
                    ss[i] = ss[i].Trim('[', ']');
                }

                //Set up initial shape design
                name = ss[0];
                switch (name)
                {
                case "IShape":
                    shape = new IShape();
                    break;

                case "JShape":
                    shape = new JShape();
                    break;

                case "LShape":
                    shape = new LShape();
                    break;

                case "OShape":
                    shape = new OShape();
                    break;

                case "SShape":
                    shape = new SShape();
                    break;

                case "TShape":
                    shape = new TShape();
                    break;

                case "ZShape":
                    shape = new ZShape();
                    break;

                case "Corner Shape":
                    shape = new CornerShape();
                    break;

                case "Easy Diagonal Shape":
                    shape = new EasyDiagonalShape();
                    break;

                case "Hockey Stick Shape":
                    shape = new HockeyStickShape();
                    break;

                case "Oklahoma Shape":
                    shape = new OklahomaShape();
                    break;

                case "Reverse Hockey Stick Shape":
                    shape = new ReverseHockeyStickShape();
                    break;

                case "Bucket Shape":
                    shape = new BucketShape();
                    break;

                case "Lobster Claw Shape":
                    shape = new LobsterClawShape();
                    break;

                case "Plus Shape":
                    shape = new PlusShape();
                    break;

                case "Stair Shape":
                    shape = new StairShape();
                    break;

                case "VShape":
                    shape = new VShape();
                    break;

                case "Hard Diagonal Shape":
                    shape = new HardDiagonalShape();
                    break;

                case "Hook Shape":
                    shape = new HookShape();
                    break;

                case "Kite Shape":
                    shape = new KiteShape();
                    break;

                case "Tonfu Shape":
                    shape = new TonfuShape();
                    break;

                case "Shape Shifting Shape":
                    shape     = new ShapeShiftingShape();
                    extraData = true;
                    break;

                default:
                    shape = new OShape();
                    break;
                }

                //Set up blocks
                numBlocks = int.Parse(ss[1]);
                for (int i = 0; i < numBlocks; i++)
                {
                    int blockIndex = int.Parse(ss[2 + i]);
                    shape.blocks[i].blockColor = BlockColors.AllBlocks[blockIndex];
                }

                //If shapeshifting shape, get state relative positions of the different forms
                if (extraData)
                {
                    shape.stateRelativePositions.Clear();
                    int index = 2 + numBlocks;
                    for (int i = 0; i < 4; i++)
                    {
                        shape.stateRelativePositions.Add(new List <Vector2>());
                        int numFormBlocks = int.Parse(ss[index]);
                        index++;
                        for (int j = 0; j < numFormBlocks; j++)
                        {
                            int x = int.Parse(ss[index]);
                            int y = int.Parse(ss[index + 1]);
                            index += 2;

                            shape.stateRelativePositions[i].Add(new Vector2(x, y));
                        }
                    }
                }
            }
            catch
            {
                Console.WriteLine("String could not be converted to shape: {0}", s);
            }

            return(shape);
        }