Esempio n. 1
0
        public World GenerateWorld()
        {
            _world.Initialize(_width, _height);
            var rand = new Random();

            for (int x = 0; x < _width; x++)
            {
                for (int y = 0; y < _height; y++)
                {
                    //TODO Change isexplored to false. For now it is set to true for testing!
                    if (rand.Next(0, 7) < 6)
                    {
                        var plains = new Plains(x, y, _world.GetCell(x, y));
                        _world.SetTileProperty(plains, x, y, false, true, true);
                    }
                    else
                    {
                        var mount = new Mountain(x, y, _world.GetCell(x, y));
                        _world.SetTileProperty(mount, x, y, false, true, true);
                    }
                }
            }

            GenerateOceans();

            return(_world);
        }
        public void OneTimeSetUp()
        {
            _mountain = new Mountain
            {
                Id     = MockDomainRoot.EntityId,
                Name   = "Name",
                Height = new Height {
                    Metres = 1
                },
                Location = new Location {
                    GridRef = new GridRef("NM123456"), Latitude = 2, Longitude = 3
                },
                Prominence = new Prominence {
                    Metres = 4, KeyCol = "KeyCol", KeyColHeight = new Height {
                        Metres = 5
                    }
                },
                Feature      = "Feature",
                Observations = "Observations",
                ListIds      = MockDomainRoot.EntityIds,
                MapIds       = MockDomainRoot.EntityIds,
                SectionId    = MockDomainRoot.EntityId,
                CountryId    = MockDomainRoot.EntityId
            };

            _sut = new MountainModel(_mountain, new MockDomainRoot());
        }
Esempio n. 3
0
        protected override void Seed(MountainsContext context)
        {
            if (!context.Countries.Any())
            {
                Country bulgaria = new Country()
                {
                    Code = "BG",
                    Name = "Bulgaria"
                };

                context.Countries.Add(bulgaria);
                context.SaveChanges();

                Mountain rila = new Mountain()
                {
                    Name = "Rila",
                };

                context.Mountains.Add(rila);
                context.SaveChanges();

                bulgaria.Mountains.Add(rila);

                Peak musala = new Peak()
                {
                    Name       = "Musala",
                    MountainId = rila.Id,
                    Elevation  = 2925,
                };

                context.Peaks.Add(musala);

                context.SaveChanges();
            }
        }
Esempio n. 4
0
    public Mountain Mutate(float noice)
    {
        Mountain mutation = new Mountain();
        double   factor   = DoubleUtil.Random(1 - noice, 1 + noice);

        mutation.entryHeight = Mathf.Clamp((int)(this.entryHeight * factor), heightRange[0], heightRange[1]);
        factor = DoubleUtil.Random(1 - noice, 1 + noice);
        mutation.exitHeight = Mathf.Clamp((int)(this.exitHeight * factor), heightRange[0], heightRange[1]);

        mutation.topWidth   = this.topWidth;
        mutation.exitWidth  = this.exitWidth;
        mutation.entryWidth = this.entryWidth;
        // mutation.actualHeight = this.actualHeight;
        // mutation.actualWidth = this.actualWidth;
        // factor = DoubleUtil.Random(1-noice, 1+noice);
        // mutation.topWidth = Mathf.Clamp((int)(this.topWidth * factor), widthRange[0], widthRange[1]);
        // factor = DoubleUtil.Random(1-noice, 1+noice);
        // mutation.exitWidth = Mathf.Clamp((int)(this.exitWidth * factor), widthRange[0], widthRange[1]);
        // factor = DoubleUtil.Random(1-noice, 1+noice);
        // mutation.entryWidth = Mathf.Clamp((int)(this.entryWidth * factor), widthRange[0], widthRange[1]);

        if (mutation.topWidth > Valley.width[0])
        {
            mutation.topIsValley = true;
            factor          = DoubleUtil.Random(1 - noice, 1 + noice);;
            mutation.valley = new Valley(Mathf.Clamp((int)(this.valley.noTrees * factor), Tree.spawn[0], Tree.spawn[1]));
        }
        return(mutation);
    }
Esempio n. 5
0
        public void FindStepWithPlayer_Traveler_Step()
        {
            int           peopleLimit   = 3;
            bool          decision      = true;
            EndStep       endStep       = new EndStep();
            Mountain      mountain      = new Mountain(peopleLimit, endStep);
            Ocean         ocean         = new Ocean(peopleLimit, mountain);
            ThermalWaters thermalWaters = new ThermalWaters(peopleLimit, ocean);
            Farm          farm          = new Farm(peopleLimit, thermalWaters);
            FirstStep     firstStep     = new FirstStep(farm);
            List <Step>   steps         = new List <Step>();

            steps.Add(farm);
            steps.Add(thermalWaters);
            steps.Add(ocean);
            steps.Add(mountain);
            Board           board     = new Board(steps, firstStep, endStep);
            List <Traveler> travelers = new List <Traveler>();

            travelers.Add(new Traveler());
            travelers.Add(new Traveler());
            GameData data     = new GameData(travelers, board);
            Movement movement = new Movement(data);

            movement.MakeMove(travelers[0], decision);
            Assert.AreEqual(movement.FindStepWithPlayer(travelers[0]), firstStep);
            Assert.AreEqual(movement.FindStepWithPlayer(travelers[1]), null);
        }
Esempio n. 6
0
        static int P(int k)
        {
            if (k == 1)
            {
                return(0);
            }
            if (k == 2)
            {
                mountains[1].CoveredIndex.Add(0);
                return(1);
            }
            double   mintag       = 1;
            double   tag          = 1;
            Mountain currMountain = mountains[k - 1];
            int      count        = 0;

            for (int i = k - 2; i >= 0; i--)
            {
                long deltaHeight   = currMountain.Height - mountains[i].Height;
                long deltaDistance = currMountain.Distance - mountains[i].Distance;
                tag = (double)deltaHeight / (double)deltaDistance;
                if (tag < mintag)
                {
                    count++;
                    mintag = tag;
                    continue;
                }
            }
            return(count);
        }
Esempio n. 7
0
    public void Draw()
    {
        this.block = new GameObject("Block");
        foreach (Mountain mountain in this.MountainEntities)
        {
            mountain.Draw(this.block);
        }

        for (int i = 0; i < this.MountainEntities.Count - 1; i++)
        {
            Mountain curr = this.MountainEntities[i];
            Mountain next = this.MountainEntities[i + 1];
            if (curr.Exit != null && next.Entry != null)
            {
                float distance = next.Entry.transform.position.x - curr.Exit.transform.position.x;
                if (distance <= 1.0f)
                {
                    float height = curr.Exit.transform.position.y + (curr.exitHeight / 2.0f) - 0.25f;
                    if (next.Entry.transform.position.y < curr.Exit.transform.position.y)
                    {
                        height = next.Entry.transform.position.y + (next.entryHeight / 2.0f) - 0.25f;
                    }
                    Vector3 pos = new Vector3((curr.Exit.transform.position.x + (distance / 2.0f)), height, 0);
                    AppController.Draw(AppController.BridgePrefab, pos, AppController.BridgePrefab.transform.localScale, this.block.transform);
                    QuantityOfBridges++;
                }
            }
        }
    }
Esempio n. 8
0
        public void initializeTest()
        {
            var advent1 = new Adventurer {
                PosX = 0, PosY = 0, MovementList = "A", Name = "Indiana", FinishMoving = false, PlayerOrientation = "S", Treasures = 0
            };
            var advent2 = new Adventurer {
                PosX = 1, PosY = 3, MovementList = "ADDGA", Name = "Shia", FinishMoving = false, PlayerOrientation = "O", Treasures = 0
            };

            adventurers = new List <IAdventurer> {
                advent1, advent2
            };
            var mountain = new Mountain(1, 1)
            {
                GotAdventurer = false, tileType = TileType.MOUNTAIN
            };
            var treasure = new Treasure(2, 2, 2)
            {
                GotAdventurer = false, tileType = TileType.TREASURE
            };

            map = new Map(5, 5);
            map.AddMountainToMap(mountain);
            map.AddTreasureToMap(treasure);
            map.TileMap[0, 0].GotAdventurer = true;
            map.TileMap[1, 3].GotAdventurer = true;
        }
        public async Task <IActionResult> Edit(int id, [Bind("Name,IsDeleted,DeletedOn,Id,CreatedOn,ModifiedOn")] Mountain mountain)
        {
            if (id != mountain.Id)
            {
                return(this.NotFound());
            }

            if (this.ModelState.IsValid)
            {
                try
                {
                    this.dataRepository.Update(mountain);
                    await this.dataRepository.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!this.MountainExists(mountain.Id))
                    {
                        return(this.NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }

                return(this.RedirectToAction(nameof(this.Index)));
            }

            return(this.View(mountain));
        }
Esempio n. 10
0
    public virtual float[,] CreateMountains()
    {
        bool         canCreateMountain;
        List <float> heights = new List <float>();

        //Debug.Log(Length);

        for (int j = 0; j < Length; j++)
        {
            for (int i = 0; i < Length; i++)
            {
                if (IsInGrasslands(i, j))
                {
                    Map[j, i] = 0f;
                    continue;
                }
                canCreateMountain = true;

                foreach (var m in Mountains)
                {
                    canCreateMountain &= m.CanCreateNewMountain(i, j);
                }

                if (canCreateMountain && GetRandomChance(Hillyness) && Mountains.Count <= MaxNumberOfMountainsAtOneTime)
                {
                    var   radius = 0f;
                    float h      = GetRandomHillHeight();
                    h = (1 / (11 - h));
                    do
                    {
                        radius = (GetRandomHillWidth() / 10f) * Length / 2f;
                    }while (radius == 0 && Mathf.Asin(h * TerrainHeight / radius) * (180f / Mathf.PI) > 35);

                    //radius = radius * Length * Length;
                    var centerX = radius + i;
                    var centerY = radius + j;
                    Mountains.Add(new Mountain(radius, (int)centerX, (int)centerY, h * RegionBase.TerrainMaxHeight));
                }

                heights.Clear();
                var tempMountain = new Mountain[Mountains.Count];
                Mountains.CopyTo(tempMountain);

                foreach (var m in tempMountain)
                {
                    if (m.IsInMountain(i, j))
                    {
                        heights.Add(m.HeightAtPosition(i, j));
                    }
                    else if (m.CanRemoveMountain(i, j))
                    {
                        Mountains.Remove(m);
                    }
                }

                Map[j, i] = heights.Count == 0 ? 0f : GetMaxHeight(heights);
            }
        }
        return(Map);
    }
Esempio n. 11
0
        public static void Parse(Mountain mountain)
        {
            var raw   = mountain.Name;
            var alias = string.Empty;
            var name  = string.Empty;

            var inAlias = false;

            foreach (var @char in mountain.Name)
            {
                if (@char == '[')
                {
                    inAlias = true;
                    alias   = string.Empty;
                }
                else if (@char == ']')
                {
                    inAlias = false;
                    mountain.Aliases.Add(alias.Trim());
                }
                else if (inAlias)
                {
                    alias += @char;
                }
                else
                {
                    name += @char;
                }
            }

            mountain.Name = name.Trim();
        }
        public void Add(string mountainName, string countryName)
        {
            bool isExist = Exists(mountainName);

            if (isExist)
            {
                throw new ArgumentException(String.Format(ServiceExceptionMessage.ExistingMountain, mountainName));
            }

            int countryId = this.context.Countries
                            .Where(x => x.Name == countryName)
                            .Select(x => x.CountryId)
                            .FirstOrDefault();

            if (countryId == 0)
            {
                throw new ArgumentException(String.Format(ServiceExceptionMessage.InvalidMountainCountryMessage, countryName));
            }

            Mountain mountain = new Mountain()
            {
                Name      = mountainName,
                CountryId = countryId
            };

            this.context.Mountains.Add(mountain);
            this.context.SaveChanges();
        }
Esempio n. 13
0
        public void initializeTest()
        {
            instruct = new InstructionDto();

            var advent1 = new Adventurer {
                PosX = 0, PosY = 0, MovementList = "A", Name = "Indiana", FinishMoving = false, PlayerOrientation = "S", Treasures = 0
            };
            var advent2 = new Adventurer {
                PosX = 3, PosY = 3, MovementList = "ADDGA", Name = "Shia", FinishMoving = false, PlayerOrientation = "O", Treasures = 0
            };

            instruct.adventurer = new List <IAdventurer> {
                advent1, advent2
            };
            instruct.mapSizeX = 5;
            instruct.mapSizeY = 5;
            var mountain = new Mountain(1, 1)
            {
                GotAdventurer = false, tileType = TileType.MOUNTAIN
            };
            var treasure = new Treasure(2, 2, 2)
            {
                GotAdventurer = false, tileType = TileType.TREASURE
            };

            instruct.tiles = new List <ITile> {
                mountain, treasure
            };
            map           = new Map(5, 5);
            loopClassTest = new LoopClass(map);
            //Assert
        }
Esempio n. 14
0
      public async Task <IActionResult> Edit(int id, [Bind("MountainId,MountainName,Elevation,Difficulty")] Mountain mountain)
      {
          if (id != mountain.MountainId)
          {
              return(NotFound());
          }

          if (ModelState.IsValid)
          {
              try
              {
                  _context.Update(mountain);
                  await _context.SaveChangesAsync();
              }
              catch (DbUpdateConcurrencyException)
              {
                  if (!MountainExists(mountain.MountainId))
                  {
                      return(NotFound());
                  }
                  else
                  {
                      throw;
                  }
              }
              return(RedirectToAction(nameof(Index)));
          }
          return(View(mountain));
      }
Esempio n. 15
0
    private void Awake()
    {
        // Assigning all the gameobjects that our goat needs to interact with.
        _mountain = GameObject.Find("Mountain").GetComponent <Mountain>();
        _ground   = GameObject.Find("GroundMesh").GetComponent <Ground>();
        _cannon   = GameObject.Find("GoatCannon").GetComponent <Cannon>();
        _forces   = GameObject.Find("Environment Forces").GetComponent <EnvironmentForces>();

        // Extracting the attributes needed for physics.
        _angle            = _cannon.Angle;
        _initialVelocity  = _cannon.Velocity;
        _gravity          = _forces.Gravity;
        _airResistance    = _forces.AirResistance;
        _myVerlets        = new List <Verlet>();
        _mountainVertices = new List <Vector3>();
        _groundVertices   = new List <Vector3>();
        _lines            = new List <LineRenderer>();

        CreateVerlets();
        // Initialize the forces acting upon the verlet(s) to be 0 at start.
        foreach (var verlet in _myVerlets)
        {
            verlet.CurrentForce = Vector3.zero;
        }
    }
Esempio n. 16
0
        public void GameDataConstructor_TravelerAndBoard_TravelerNullException()
        {
            void Excecute()
            {
                int           peopleLimit   = 3;
                EndStep       endStep       = new EndStep();
                Mountain      mountain      = new Mountain(peopleLimit, endStep);
                Ocean         ocean         = new Ocean(peopleLimit, mountain);
                ThermalWaters thermalWaters = new ThermalWaters(peopleLimit, ocean);
                Farm          farm          = new Farm(peopleLimit, thermalWaters);
                FirstStep     firstStep     = new FirstStep(farm);
                List <Step>   steps         = new List <Step>();

                steps.Add(farm);
                steps.Add(thermalWaters);
                steps.Add(ocean);
                steps.Add(mountain);
                Board           board     = new Board(steps, firstStep, endStep);
                List <Traveler> travelers = new List <Traveler>();

                travelers.Add(null);
                travelers.Add(null);
                GameData data = new GameData(travelers, board);
            }

            Assert.Throws(typeof(TravelerNullException), Excecute);
        }
Esempio n. 17
0
        // ------------ Methods to create unwalkable areas such as mountains and forests ------------\\



        /// <summary>
        /// Replaces walls with mountains/forests/unwalkables
        /// </summary>
        // TODO: Include mountains
        private void replaceWalls()
        {
            Mountain mountain = new Mountain();
            Grass    grass    = new Grass();

            // Trying mountains first:
            for (int y = 0; y < height; y++)
            {
                for (int x = 0; x < width; x++)
                {
                    if (map[x, y] == WALL)
                    {
                        if (Shapes.CanFitShapeOver(WALL, new Point(x, y), Shapes.GetShape(Shapes.TRIPLEx3_LEFT), map))
                        {
                            PlaceMountain(new Point(x, y), mountain.GetSpriteID(), GRASS2_SPRITEID, mountain.Shape);
                        }
                    }
                }
            }

            // Filling with forests where mountains do not fill.
            for (int y = 0; y < height; y++)
            {
                for (int x = 0; x < width; x++)
                {
                    if (map[x, y] == WALL)
                    {
                        FloodFillWall(new Point(x, y), FOREST_SPRITEID);
                    }
                }
            }
        }
Esempio n. 18
0
        public void AddMountainToMap_ShouldThrowIfMoutainAlreadyOnTile()
        {
            Mountain mountain = new Mountain(5, 5);

            TestMap.AddMountainToMap(mountain);
            TestMap.AddMountainToMap(mountain);
        }
Esempio n. 19
0
        public MountainResource Convert(Mountain mountain)
        {
            var mountainResource = _mapper.Map <MountainResource>(mountain);

            mountainResource.Location = _locationConverter.Convert(mountain.Latitude, mountain.Longitude, mountain.Location.RegionName);
            mountainResource.Trails   = mountain.MountainTrail.Select(x => _mountainTrailResourceConverter.Convert(x));
            return(mountainResource);
        }
Esempio n. 20
0
        public void AddMountainToMap_ShouldAddMountainTileToMap()
        {
            Mountain mountain = new Mountain(5, 5);

            TestMap.AddMountainToMap(mountain);

            Assert.AreEqual(TileType.MOUNTAIN, TestMap.TileMap[5, 5].tileType);
        }
Esempio n. 21
0
 public Map()
 {
     Forest   = new Forest();
     Mountain = new Mountain();
     Lake     = new Lake();
     Castle   = new Castle();
     Cave     = new Cave();
 }
Esempio n. 22
0
 // Distribute n tiles to hand
 void distribute(Mountain mountain, Player player, int n)
 {
     for (int i = 0; i < n; i++)
     {
         GameObject tile = mountain.take();
         player.initTileInHand(tile);
     }
 }
Esempio n. 23
0
 public MountainSummaryModel(Mountain mountain)
 {
     Id        = mountain.Id;
     Name      = mountain.Name;
     Height    = mountain.Height.ToString();
     Latitude  = mountain.Location.Latitude;
     Longitude = mountain.Location.Longitude;
 }
Esempio n. 24
0
        /// <summary>If the user for this mod never gets the event that makes the railroad blok go away we will always force it to go away if they have met the conditions for it. I.E not being in spring of year 1.</summary>
        private void clearRailRoadBlock()
        {
            Mountain mountain = (Mountain)Game1.getLocationFromName("Mountain");

            var netBool2 = this.Helper.Reflection.GetField <NetBool>(mountain, "railroadAreaBlocked").GetValue();

            netBool2.Value = false;

            this.Helper.Reflection.GetField <Rectangle>(mountain, "railroadBlockRect").SetValue(Rectangle.Empty);
        }
    private static void ImportMountain(JToken mountainObj)
    {
        var context = new MountainsContext();
        var mountain = new Mountain();

        // Parse mountain
        if (mountainObj["mountainName"] == null)
        {
            throw new Exception("Missing mountain name");
        }
        mountain.Name = mountainObj["mountainName"].Value<string>();

        // Parse peaks
        var peaks = mountainObj["peaks"];
        if (peaks != null)
        {
            foreach (var peak in peaks)
            {
                if (peak["peakName"] == null)
                {
                    throw new Exception("Missing peak name");
                }
                string peakName = peak["peakName"].Value<string>();

                if (peak["elevation"] == null)
                {
                    throw new Exception("Missing peak elevation");
                }
                int elevation = peak["elevation"].Value<int>();

                mountain.Peaks.Add(new Peak() { Name = peakName, Elevation = elevation});
            }
        }

        // Parse countries
        var countryNames = mountainObj["countries"];
        if (countryNames != null)
        {
            foreach (var countryName in countryNames)
            {
                var countryCode =
                    new string(countryName.Value<string>().Take(2).ToArray()).ToUpper();
                var country = context.Countries.Find(countryCode);
                if (country == null)
                {
                    country = new Country() { Code = countryCode, Name = countryName.Value<string>() };
                }
                mountain.Countries.Add(country);
            }
        }

        // Persist the mountain in the database
        context.Mountains.Add(mountain);
        context.SaveChanges();
    }
Esempio n. 26
0
      public async Task <IActionResult> Create([Bind("MountainId,MountainName,Elevation,Difficulty")] Mountain mountain)
      {
          if (ModelState.IsValid)
          {
              _context.Add(mountain);
              await _context.SaveChangesAsync();

              return(RedirectToAction(nameof(Index)));
          }
          return(View(mountain));
      }
Esempio n. 27
0
        protected override void Seed(MountainsContext context)
        {
            if (!context.Countries.Any())
            {
                Country bulgaria = new Country()
                {
                    Code = "BG",
                    Name = "Bulgaria"
                };
                context.Countries.Add(bulgaria);

                Country germany = new Country()
                {
                    Code = "DE",
                    Name = "Bulgaria"
                };
                context.Countries.Add(germany);

                Mountain pirin = new Mountain {
                    Name = "Pirin", Countries = { bulgaria }
                };
                context.Mountains.Add(pirin);

                Mountain rila = new Mountain {
                    Name = "Rila", Countries = { bulgaria }
                };
                context.Mountains.Add(rila);

                Mountain rhodopes = new Mountain {
                    Name = "Rhodopes", Countries = { bulgaria }
                };
                context.Mountains.Add(rhodopes);

                Peak musala = new Peak()
                {
                    Name = "Musala", Mountain = rila, Elevation = 2925
                };
                context.Peaks.Add(musala);

                Peak malyovitsa = new Peak()
                {
                    Name = "Malyovitsa ", Mountain = rila, Elevation = 2729
                };
                context.Peaks.Add(malyovitsa);

                Peak vihren = new Peak()
                {
                    Name = "Vihren", Mountain = pirin, Elevation = 2914
                };
                context.Peaks.Add(vihren);

                context.SaveChanges();
            }
        }
Esempio n. 28
0
        protected override void Seed(MountainsContext context)
        {
            if (context.Countries.Any())
            {
                return;
            }

            var bulgaria = new Country {
                Code = "BG", Name = "Bulgaria"
            };

            context.Countries.Add(bulgaria);
            var germany = new Country {
                Code = "DE", Name = "Germany"
            };

            context.Countries.Add(germany);

            var rila = new Mountain {
                Name = "Rila", Countries = { bulgaria }
            };

            context.Mountains.Add(rila);
            var pirin = new Mountain {
                Name = "Pirin", Countries = { bulgaria }
            };

            context.Mountains.Add(pirin);
            var rhodopes = new Mountain {
                Name = "Rhodopes", Countries = { bulgaria }
            };

            context.Mountains.Add(rhodopes);

            var musala = new Peak {
                Name = "Musala", Elevation = 2925, Mountain = rila
            };

            context.Peaks.Add(musala);
            var malyovitsa = new Peak {
                Name = "Malyovitsa", Elevation = 2729, Mountain = rila
            };

            context.Peaks.Add(malyovitsa);
            var vihren = new Peak {
                Name = "Vihren", Elevation = 2914, Mountain = pirin
            };

            context.Peaks.Add(vihren);

            base.Seed(context);
        }
Esempio n. 29
0
        private void buttonSearch_Click(object sender, EventArgs e)
        {
            bool   found   = false;
            string sNumber = textBoxSearch.Text;

            if (radioButtonMountain.Checked == true)
            {
                Mountain temp = new Mountain();

                foreach (Mountain bike in listBikeMountain)
                {
                    if (String.Compare(bike.SerialNumber, sNumber) == 0)
                    {
                        temp  = bike;
                        found = true;
                        break;
                    }
                }

                if (found)
                {
                    MessageBox.Show("Mountain Bike Found....\n" + temp);
                }
                else
                {
                    MessageBox.Show("Mountain Bike Not Found");
                }
            }
            else if (radioButtonRoad.Checked == true)
            {
                Road temp = new Road();

                foreach (Road bike in listBikeRoad)
                {
                    if (string.Equals(bike.SerialNumber, sNumber))
                    {
                        temp  = bike;
                        found = true;
                        break;
                    }
                }

                if (found)
                {
                    MessageBox.Show("Road Bike Found....\n" + temp);
                }
                else
                {
                    MessageBox.Show("Road Bike Not Found");
                }
            }
        }
        public async Task <IActionResult> Create([Bind("Name,IsDeleted,DeletedOn,Id,CreatedOn,ModifiedOn")] Mountain mountain)
        {
            if (this.ModelState.IsValid)
            {
                await this.dataRepository.AddAsync(mountain);

                await this.dataRepository.SaveChangesAsync();

                return(this.RedirectToAction(nameof(this.Index)));
            }

            return(this.View(mountain));
        }
Esempio n. 31
0
        private static void ImportMountain(MountainDTO mountainDTO)
        {
            var context = new MountainsContext();

            // Parse mountain
            if (mountainDTO.MountainName == null)
            {
                throw new Exception("Missing mountain name");
            }
            var mountainToImport = new Mountain {
                Name = mountainDTO.MountainName
            };

            // Parse peaks optional
            foreach (var peakDto in mountainDTO.Peaks)
            {
                if (peakDto.PeakName == null)
                {
                    throw new Exception("Missing peak name");
                }
                if (peakDto.Elevation == null)
                {
                    throw new Exception("Missing peak elevation");
                }

                mountainToImport.Peaks.Add(new Peak()
                {
                    Name      = peakDto.PeakName,
                    Elevation = peakDto.Elevation.GetValueOrDefault()
                });
            }

            // Parse countries optional
            foreach (var countryName in mountainDTO.Countries)
            {
                var country = context.Countries.FirstOrDefault(c => c.Name == countryName);
                if (country == null)
                {
                    country = new Country()
                    {
                        Code = countryName.ToUpper().Substring(0, 2),
                        Name = countryName
                    };
                }

                mountainToImport.Countries.Add(country);
            }

            context.Mountains.Add(mountainToImport);
            context.SaveChanges();
        }
Esempio n. 32
0
        private static void ImportMountain(MountainJson mountain)
        {
            var context = new MountainsContext();

            if (string.IsNullOrEmpty(mountain.MountainName))
            {
                throw new ArgumentException("Mountain name is required.");
            }

            var peaks = new List<Peak>();
            foreach (var peak in mountain.Peaks)
            {
                if (string.IsNullOrEmpty(peak.PeakName))
                {
                    throw new ArgumentException("Peak name is required.");
                }

                if (peak.Elevation == null)
                {
                    throw new ArgumentException("Peak elevation is required.");
                }

                var dataPeak = new Peak()
                {
                    Name = peak.PeakName,
                    Elevation = (int)peak.Elevation
                };

                peaks.Add(dataPeak);
            }

            var countries = mountain.Countries
                .Select(country => new Country()
                {
                    CountryName = country,
                    CountryCode = country.Substring(0, 2).ToUpper()
                })
                .ToList();

            var dataMountain = new Mountain()
            {
                Name = mountain.MountainName,
                Countries = countries,
                Peaks = peaks
            };

            context.Mountains.AddOrUpdate(dataMountain);
            context.SaveChanges();
        }
Esempio n. 33
0
 public List<Structure> CreateMountains(Vector3 location, Vector3 bounds, float scale, int number)
 {
     var mountains = new List<Structure>();
     var parent = new GameObject("Mountains");
     for (var i = 0; i < number; i++)
     {
         var size = Random.Range(0.3f * scale, scale) * Vector3.one;
         var pos = location + Vector3.Scale(bounds, Util.RandomVector());
         var mountain = new Mountain(pos, size);
         mountain.Color(Color.white);
         mountain.gameObject.transform.SetParent(parent.transform);
         mountains.Add(mountain);
     }
     return mountains;
 }
Esempio n. 34
0
	// Use this for initialization
	void Start()
	{
		Mountain = GameObject.FindGameObjectWithTag("Mountain").GetComponent<Mountain>();
		ActiveCube = GetStartCube();
		Player.transform.position = ActiveCube.transform.position + new Vector3(0f, 1f, 0f);
	}
Esempio n. 35
0
	protected virtual void Start()
	{
		Mountain = GameObject.FindGameObjectWithTag("Mountain").GetComponent<Mountain>();
    }
Esempio n. 36
0
	// Use this for initialization
	protected virtual void Start()
    {
        Mountain = GetComponent<Mountain>();
		ConsumeFirstRow();
	}
Esempio n. 37
0
        static void Main(string[] args)
        {
            Console.WriteLine("Welcome to this game");
            Console.WriteLine("What is your name?");
            string playerName = Console.ReadLine();
            Player gamePlayer = null;

            // Ask player if they want to load a save
            Console.WriteLine("Do you want to load your previous save? (y/n)");
            string loadSaveResponse = Console.ReadLine();
            if (loadSaveResponse == "y")
            {
                gamePlayer = SaveAndLoad.load(playerName);
            }
            else
            {
                Console.WriteLine("Starting new character");
            }

            // Creates player with given name, 20 health, 5 damage, 10 coins, 25% crit chance, 0 armor points, 40% block chance
            if (gamePlayer == null)
            {
                gamePlayer = new Player(playerName, 20, 5, 10, 25, 0, 40);
            }
            Forest fightForest = new Forest((new List<Monster> { new Monster(10, 75, 1, 1, "Beetle"),
                                                                 new Monster(20, 50, 3, 2, "Bear"),
                                                                 new Monster(15, 20, 5, 2, "mountainLionThing"),
                                                                 new Monster(25, 50, 5, 3, "Wild Beast"),
                                                                 new Monster(35, 35, 10, 15, "advancedBeetle")
                                                                 }).AsQueryable<Monster>());
            Mountain bossMountain = new Mountain((new List<Boss> { new Boss("Gondlaf The Passable", 25, 50, 10, 25, 10, 40), new Boss("Superboss", 25, 40, 15, 50, 25, 25) }.AsQueryable<Boss>()));
            // TODO: Add more items to shop
            Shop buyShop = new Shop((new List<Item> { new Weapon("basicSword", 7, 20, 2),
                                                      new Armor("basicChestplate", 25, 3, 25),
                                                      new Potion("basicPotion", 10, 5, 5),
                                                      new Weapon("advancedSword", 11, 35, 1),
                                                      new Armor("advancedChestplate", 40, 2, 50),
                                                      new Potion("advancedPotion", 20, 1, 15),
                                                      new Weapon("superSword", 20, 55, 3),
                                                      new Armor("superChestplate", 60, 1, 75)
                                                      } ).AsQueryable<Item>());

            // Greets player and prompts, begins game
            Console.WriteLine("Hello " + gamePlayer.name + "!");
            while (true)
            {
                Console.WriteLine("You have " +
                                  gamePlayer.health +
                                  " health, " +
                                  gamePlayer.coins +
                                  " coins, " +
                                  gamePlayer.damage +
                                  " damage per hit, a " +
                                  gamePlayer.critChance +
                                  "% crit chance, " +
                                  gamePlayer.armorPoints +
                                  " armor points, and are level " +
                                  gamePlayer.level +
                                  ".");
                Console.WriteLine("What would you like to do? (village, forest, mountain, or shop)");

                string choice = Console.ReadLine();
                if (choice == "village" || choice == "v")
                {
                    // Player heals at village
                    Console.WriteLine("You have slept at the village. You are healed.");
                    gamePlayer.fillHealth();
                }
                else if (choice == "forest" || choice == "f")
                {
                    // Player goes to forest to fight monsters
                    Console.WriteLine("You have gone to the forest. Are you ready to fight? (y/n)");
                    string answer = Console.ReadLine();
                    if (answer.Equals("y"))
                    {
                        // Player is ready to fight. Choose monster and begin
                        Monster fightMonster = fightForest.chooseMonster(gamePlayer.level);
                        Console.WriteLine("You are a fighting a " + fightMonster.name + ".");
                        if (fightForest.fight(gamePlayer, fightMonster))
                        {
                            if (fightMonster.isEvaded)
                            {
                                // Monster was evaded; do not give gold
                                Console.WriteLine("You successfully evaded the monster!");
                            }
                            else
                            {
                                // Monster was defeated; give gold and increase level
                                Console.WriteLine("You successfully defeated the monster.");
                                int lootGold = fightForest.lootCalc(fightMonster.level);
                                Console.WriteLine("You looted " + lootGold + " gold from the monster.");
                                gamePlayer.coins += lootGold;
                                gamePlayer.level += 1;
                            }
                        }
                        else
                        {
                            // Player defeated.
                            Console.WriteLine("You were defeated. Luckily, a kindly villager found you, " +
                            "brought you back to the village and healed you, but not before looters found you. " +
                            "You have lost all your belongings.");
                            gamePlayer.clearInv();
                            gamePlayer.fillHealth();
                            gamePlayer.deadLevel();
                        }
                    }
                    else
                    {
                        // Player is not ready to fight. Return to choice menu
                        Console.WriteLine("Returning to choice menu.");
                    }
                }
                else if (choice == "shop" || choice == "s")
                {
                    // Player goes to shop to buy items
                    Console.WriteLine("You are at the shop. You have " + gamePlayer.coins + " coins.");
                    Console.WriteLine("Shop items: ");
                    int i = 0;
                    foreach (Item cItem in buyShop.availableItems)
                    {
                        // List each available item in shop
                        if (cItem is Weapon)
                        {
                            Weapon cItemWeapon = null;
                            try
                            {
                                cItemWeapon = (Weapon)cItem;
                            }
                            catch (InvalidCastException e)
                            {

                            }
                            Console.WriteLine(i + ". {0} is a weapon hitting {1} damage, with {2} in stock at {3} coins each.", cItemWeapon.name, cItemWeapon.damage, cItemWeapon.stock, cItemWeapon.cost);
                        }
                        else if (cItem is Armor)
                        {
                            Armor cItemArmor = null;
                            try
                            {
                                cItemArmor = (Armor)cItem;
                            }
                            catch (InvalidCastException e)
                            {

                            }
                            Console.WriteLine(i + ". {0} is an armor piece with {1} points, {2} in stock at {3} coins each.", cItemArmor.name, cItemArmor.armorPoints, cItemArmor.stock, cItemArmor.cost);
                        }
                        else if (cItem is Potion)
                        {
                            Potion cItemPotion = null;
                            try
                            {
                                cItemPotion = (Potion)cItem;
                            }
                            catch (InvalidCastException e)
                            {

                            }
                            Console.WriteLine(i + ". {0} is a potion healing {1} points, with {2} in stock at {3} coins each.", cItemPotion.name, cItemPotion.healPoints, cItemPotion.stock, cItemPotion.cost);
                        }
                        i++;
                    }

                    // Loop through purchases until user chooses to leave
                    while (true)
                    {
                        // Receive user input of which item to buy
                        Console.WriteLine("Write index of item you want to buy, or type nothing to leave.");
                        string input = Console.ReadLine();

                        if (input == "")
                        {
                            // User does not want to buy anything, leave shop
                            break;
                        }
                        else
                        {
                            // Check if user can buy item specified
                            Item chosenItem = buyShop.availableItems.ToList<Item>()[Int32.Parse(input)];
                            if (gamePlayer.coins >= chosenItem.cost)
                            {
                                // User has enough coins to purchase; check stock
                                if (buyShop.buyItem(chosenItem))
                                {
                                    gamePlayer.coins -= chosenItem.cost;
                                    Console.WriteLine("You have purchased the item. You now have " + gamePlayer.coins + " coins.");

                                    if (chosenItem is Weapon)
                                    {
                                        Weapon chosenItemWeapon = null;
                                        try { chosenItemWeapon = (Weapon)chosenItem; }
                                        catch (InvalidCastException e) { }
                                        gamePlayer.damage = chosenItemWeapon.damage;
                                    }
                                    else if (chosenItem is Armor)
                                    {
                                        Armor chosenItemArmor = null;
                                        try { chosenItemArmor = (Armor)chosenItem; }
                                        catch (InvalidCastException e) { }
                                        gamePlayer.armorPoints = chosenItemArmor.armorPoints;
                                    }
                                    else if (chosenItem is Potion)
                                    {
                                        Potion chosenItemPotion = null;
                                        try { chosenItemPotion = (Potion)chosenItem; }
                                        catch (InvalidCastException e) { }
                                        gamePlayer.inventory.Add(chosenItemPotion);
                                    }
                                }
                            }
                            else
                            {
                                // User does not have enough coins to purchase. Loop again
                                Console.WriteLine("You do not have enough coins! You have " + gamePlayer.coins + " coins.");
                            }

                        }
                    }
                }
                else if (choice == "mountain" || choice == "m")
                {
                    Console.WriteLine("You have gone to the mountain. Are you sure you want to fight a boss?");
                    Console.WriteLine("Bosses are very difficult and you should not attempt to fight one if you are lower than level 10.");
                    Console.WriteLine("(y/n)");
                    string confirmChoice = Console.ReadLine();

                    if (confirmChoice == "y")
                    {
                        // Player is sure that they want to fight a boss
                        Boss fightBoss = bossMountain.chooseBoss(gamePlayer.level);
                        if (bossMountain.fight(gamePlayer, fightBoss))
                        {
                            // Player "won" battle, either through boss defeat or evasion
                            if (fightBoss.isEvaded)
                            {
                                // Player evaded boss; do not give gold or level
                                Console.WriteLine("You successfully evaded the boss!");
                            }
                            else
                            {
                                // Player defeated boss; give gold and level
                                Console.WriteLine("You successfully defeated the monster!");
                                int lootGold = bossMountain.lootCalc(fightBoss.level);
                                Console.WriteLine("You looted " + lootGold + " from the boss.");
                                gamePlayer.coins += lootGold;
                                gamePlayer.level += (fightBoss.level / 2);
                            }
                        }
                        else
                        {
                            // Player defeated.
                            Console.WriteLine("You were defeated. Luckily, a kindly villager found you, " +
                            "brought you back to the village and healed you, but not before looters found you. " +
                            "You have lost all your belongings.");
                            gamePlayer.clearInv();
                            gamePlayer.fillHealth();
                            gamePlayer.deadLevel();
                        }
                    }
                }
                else if (choice == "exit" || choice == "e")
                {
                    Console.WriteLine("Are you sure you want to leave? (y/n)");
                    if (Console.ReadLine() == "y")
                    {
                        Environment.Exit(0);
                    }
                }
                else if (choice == "save")
                {
                    Console.WriteLine("Saving to " + gamePlayer.name + "-Save.txt");
                    SaveAndLoad.save(gamePlayer);
                }
                else
                {
                    // Unrecognized command
                    Console.WriteLine("I don't recognize that command.");
                }

                Console.Write("\r\n");
            }
        }
Esempio n. 38
0
	void Awake()
	{
		Instance = this;
	}
Esempio n. 39
0
	// Use this for initialization
	void Start ()
	{
		Player = PlayerController.Instance;
		InputController = SimpleController.Instance;
		Mountain = Mountain.Instance;
	}