Exemple #1
0
    private void Awake()
    {
        _toggles         = ObjectsLibrary.Find("ImageCheatSheet/ObjectSelected/Shape").GetComponentsInChildren <Toggle>();
        _currentWallType = WallsUtils.Walltype.WC; // TODO Set null

        Transform wallObjectProperties = WallObjectProperties.Find("ImageCheatSheet/Properties");
        Transform wallObjectContent    = WallObjectProperties.Find("ImageCheatSheet/ObjectSelected");

        _wallObjectId = wallObjectProperties.Find("Id").gameObject;
        _time         = wallObjectProperties.Find("Time").gameObject;
        // _backgroundImage = wallObjectContent.Find("Shape/ImageBackground").gameObject;
        _shapeImage = wallObjectContent.Find("Shape/ImageBackground/WallImage").gameObject;
        _dodgeImage = wallObjectContent.Find("Dodge/ImageBackground").gameObject;

        _coinImageBackground = wallObjectContent.Find("Coin/ImageBackground").gameObject;
        _coinImage           = wallObjectContent.Find("Coin/ImageBackground/Image").gameObject;

        _currentTab = wallObjectContent.Find("Shape").gameObject;
        _currentTab.SetActive(true);

        WallShape   = new WallShape();
        WallHit     = new WallHit();
        WallDodge   = new WallDodge();
        WallCoin    = new Coin();
        WallCustom  = new WallCustom();
        CurrentWall = WallShape;
    }
Exemple #2
0
    public int GetPositionOfCharToChange(WallsUtils.Walltype wallType, string name)
    {
        switch (wallType)
        {
        case WallsUtils.Walltype.NONE:
            break;

        case WallsUtils.Walltype.WP:
            return(WallShape.GetPositionOfCharToChange(name));

        case WallsUtils.Walltype.WA:
            break;

        case WallsUtils.Walltype.WH:
            return(WallHit.GetPositionOfCharToChange(name));

        case WallsUtils.Walltype.WC:
            break;

        case WallsUtils.Walltype.CN:
            break;

        case WallsUtils.Walltype.EV:
            break;

        default:
            break;
        }

        return(-1);
    }
Exemple #3
0
    public void MoveWallObjectSprite()
    {
        float factor = 42.5f; // TODO Change this factor to public settings in editor

        RectTransform wallImage = _shapeImage.GetComponent <RectTransform>();

        wallImage.anchoredPosition = new Vector2(factor * WallShape.getPosition(), wallImage.anchoredPosition.y);
    }
Exemple #4
0
        /// <summary>
        /// This function takes an XmlReader the was created from a BRUSH element in the main file,
        /// It then creates a new BRUSH and adds it to the List<Brush>
        /// </summary>
        /// <param name="brushReader">
        /// The XML Reader object created from a brush subtree in the ParseLevel() method
        /// </param>
        private void ParseBrush(XmlReader brushReader)
        {
            //a point to hold the location from where we add the brush
            Point brushLocation = new Point();

            //a Brushshape to hold the shape, default is vertical line
            WallShape ws = WallShape.l;

            //width and height variables
            int width = 0, height = 0;

            //read to the end
            while (brushReader.Read())
            {
                //check the node type
                switch (brushReader.NodeType)
                {
                ///*******************************************************
                ///Here we parse the BRUSH subelements into their own parts
                ///*******************************************************
                case XmlNodeType.Element:
                    //check the tag name and perform the necessary action on it
                    switch (brushReader.Name)
                    {
                    //get the starting X location of the brush
                    case "X":
                        brushLocation.X = brushReader.ReadElementContentAsInt();
                        break;

                    //get the starting Y location of the brush
                    case "Y":
                        brushLocation.Y = brushReader.ReadElementContentAsInt();
                        break;

                    //Get the shape type. Call the SetBrushShape function. It returns the appropriate enum BurshShape
                    case "SHAPE":
                        ws = SetBrushShape(brushReader.ReadElementContentAsString());
                        break;

                    //Get the width of the brush
                    case "WIDTH":
                        width = brushReader.ReadElementContentAsInt() * Tilesize;
                        break;

                    //Get the height of the brush
                    case "HEIGHT":
                        height = brushReader.ReadElementContentAsInt() * Tilesize;
                        //add the brushes once we reach the end
                        AddBrushes(brushLocation, ws, width, height);
                        break;
                    }
                    break;
                }
            }
        }
Exemple #5
0
        /// <summary>
        /// This method adds the brushes to the list of brushes
        /// </summary>
        /// <param name="brushLocation"> location to draw the brush </param>
        /// <param name="ws"> The Shape of the brush </param>
        /// <param name="width"> The width of the brush </param>
        /// <param name="height"> The height of the brush </param>
        private void AddBrushes(Point brushLocation, WallShape ws, int width, int height)
        {
            //create a temporary point to hold the location we are adding to
            Point tempPoint = new Point(brushLocation.X, brushLocation.Y);

            switch (ws)
            {
            //add an 'o' shaped brush
            case WallShape.o:
                //copy of the origin point for drawing
                Point drawPoint = tempPoint;
                //nested for loop because the shape is a equilateral
                for (int i = 0; i < height / Tilesize; ++i)
                {
                    //move the draw point down
                    drawPoint.Y = tempPoint.Y + i;
                    //cycle through the horizontal plane
                    for (int j = 0; j < width / Tilesize; ++j)
                    {
                        //move the draw point across the screen
                        drawPoint.X = tempPoint.X + j;
                        //add the brush at the draw point
                        SlowFloors.Add(new Brush(new Point(drawPoint.X * Tilesize, drawPoint.Y * Tilesize)));
                    }
                    //reset the drawpoint to the original x position
                    drawPoint.X = tempPoint.X;
                }
                break;

            //add a vertical line shaped wall
            case WallShape.l:
                //single for loop because we are drawing straight down. no change in X
                for (int i = 0; i < height / Tilesize; ++i)
                {
                    SlowFloors.Add(new Brush
                                       (new Point(tempPoint.X * Tilesize, (tempPoint.Y + i) * Tilesize)));
                }
                break;

            //add a horizontal line shaped wall
            case WallShape.hl:
                //single for loop because we are drawing straight across. no change in Y
                for (int i = 0; i < width / Tilesize; ++i)
                {
                    SlowFloors.Add(new Brush
                                       (new Point((tempPoint.X + i) * Tilesize, tempPoint.Y * Tilesize)));
                }
                break;
            }
        }
Exemple #6
0
        public void SimulateCostBaseTest()
        {
            setBuildings.SetValue(0, -1);
            setBuildings.SetValue(1, 0);
            setBuildings.SetValue(2, 8);
#if DEBUG
            setBuildings.Print();
#endif
            var varSimCost = new Dictionary <int, double[]>();
            for (int i = 0; i < setBuildings.Domain(1).MaxValue() + 1; ++i)
            {
                varSimCost[i] = new double[setBuildings.GetNumberVariables()];
                for (var j = 0; j < setBuildings.GetNumberVariables(); ++j)
                {
                    varSimCost[i][j] = -1;
                }
            }

            var noHoles  = new WallShape(setBuildings);
            var vecCosts = noHoles.SimulateCost(1, varSimCost);

            foreach (var tuple in vecCosts)
            {
                if (tuple.Key == 0 || tuple.Key == 7 || tuple.Key == 8 || tuple.Key == 12 || tuple.Key == 13)
                {
                    Assert.AreEqual(2.0, tuple.Value);
                }
                else if (tuple.Key == 1 || tuple.Key == 6 || tuple.Key == 11 || tuple.Key == 16 || tuple.Key == 17 || tuple.Key == 18)
                {
                    Assert.AreEqual(0.0, tuple.Value);
                }
                else
                {
                    Assert.AreEqual(4.0, tuple.Value);
                }
            }
        }
        public void SimulateCostBaseTest()
        {
            setBuildings.SetValue( 0, -1 );
              setBuildings.SetValue( 1, 0 );
              setBuildings.SetValue( 2, 8 );
            #if DEBUG
              setBuildings.Print();
            #endif
              var varSimCost = new Dictionary<int, double[] >();
              for( int i = 0 ; i < setBuildings.Domain( 1 ).MaxValue() + 1 ; ++i )
              {
            varSimCost[ i ] = new double[ setBuildings.GetNumberVariables() ];
            for( var j = 0 ; j < setBuildings.GetNumberVariables() ; ++j )
              varSimCost[ i ][ j ] = -1;
              }

              var noHoles = new WallShape( setBuildings );
              var vecCosts = noHoles.SimulateCost( 1 );

              foreach( var tuple in vecCosts )
            if( tuple.Key == 0 || tuple.Key == 7 || tuple.Key == 8 || tuple.Key == 12 || tuple.Key == 13 )
            {
              Assert.That( tuple.Value, Is.EqualTo( 2.0 ) );
            }
            else if( tuple.Key == 1 || tuple.Key == 6 || tuple.Key == 11 || tuple.Key == 16 || tuple.Key == 17 || tuple.Key == 18 )
            {
              Assert.That( tuple.Value, Is.Zero );
            }
            else
            {
              Assert.That( tuple.Value, Is.EqualTo( 4.0 ) );
            }
        }
Exemple #8
0
        /// <summary>
        /// This function takes an XmlReader the was created from a WALL element in the main file,
        /// It then creates a new wall and adds it to the List<Wall>
        /// </summary>
        /// <param name="wallReader">
        /// The XML Reader object created from a wall subtree in the ParseLevel() method
        /// </param>
        private void ParseWall(XmlReader wallReader)
        {
            //a point to hold the location from where we add the wall
            Point wallLocation = new Point();

            //a Walltype to hold the type, set the default to hard
            WallType wt = WallType.Hard;

            //a Wallshape to hold the shape, default is vertical line
            WallShape ws = WallShape.l;

            //a string to hold text data parsed from the file
            string tempString = "";

            //width and height variables
            int width = 0, height = 0;

            //read to the end
            while (wallReader.Read())
            {
                //check the node type
                switch (wallReader.NodeType)
                {
                ///*******************************************************
                ///Here we parse the WALL subelements into their own parts
                ///*******************************************************
                case XmlNodeType.Element:
                    //check the tag name and perform the necessary action on it
                    switch (wallReader.Name)
                    {
                    //get the starting X location of the wall
                    case "X":
                        wallLocation.X = wallReader.ReadElementContentAsInt();
                        break;

                    //get the starting Y location of the wall
                    case "Y":
                        wallLocation.Y = wallReader.ReadElementContentAsInt();
                        break;

                    //Get the wall type as a string, and then assign the appropriate type based on
                    //the string
                    case "TYPE":
                        tempString = wallReader.ReadElementContentAsString();
                        if (tempString == "WEAK")
                        {
                            wt = WallType.Weak;
                        }
                        break;

                    //Get the shape type. Call the SetWallShape function. It returns the appropriate enum WallShape
                    case "SHAPE":
                        tempString = wallReader.ReadElementContentAsString();
                        ws         = SetWallShape(tempString);
                        break;

                    //Get the width of the wall
                    case "WIDTH":
                        width = wallReader.ReadElementContentAsInt() * Tilesize;
                        break;

                    //Get the height of the wall
                    case "HEIGHT":
                        height = wallReader.ReadElementContentAsInt() * Tilesize;
                        //add the walls once we reach the end
                        AddWalls(wallLocation, wt, ws, width, height);
                        break;
                    }
                    break;
                }
            }
        }