コード例 #1
0
        public async Task <IActionResult> Edit(int id, [Bind("RV_ID,RV_NAME")] Rivers rivers)
        {
            if (id != rivers.RV_ID)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(rivers);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!RiversExists(rivers.RV_ID))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(rivers));
        }
コード例 #2
0
    public void TriangulateAllCells()
    {
        // This method could be invoked at any time, even when cells have already been triangulated earlier.
        // So we should begin by clearing the old data.
        Terrain.Clear();
        Rivers.Clear();
        Roads.Clear();
        Water.Clear();
        WaterShore.Clear();
        Estuaries.Clear();
        Features.Clear();

        for (int i = 0; i < _cells.Length; i++)
        {
            Precalculation(_cells[i]);
        }

        for (int i = 0; i < _cells.Length; i++)
        {
            TriangulateCell(_cells[i]);
            AddFeatures(_cells[i]);
        }

        Terrain.Apply();
        Rivers.Apply();
        Roads.Apply();
        Water.Apply();
        WaterShore.Apply();
        Estuaries.Apply();
        Features.Apply();
    }
コード例 #3
0
        private void TriangulateWithRiverBeginOrEnd(HexDirection direction, HexCell cell, Vector3 centre, EdgeVertices e)
        {
            var m = new EdgeVertices(
                Vector3.Lerp(centre, e.v1, 0.5f),
                Vector3.Lerp(centre, e.v5, 0.5f));

            m.v3.y = e.v3.y;

            TriangulateEdgeStrip(m, weights1, cell.Index, e, weights1, cell.Index);
            TriangulateEdgeFan(centre, m, cell.Index);

            var reversed = cell.HasIncomingRiver;
            var indices  = new Vector3(cell.Index, cell.Index, cell.Index);

            TriangulateRiverQuad(m.v2, m.v4, e.v2, e.v4, cell.RiverSurfaceY, 0.6f, reversed, indices);

            centre.y = m.v2.y = m.v4.y = cell.RiverSurfaceY;
            Rivers.AddTriangle(centre, m.v2, m.v4);
            if (reversed)
            {
                Rivers.AddTriangleUV(new Vector2(0.5f, 0.4f), new Vector2(1f, 0.2f), new Vector2(0f, 0.2f));
            }
            else
            {
                Rivers.AddTriangleUV(new Vector2(0.5f, 0.4f), new Vector2(0f, 0.6f), new Vector2(1f, 0.6f));
            }

            Rivers.AddTriangleCellData(indices, weights1);
        }
コード例 #4
0
        private void PopulateState(BaseItem item)
        {
            if (item is Empty empty)
            {
                EmptyItems.Add(empty);
                return;
            }

            if (item is AiTank aiTank)
            {
                AiTanks.Add(aiTank);

                if (item is AiPrizeTank aiPrizeTank)
                {
                    AiPrizeTanks.Add(aiPrizeTank);
                }

                return;
            }

            if (item is EnemyTank enemyTank)
            {
                EnemyTanks.Add(enemyTank);
                return;
            }

            if (item is MyTank myTank)
            {
                MyTank = myTank;
                return;
            }

            if (item is Bullet bullet)
            {
                Bullets.Add(bullet);
                return;
            }

            if (item is River river)
            {
                Rivers.Add(river);
                return;
            }

            if (item is Tree tree)
            {
                Trees.Add(tree);
                return;
            }

            if (item is Ice ice)
            {
                Ice.Add(ice);
                return;
            }
        }
コード例 #5
0
        public async Task <IActionResult> Create([Bind("RV_ID,RV_NAME")] Rivers rivers)
        {
            if (ModelState.IsValid)
            {
                _context.Add(rivers);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(rivers));
        }
コード例 #6
0
        public static void Main(string[] args)
        {
            var context = new GeographyEntities();

            // Parse the test file rivers.xml
            var xmlDoc = XDocument.Load(@"..\..\rivers.xml");

            var riverNodes = xmlDoc.XPathSelectElements("/rivers/river");

            foreach (var riverNode in riverNodes)
            {
                // mandatory
                string riverName    = riverNode.Element("name").Value;
                int    riverLength  = int.Parse(riverNode.Element("length").Value);
                string riverOutflow = riverNode.Element("outflow").Value;

                // optional
                int?riverDrainageArea = null;
                if (riverNode.Element("drainage-area") != null)
                {
                    riverDrainageArea = int.Parse(riverNode.Element("drainage-area").Value);
                }

                int?riverAverageDischarge = null;
                if (riverNode.Element("average-discharge") != null)
                {
                    riverAverageDischarge = int.Parse(riverNode.Element("average-discharge").Value);
                }

                // Create object for current River
                var river = new Rivers()
                {
                    RiverName        = riverName,
                    Length           = riverLength,
                    DrainageArea     = riverDrainageArea,
                    AverageDischarge = riverAverageDischarge,
                    Outflow          = riverOutflow
                };

                // Add the countries for the rivers
                var countryNodes = riverNode.XPathSelectElements("countries/country");
                var countryNames = countryNodes.Select(c => c.Value);
                foreach (var countryName in countryNames)
                {
                    var country = context.Countries.FirstOrDefault(c => c.CountryName == countryName);
                    river.Countries.Add(country);
                }

                // Add the rivers to the DB
                context.Rivers.Add(river);
                context.SaveChanges();
            }
        }
コード例 #7
0
        public void TestRiver2()
        {
            int[,] matrix = { { 1, 0, 0, 0, 0 },
                              { 1, 0, 0, 0, 0 },
                              { 1, 0, 0, 0, 0 },
                              { 1, 0, 0, 0, 0 },
                              { 1, 0, 0, 0, 0 } };
            int[] expected = { 5 };
            var   rivers   = new Rivers();
            var   received = rivers.Solve(matrix);

            Assert.AreEqual(expected.Length, received.Length);
        }
コード例 #8
0
    void TriangulateWithRiverBeginOrEnd(HexDirection direction, HexCell cell)
    {
        var center     = cell.Center;
        var closerEdge = cell.Edges[(int)direction];

        if (cell.HasRiverThroughEdge(direction.Next()))
        {
            if (cell.HasRiverThroughEdge(direction.Previous()))
            {
                center += HexMetrics.GetSolidEdgeMiddle(direction) * (HexMetrics.InnerToOuter * 0.5f);
            }
            else if (cell.HasRiverThroughEdge(direction.Previous2()))
            {
                center += HexMetrics.GetLeftSolidCorner(direction) * 0.25f;
            }
        }
        else if (cell.HasRiverThroughEdge(direction.Previous()) && cell.HasRiverThroughEdge(direction.Next2()))
        {
            center += HexMetrics.GetRightSolidCorner(direction) * 0.25f;
        }

        var m = new EdgeVertices(Vector3.Lerp(center, closerEdge.V1, 0.5f), Vector3.Lerp(center, closerEdge.V5, 0.5f));

        m.V3.y = closerEdge.V3.y; // reassign middle verticle height as it is ommited in the calculation above

        TriangulateEdgeStrip(m, cell.Color, closerEdge, cell.Color);
        TriangulateEdgeFan(center, m, cell.Color);

        // river segments are added only if the current segment is not under water
        if (!cell.IsUnderwater)
        {
            bool reversed = cell.HasIncomingRiver;

            // outer circle of the hex
            TriangulateRiverQuadUnperturbed(m.V2, m.V4, closerEdge.V2, closerEdge.V4, cell.RiverSurfaceY, 0.6f, reversed);

            // end (or start) triangle
            center.y = m.V2.y = m.V4.y = cell.RiverSurfaceY;
            Rivers.AddTriangleUnperturbed(center, m.V2, m.V4);

            if (reversed)
            {
                Rivers.AddTriangleUV(new Vector2(0.5f, 0.4f), new Vector2(1f, 0.2f), new Vector2(0f, 0.2f));
            }
            else
            {
                Rivers.AddTriangleUV(new Vector2(0.5f, 0.4f), new Vector2(0f, 0.6f), new Vector2(1f, 0.6f));
            }
        }
    }
コード例 #9
0
    /// <summary>
    /// Creates a river quad and adds uvs to it.
    /// Height1 is applied to v1 and v2 vectors and height2 is applied to v3 and v4 vectors.
    /// Therefore vector original y values are ignored.
    /// </summary>
    void TriangulateRiverQuadUnperturbed(Vector3 v1, Vector3 v2, Vector3 v3, Vector3 v4, float height1, float height2, float uv, bool reversed)
    {
        v1.y = v2.y = height1;
        v3.y = v4.y = height2;
        Rivers.AddQuadUnperturbed(v1, v2, v3, v4);

        if (reversed)
        {
            Rivers.AddQuadUV(1f, 0f, 0.8f - uv, 0.6f - uv);
        }
        else
        {
            Rivers.AddQuadUV(0f, 1f, uv, uv + 0.2f);
        }
    }
コード例 #10
0
        public River GetRiver(int id)
        {
            if (id == 0)
            {
                return(null);
            }
            var river = Rivers.Where(r => r.ID == id);

            if (river.Count() == 1)
            {
                return(river.First());
            }
            else
            {
                return(null);
            }
        }
コード例 #11
0
    void TriangulateWaterfallInWater(Vector3 v1, Vector3 v2, Vector3 v3, Vector3 v4, float y1, float y2, float waterY)
    {
        v1.y = v2.y = y1;
        v3.y = v4.y = y2;

        v1 = HexMetrics.Perturb(v1);
        v2 = HexMetrics.Perturb(v2);
        v3 = HexMetrics.Perturb(v3);
        v4 = HexMetrics.Perturb(v4);
        float t = (waterY - y2) / (y1 - y2);

        v3 = Vector3.Lerp(v3, v1, t);
        v4 = Vector3.Lerp(v4, v2, t);

        Rivers.AddQuadUnperturbed(v1, v2, v3, v4);
        Rivers.AddQuadUV(0f, 1f, 0.8f, 1f);
    }
コード例 #12
0
    /// <summary>
    /// Creates geometry for river water surface with different start and end Y.
    /// </summary>
    void TriangulateRiverQuad(Vector3 v1, Vector3 v2, Vector3 v3, Vector3 v4, float y1, float y2, float v, bool reversed, Vector3 indices)
    {
        v1.y = v2.y = y1;
        v3.y = v4.y = y2;
        Rivers.AddQuad(v1, v2, v3, v4);

        // Add UVs according to river orientation (used in water flow effect in river shader)
        if (reversed)
        {
            Rivers.AddQuadUV(1f, 0f, 0.8f - v, 0.6f - v);
        }
        else
        {
            Rivers.AddQuadUV(0f, 1f, v, v + 0.2f);
        }

        Rivers.AddQuadCellData(indices, weights1, weights2);
    }
コード例 #13
0
 private void TriangulateRiverQuad(
     Vector3 v1, Vector3 v2, Vector3 v3, Vector3 v4,
     float y1, float y2, float v,
     bool reversed, Vector3 indices)
 {
     v1.y = v2.y = y1;
     v3.y = v4.y = y2;
     Rivers.AddQuad(v1, v2, v3, v4);
     if (reversed)
     {
         Rivers.AddQuadUV(1f, 0f, 0.8f - v, 0.6f - v);
     }
     else
     {
         Rivers.AddQuadUV(0f, 1f, v, v + 0.2f); // left to right, bottom to top.
     }
     Rivers.AddQuadCellData(indices, weights1, weights2);
 }
コード例 #14
0
        private void TriangulateWaterfallInWater(
            Vector3 v1, Vector3 v2, Vector3 v3, Vector3 v4,
            float y1, float y2, float waterY, Vector3 indices)
        {
            v1.y = v2.y = y1;
            v3.y = v4.y = y2;
            v1   = HexMetrics.Perturb(v1);
            v2   = HexMetrics.Perturb(v2);
            v3   = HexMetrics.Perturb(v3);
            v4   = HexMetrics.Perturb(v4);
            var t = (waterY - y2) / (y1 - y2);

            v3 = Vector3.Lerp(v3, v1, t);
            v4 = Vector3.Lerp(v4, v2, t);
            Rivers.AddQuadUnperterbed(v1, v2, v3, v4);
            Rivers.AddQuadUV(0f, 1f, 0.8f, 1f);
            Rivers.AddQuadCellData(indices, weights1, weights2);
        }
コード例 #15
0
 /// <summary>
 /// Builds the mesh of the hex grid out of the provided array of cells.
 /// </summary>
 public void Triangulate()
 {
     Terrain.Clear();
     Rivers.Clear();
     Roads.Clear();
     Water.Clear();
     WaterShore.Clear();
     Estuaries.Clear();
     Features.Clear();
     for (int i = 0; i < Cells.Length; i++)
     {
         Triangulate(Cells[i]);
     }
     Terrain.Apply();
     Rivers.Apply();
     Roads.Apply();
     Water.Apply();
     WaterShore.Apply();
     Estuaries.Apply();
     Features.Apply();
 }
コード例 #16
0
        public void Triangulate(HexCell[] cells)
        {
            Terrain.Clear();
            Rivers.Clear();
            Roads.Clear();
            Water.Clear();
            WaterShore.Clear();
            Estuaries.Clear();
            Features.Clear();

            foreach (var cell in cells)
            {
                TriangulateCell(cell);
            }

            Terrain.Apply();
            Rivers.Apply();
            Roads.Apply();
            Water.Apply();
            WaterShore.Apply();
            Estuaries.Apply();
            Features.Apply();
        }
コード例 #17
0
    /// <summary>
    /// Creates the triangles for a side of the hexagon, with river starting or ending this side.
    /// </summary>
    void TriangulateWithRiverBeginOrEnd(HexDirection direction, HexCell cell, Vector3 center, EdgeVertices e)
    {
        // Edge 1/2 the way from edge and cell center
        EdgeVertices m = new EdgeVertices(
            Vector3.Lerp(center, e.v1, 0.5f),
            Vector3.Lerp(center, e.v5, 0.5f)
            );

        m.v3.y = e.v3.y;         // middle at river bed height, but not the center of the cell

        TriangulateEdgeStrip(m, weights1, cell.Index, e, weights1, cell.Index);
        TriangulateEdgeFan(center, m, cell.Index);

        if (!cell.IsUnderwater)             // No river water surface underwater, riverbed itself is allowed
        // River water surface
        {
            bool reversed = cell.HasIncomingRiver;

            Vector3 indices;
            indices.x = indices.y = indices.z = cell.Index;
            TriangulateRiverQuad(m.v2, m.v4, e.v2, e.v4, cell.RiverSurfaceY, 0.6f, reversed, indices);

            // Add first/last water surface triangle for river begin/end
            center.y = m.v2.y = m.v4.y = cell.RiverSurfaceY;
            Rivers.AddTriangle(center, m.v2, m.v4);
            if (reversed)
            {
                Rivers.AddTriangleUV(new Vector2(0.5f, 0.4f), new Vector2(1f, 0.2f), new Vector2(0f, 0.2f));
            }
            else
            {
                Rivers.AddTriangleUV(new Vector2(0.5f, 0.4f), new Vector2(0f, 0.6f), new Vector2(1f, 0.6f));
            }

            Rivers.AddTriangleCellData(indices, weights1);
        }
    }
コード例 #18
0
    /// <summary>
    /// Create geometry for a river than flows in a waterfall unto the water surface,
    /// parameter orientation is aligned with river, looking downstream, left & right start vertex,
    /// left and right end vertex, cell start height, cell end height and water (where waterfall ends) height.
    /// </summary>
    void TriangulateWaterfallInWater(Vector3 v1, Vector3 v2, Vector3 v3, Vector3 v4, float y1, float y2, float waterY, Vector3 indices)
    {
        v1.y = v2.y = y1;
        v3.y = v4.y = y2;

        // Perturn vertices before interpolating
        // If we didnt do this and did it afterwards when creating the quad then we would loose
        // the results we will calculate with our interpolation bellow
        v1 = HexMetrics.Perturb(v1);
        v2 = HexMetrics.Perturb(v2);
        v3 = HexMetrics.Perturb(v3);
        v4 = HexMetrics.Perturb(v4);

        float t = (waterY - y2) / (y1 - y2);         // calculate interpolator

        v3 = Vector3.Lerp(v3, v1, t);
        v4 = Vector3.Lerp(v4, v2, t);

        // Create unperturbed quad, we already perturbed the vertices
        Rivers.AddQuadUnperturbed(v1, v2, v3, v4);
        Rivers.AddQuadUV(0f, 1f, 0.8f, 1f);

        Rivers.AddQuadCellData(indices, weights1, weights2);
    }
コード例 #19
0
        private void Collision(float dt)
        {
            var delWalls   = new List <WallViewModel>();
            var delTanks   = new List <TankViewModel>();
            var delApples  = new List <AppleViewModel>();
            var delBullets = new List <BulletViewModel>();

            if (IsGame)
            {
                DynamicEntity player = Player.Clone() as DynamicEntity;
                player.Move(dt);

                if (ObjectInScreen(player) &&
                    Rivers.Find(river => IsCollision(river, player)) == null &&
                    Walls.Find(wall => IsCollision(wall, player)) == null)
                {
                    bool isFree = true;

                    foreach (var tank in Tanks)
                    {
                        if (IsCollision(tank, player))
                        {
                            isFree = false;
                            CreateBang(player);
                            GameOver();
                        }
                    }

                    if (isFree)
                    {
                        Player.Move(dt);
                    }
                }

                Apples.ForEach(apple =>
                {
                    if (IsCollision(player, apple))
                    {
                        delApples.Add(apple);
                        Score++;
                    }
                });
            }

            Tanks.ForEach(t =>
            {
                t.Move(dt);
                if (!ObjectInScreen(t) ||
                    Walls.Find(wall => IsCollision(wall, t)) != null ||
                    Rivers.Find(river => IsCollision(river, t)) != null ||
                    Tanks.Find(tnk => tnk != t ? IsCollision(tnk, t) : false) != null)
                {
                    t.ChangeDirection();
                    t.Move(dt);
                }
            });

            Bullets.ForEach(bullet =>
            {
                bool delBullet = false;

                if (!ObjectInScreen(bullet))
                {
                    delBullet = true;
                }

                Walls.ForEach(wall =>
                {
                    if (IsCollision(bullet, wall))
                    {
                        if (wall.Destroyable)
                        {
                            delWalls.Add(wall);
                        }
                        delBullet = true;
                        CreateBang(bullet);
                    }
                });

                Tanks.ForEach(tank =>
                {
                    if (IsCollision(tank, bullet) && bullet.Shooter != tank)
                    {
                        delBullet = true;
                        delTanks.Add(tank);
                        CreateBang(tank);
                    }
                });

                if (IsGame)
                {
                    if (IsCollision(bullet, Player) && bullet.Shooter != Player)
                    {
                        delBullet = true;
                        CreateBang(Player);
                        GameOver();
                    }
                }

                if (delBullet)
                {
                    delBullets.Add(bullet);
                }
                else
                {
                    bullet.Move(dt);
                }
            });

            delWalls.ForEach(wall => Walls.Remove(wall));
            delTanks.ForEach(tank => Tanks.Remove(tank));
            delApples.ForEach(apple => Apples.Remove(apple));
            delBullets.ForEach(bullet => Bullets.Remove(bullet));
        }
コード例 #20
0
 public void AddRiver(River river)
 {
     Rivers.Add(river);
 }
コード例 #21
0
 private void button_River_Click(object sender, RoutedEventArgs e)
 {
     ListBoxItems.Clear();
     Rivers.ForEach(i => ListBoxItems.Add(i));
 }