public void InitLevel()
        {
            if (m_levelCounter >= m_levels.Count)
            {
                SceneManager.LoadScene(m_victoryScene);
                return;
            }

            // clear old level
            Clear();

            // initialize settlements
            foreach (var point in m_levels[m_levelCounter].Points)
            {
                var obj = Instantiate(m_pointPrefab, point, Quaternion.identity) as GameObject;
                obj.transform.parent = this.transform;
                instantObjects.Add(obj);
            }

            //Make vertex list
            m_points = FindObjectsOfType <HullPoint>().ToList();

            // compute convex hull
            m_solutionHull = ConvexHull.ComputeConvexHull(m_points.Select(v => v.Pos));

            m_advanceButton.Disable();
        }
Beispiel #2
0
        public void InitLevel()
        {
            // clear old level
            Clear();

            if (m_levelCounter >= m_levels.Count && m_endlessMode)
            {
                var m_endlessDifficulty = PlayerPrefs.GetInt(m_endlessScoreKey);
                Camera.main.orthographicSize = 2 * (1 + m_settlementRadius * Mathf.Sqrt(m_endlessDifficulty));

                var            height    = Camera.main.orthographicSize * 2;
                var            width     = height * Camera.main.aspect;
                List <Vector2> positions = InitEndlessLevel(m_endlessDifficulty, width, height);

                foreach (var position in positions)
                {
                    GameObject obj;
                    if (UnityEngine.Random.Range(0f, 1f) < .75f)
                    {
                        obj = Instantiate(m_villagePrefab, position, Quaternion.identity);
                    }
                    else
                    {
                        obj = Instantiate(m_castlePrefab, position, Quaternion.identity);
                    }
                    instantObjects.Add(obj);
                }

                m_t = 1.5f;
            }
            else
            {
                // initialize settlements
                foreach (var village in m_levels[m_levelCounter].Villages)
                {
                    var obj = Instantiate(m_villagePrefab, village, Quaternion.identity);
                    obj.transform.parent = this.transform;
                    instantObjects.Add(obj);
                }
                foreach (var castle in m_levels[m_levelCounter].Castles)
                {
                    var obj = Instantiate(m_castlePrefab, castle, Quaternion.identity);
                    obj.transform.parent = this.transform;
                    instantObjects.Add(obj);
                }

                m_t = m_levels[m_levelCounter].TSpannerRatio;
            }

            //Make vertex list
            m_settlements = FindObjectsOfType <Settlement>();

            //init empty graph
            m_graph = new AdjacencyListGraph(m_settlements.Select(go => go.Vertex));

            FinishLevelSetup();

            m_advanceButton.Disable();
        }
 /// <summary>
 /// Checks whether there is a solution of sufficient quality present
 /// </summary>
 public void CheckSolution()
 {
     if (CheckTour())
     {
         m_advanceButton.Enable();
         m_giveUpButton.Disable();
     }
     else
     {
         m_giveUpButton.Enable();
         m_advanceButton.Disable();
     }
 }
Beispiel #4
0
        public void InitLevel()
        {
            // clear old level
            m_solution.Clear();
            m_selectedLighthouse = null;
            m_advanceButton.Disable();

            // create new level
            var level = m_levels[m_levelCounter];

            LevelPolygon             = level.Polygon;
            m_maxNumberOfLighthouses = level.MaxNumberOfLighthouses;
            m_levelMesh.Polygon      = LevelPolygon;

            // update text box
            UpdateLighthouseText();
        }
Beispiel #5
0
 /// <summary>
 /// Allow user to advance to next level.
 /// </summary>
 private void EnableAdvanceButton()
 {
     m_hintButton.Disable();
     m_advanceButton.Enable();
 }
Beispiel #6
0
        // Use this for initialization
        void Start()
        {
            // get unity objects
            m_segments              = new List <LineSegment>();
            instantObjects          = new List <GameObject>();
            instantTrapezoidObjects = new List <GameObject>();
            m_advanceButton.Disable();
            m_tryagainContainer.gameObject.SetActive(false);
            m_tryagainText.gameObject.SetActive(false);
            m_boromirExceptionContainer.gameObject.SetActive(false);
            m_boromirExceptionText.gameObject.SetActive(false);

            map = new List <CountryLineSegment>();
            map.Add(new CountryLineSegment(new Vector2(0.27f, 0.3178717598908595f), new Vector2(0.32f, 0.41336971350613916f), "null"));
            map.Add(new CountryLineSegment(new Vector2(0.32f, 0.41336971350613916f), new Vector2(0.3f, 0.48158253751705316f), "Gondor"));
            map.Add(new CountryLineSegment(new Vector2(0.27f, 0.3178717598908595f), new Vector2(0.45f, 0.3997271487039563f), "Gondor"));
            map.Add(new CountryLineSegment(new Vector2(0.3f, 0.48158253751705316f), new Vector2(0.34f, 0.5361527967257844f), "Eriador"));
            map.Add(new CountryLineSegment(new Vector2(0.34f, 0.5361527967257844f), new Vector2(0.47f, 0.5634379263301501f), "Eriador"));
            map.Add(new CountryLineSegment(new Vector2(0.47f, 0.5634379263301501f), new Vector2(0.68f, 0.4679399727148704f), "Rohan"));
            map.Add(new CountryLineSegment(new Vector2(0.45f, 0.3997271487039563f), new Vector2(0.51f, 0.20873124147339694f), "Gondor"));
            map.Add(new CountryLineSegment(new Vector2(0.51f, 0.20873124147339694f), new Vector2(0.61f, 0.16780354706684852f), "Gondor"));
            map.Add(new CountryLineSegment(new Vector2(0.61f, 0.16780354706684852f), new Vector2(0.77f, 0.2633015006821282f), "Gondor"));
            map.Add(new CountryLineSegment(new Vector2(0.68f, 0.4679399727148704f), new Vector2(0.77f, 0.2633015006821282f), "Mordor"));
            map.Add(new CountryLineSegment(new Vector2(0.66f, 0.5361527967257844f), new Vector2(0.68f, 0.4679399727148704f), "Mordor"));
            map.Add(new CountryLineSegment(new Vector2(0.66f, 0.5361527967257844f), new Vector2(0.84f, 0.5497953615279673f), "Rhovanion"));
            map.Add(new CountryLineSegment(new Vector2(0.77f, 0.2633015006821282f), new Vector2(0.83f, 0.24965893587994548f), "Mordor"));
            map.Add(new CountryLineSegment(new Vector2(0.83f, 0.24965893587994548f), new Vector2(0.97f, 0.3587994542974079f), "Mordor"));
            map.Add(new CountryLineSegment(new Vector2(0.97f, 0.3587994542974079f), new Vector2(0.98f, 0.5088676671214188f), "Mordor"));
            map.Add(new CountryLineSegment(new Vector2(0.38f, 0.017735334242837686f), new Vector2(0.51f, 0.20873124147339694f), "null"));
            map.Add(new CountryLineSegment(new Vector2(0.38f, 0.017735334242837686f), new Vector2(0.69f, 0.03137789904502042f), "NearHarad"));
            map.Add(new CountryLineSegment(new Vector2(0.89f, 0.07230559345156895f), new Vector2(0.97f, 0.3587994542974079f), "NearHarad"));
            map.Add(new CountryLineSegment(new Vector2(0.69f, 0.03137789904502042f), new Vector2(0.89f, 0.07230559345156895f), "NearHarad"));
            map.Add(new CountryLineSegment(new Vector2(0.55f, 0.6862210095497954f), new Vector2(0.66f, 0.5361527967257844f), "Rhovanion"));
            map.Add(new CountryLineSegment(new Vector2(0.47f, 0.5634379263301501f), new Vector2(0.55f, 0.6862210095497954f), "Eriador"));
            map.Add(new CountryLineSegment(new Vector2(0.55f, 0.6862210095497954f), new Vector2(0.56f, 0.9045020463847203f), "Eriador"));
            map.Add(new CountryLineSegment(new Vector2(0.56f, 0.9045020463847203f), new Vector2(0.81f, 0.8362892223738063f), "Forodwaith"));
            map.Add(new CountryLineSegment(new Vector2(0.81f, 0.8362892223738063f), new Vector2(0.84f, 0.5497953615279673f), "Rhun"));
            map.Add(new CountryLineSegment(new Vector2(0.84f, 0.5497953615279673f), new Vector2(0.98f, 0.5088676671214188f), "Rhun"));
            map.Add(new CountryLineSegment(new Vector2(0.81f, 0.8362892223738063f), new Vector2(0.92f, 0.9454297407912687f), "Forodwaith"));
            map.Add(new CountryLineSegment(new Vector2(0.92f, 0.9454297407912687f), new Vector2(0.98f, 0.5088676671214188f), "null"));
            map.Add(new CountryLineSegment(new Vector2(0.31f, 0.9181446111869032f), new Vector2(0.56f, 0.9045020463847203f), "Forodwaith"));
            map.Add(new CountryLineSegment(new Vector2(0.09f, 0.7407912687585265f), new Vector2(0.31f, 0.9181446111869032f), "null"));
            map.Add(new CountryLineSegment(new Vector2(0.09f, 0.7407912687585265f), new Vector2(0.3f, 0.48158253751705316f), "Eriador"));
            map.Add(new CountryLineSegment(new Vector2(0.28f, 0.9727148703956344f), new Vector2(0.31f, 0.9181446111869032f), "Forodwaith"));
            map.Add(new CountryLineSegment(new Vector2(0.28f, 0.9727148703956344f), new Vector2(0.73f, 0.9863574351978172f), "null"));
            map.Add(new CountryLineSegment(new Vector2(0.73f, 0.9863574351978172f), new Vector2(0.92f, 0.9454297407912687f), "null"));

            decomp = new TrapezoidalDecomposition(map);

            // get unity objects
            instantObjects          = new List <GameObject>();
            instantTrapezoidObjects = new List <GameObject>();

            // Display segments on screen.
            foreach (CountryLineSegment seg in map)
            {
                AddSegment(seg);
            }

            AdvanceLevel();
        }
Beispiel #7
0
        public void InitLevel()
        {
            if (m_levelCounter >= m_levels.Count)
            {
                SceneManager.LoadScene(m_victoryScene);
                return;
            }

            // clear old level
            Clear();

            //affine transformation


            // initialize settlements
            for (var i = 0; i < m_levels[m_levelCounter].Points.Count; i++)
            {
                m_levels[m_levelCounter].Points[i] += new Vector2(epsilon * (Random.Range(0f, 1f) - 0.5f), epsilon * (Random.Range(0f, 0.1f)));

                var point = m_levels[m_levelCounter].Points[i];

                var obj = Instantiate(m_pointPrefab, point, Quaternion.identity) as GameObject;
                obj.transform.parent = this.transform;
                instantObjects.Add(obj);
            }

            foreach (var point in m_levels[m_levelCounter].Points)
            {
            }

            m_pointSelection = false;


            //Make vertex list
            m_points = FindObjectsOfType <P1HullPoint>().ToList();


            // set maximum number of selected m_points
            var convexhulltemp = ConvexHull.ComputeConvexHull(m_points.Select(v => v.Pos));

            m_pointNumberLimit = Random.Range(3, convexhulltemp.VertexCount + 1);
            if (m_pointNumberLimit < 3)
            {
                m_pointNumberLimit = 3;
            }

            // set selected number panel
            GameObject.Find("MaximumNumber").GetComponent <Text>().text  = m_pointNumberLimit.ToString();
            GameObject.Find("SelectedNumber").GetComponent <Text>().text = "0";


            // compute maximum k-gon (Area)
            if (m_pointNumberLimit >= convexhulltemp.VertexCount)
            {
                m_solutionHull = convexhulltemp;
            }
            else
            {
                m_solutionHull = MaximumKgon.ComputeMaximumAreaKgon(m_points.Select(v => v.Pos), m_pointNumberLimit);
            }


            // set hint button

            Debug.Log(m_hint);
            foreach (var seg in m_solutionHull.Segments)
            {
                //Add a line renderer
                // instantiate new road mesh

                var hintmesh = Instantiate(m_hintLineMeshPrefab, Vector3.forward, Quaternion.identity) as GameObject;
                hintmesh.transform.parent = m_hint.transform;
                instantObjects.Add(hintmesh);
                hintMeshes.Add(hintmesh);

                hintmesh.GetComponent <P1HullSegment>().Segment = seg;

                var hintmeshScript = hintmesh.GetComponent <ReshapingMesh>();
                hintmeshScript.CreateNewMesh(seg.Point1, seg.Point2);
            }
            m_hint.SetActive(false);

            //set stars information
            GameObject.Find("Area").GetComponent <Text>().text = "0";
            m_rateList = new List <float>()
            {
                0.6f, 0.8f, 0.95f, 1.0f
            };
            Debug.Log(m_rateList.Count);
            for (int i = 1; i < m_rateList.Count; i++)
            {
                var objName = "Star" + i;
                Debug.Log(objName);
                var starArea = m_rateList[i - 1] * m_solutionHull.Area;
                GameObject.Find(objName).GetComponent <Text>().text = starArea.ToString();
            }



            m_advanceButton.Disable();
        }