示例#1
0
        public void Highlighting_a_branch_that_does_exist_highlights_only_that_branch()
        {
            // Given
            var unused             = 0.0;
            var width              = 1000;
            var height             = 2000;
            var viewControlData    = new ViewControlData(unused, unused, unused, width, height);
            var releaseBranchName  = "ReleaseBranch";
            var unusedColour       = Color.FromRgb(255, 255, 255);
            var releaseArchipelago = new Branch(releaseBranchName, unusedColour);

            Islands islands = new Islands(viewControlData, releaseArchipelago);

            var branch  = new Branch("existingBranch", unusedColour);
            var branch2 = new Branch("anotherBranch", unusedColour);

            // this is a bit of a kludge, really, we should be mocking
            double[] islandStrokeThicknessesBeforeHighlighting =
            {
                branch.Shape.MainIslandShape.Shape.StrokeThickness,
                releaseArchipelago.Shape.MainIslandShape.Shape.StrokeThickness,
                branch2.Shape.MainIslandShape.Shape.StrokeThickness
            };

            islands.Add(branch);
            islands.Add(branch2);

            // When
            islands.Highlight("existingBranch");

            // Then
            Assert.AreNotEqual(islandStrokeThicknessesBeforeHighlighting[0], branch.Shape.MainIslandShape.Shape.StrokeThickness);
            Assert.AreEqual(islandStrokeThicknessesBeforeHighlighting[1], releaseArchipelago.Shape.MainIslandShape.Shape.StrokeThickness);
            Assert.AreEqual(islandStrokeThicknessesBeforeHighlighting[2], branch2.Shape.MainIslandShape.Shape.StrokeThickness);
        }
示例#2
0
        public void Branch_moves_to_collision_free_location_instead_of_rotated_location_when_there_is_a_collision()
        {
            // Given
            CreateMockFactory();
            var collisionFreeLocation = new System.Windows.Point(999, 999);

            _mockCollisionDetector.Setup(m => m.GetNearestFreeLocation(It.IsAny <IslandShape>(),
                                                                       It.IsAny <IslandShape>())).Returns(collisionFreeLocation); // forcing a collision

            var unused             = 0.0;
            var width              = 1000;
            var height             = 2000;
            var viewControlData    = new ViewControlData(unused, unused, unused, width, height);
            var releaseBranchName  = "ReleaseBranch";
            var unusedColour       = Color.FromRgb(255, 255, 255);
            var releaseArchipelago = new Branch(releaseBranchName, unusedColour);

            Islands islands = new Islands(viewControlData, releaseArchipelago);

            var branch = new Branch("mr branch", unusedColour);

            branch.Distance = 50;
            islands.Add(branch);

            // When
            islands.MoveAll();

            // Then
            var branchCentre = branch.Shape.CentrePoint;

            Assert.AreEqual(collisionFreeLocation.X, branchCentre.X);
            Assert.AreEqual(collisionFreeLocation.Y, branchCentre.Y);
        }
示例#3
0
        public void Setting_an_islands_distance()
        {
            // Given
            var unused             = 0.0;
            var width              = 1000;
            var height             = 2000;
            var viewControlData    = new ViewControlData(unused, unused, unused, width, height);
            var releaseBranchName  = "ReleaseBranch";
            var unusedColour       = Color.FromRgb(255, 255, 255);
            var releaseArchipelago = new Branch(releaseBranchName, unusedColour);

            Islands islands = new Islands(viewControlData, releaseArchipelago);

            var branch = new Branch("existingBranch", unusedColour);

            islands.Add(branch);

            var distanceToSet = 123.45;

            islands.SetBranchDistance("existingBranch", distanceToSet);

            // When
            var actualDistance = islands.GetDistance("existingBranch");

            // Then
            var expectedDistance = distanceToSet;

            Assert.AreEqual(expectedDistance, actualDistance);
        }
示例#4
0
        public void An_island_does_not_exist_if_it_has_been_deleted()
        {
            // Given
            var unused             = 0.0;
            var width              = 1000;
            var height             = 2000;
            var viewControlData    = new ViewControlData(unused, unused, unused, width, height);
            var releaseBranchName  = "ReleaseBranch";
            var unusedColour       = Color.FromRgb(255, 255, 255);
            var releaseArchipelago = new Branch(releaseBranchName, unusedColour);

            Islands islands = new Islands(viewControlData, releaseArchipelago);

            var branch  = new Branch("existingBranch", unusedColour);
            var branch2 = new Branch("branch-to-delete", unusedColour);
            var branch3 = new Branch("anotherBranch", unusedColour);

            islands.Add(branch);
            islands.Add(branch2);
            islands.Add(branch3);

            // When
            islands.Delete("branch-to-delete");

            // Then
            var islandExists = islands.Contains("branch-to-delete");

            Assert.IsFalse(islandExists);
        }
示例#5
0
        public void Getting_an_islands_location_for_an_island_that_does_not_exist()
        {
            // Given
            var unused             = 0.0;
            var width              = 1000;
            var height             = 2000;
            var viewControlData    = new ViewControlData(unused, unused, unused, width, height);
            var releaseBranchName  = "ReleaseBranch";
            var unusedColour       = Color.FromRgb(255, 255, 255);
            var releaseArchipelago = new Branch(releaseBranchName, unusedColour);

            Islands islands = new Islands(viewControlData, releaseArchipelago);

            // When
            bool exceptionRaised = false;

            try
            {
                islands.GetLocation("branch-that-does-not-exist");
            }
            catch (IndexOutOfRangeException)
            {
                exceptionRaised = true;
            }

            // Then
            Assert.IsTrue(exceptionRaised);
        }
示例#6
0
        public void Moving_with_one_island_added_moves_the_island()
        {
            // Given
            var unused             = 0.0;
            var width              = 100;
            var height             = 200;
            var viewControlData    = new ViewControlData(unused, unused, unused, width, height);
            var releaseBranchName  = "ReleaseBranch";
            var unusedColour       = Color.FromRgb(255, 255, 255);
            var releaseArchipelago = new Branch(releaseBranchName, unusedColour);

            Islands islands = new Islands(viewControlData, releaseArchipelago);

            var newBranchName = "bob";
            var newBranch     = new Branch(newBranchName, unusedColour);

            islands.Add(newBranch);

            // the island has never been moved
            Assert.AreEqual(0.0, newBranch.Shape.CentrePoint.X);
            Assert.AreEqual(0.0, newBranch.Shape.CentrePoint.Y);

            // When
            islands.MoveAll();

            // Then
            Assert.AreNotEqual(0.0, newBranch.Shape.CentrePoint.X);
            Assert.AreNotEqual(0.0, newBranch.Shape.CentrePoint.Y);
        }
示例#7
0
        private static IEnumerable <Classes.RevisionClass> _getItemRevisions(XElement item, string sRev, string StorageClass)
        {
            IEnumerable <XElement> Rev;

            Islands.TryGetValue(sRev, out Rev);
            Rev = Rev ?? Enumerable.Empty <XElement>();

            var Revisions = (from rev in Rev
                             where rev.Attribute("items_tag").Value == item.Attribute("puid").Value
                             select new Classes.RevisionClass {
                element = rev, masterRevForm = new RevisionClass.ItemRevMasterFormClass()
            }).ToList();

            if (Revisions.Count() == 0)
            {
                Revisions = (from rev in _xml.Elements(_ns + sRev)
                             where rev.Attribute("items_tag").Value == item.Attribute("puid").Value
                             select new Classes.RevisionClass {
                    element = rev, masterRevForm = new RevisionClass.ItemRevMasterFormClass()
                }).ToList();
            }

            if (Revisions.Count() == 0)
            {
                Global._errList.Add(new ErrorList.ErrorInfo(Global._mapCounter, ErrorCodes.REVISIONS_NOT_FOUND, item.Attribute("puid").Value, sRev, TCTypes.Item, item.Attribute("item_id").Value));
            }

            foreach (var r in Revisions)
            {
                r.masterRevForm = new RevisionClass.ItemRevMasterFormClass(r.element, StorageClass);
            }

            return(Revisions);
        }
示例#8
0
        public void Removing_an_island_and_getting_all_island_names_does_not_include_the_removed_island_in_the_list()
        {
            // Given
            var unused             = 0.0;
            var width              = 1000;
            var height             = 2000;
            var viewControlData    = new ViewControlData(unused, unused, unused, width, height);
            var releaseBranchName  = "ReleaseBranch";
            var unusedColour       = Color.FromRgb(255, 255, 255);
            var releaseArchipelago = new Branch(releaseBranchName, unusedColour);

            Islands islands = new Islands(viewControlData, releaseArchipelago);
            var     branch1 = new Branch("one", unusedColour);
            var     branch2 = new Branch("island-to-delete", unusedColour);
            var     branch3 = new Branch("three", unusedColour);

            islands.Add(branch1);
            islands.Add(branch2);
            islands.Add(branch3);

            islands.Delete("island-to-delete");

            // When
            var nameList = islands.GetAllNames();

            // Then
            var expectedCount = 2;
            var actualCount   = nameList.Count;

            Assert.AreEqual(expectedCount, actualCount);

            var islandToDeleteIsInTheList = nameList.Contains("island-to-delete");

            Assert.IsFalse(islandToDeleteIsInTheList);
        }
示例#9
0
        private static ItemClass _getItem(XElement rev, string sitem, string srev, string sMasterFormS, string smasterRevFormS)
        {
            //var islandElements = Islands[rev.Attribute("island_id").Value];
            IEnumerable <XElement> Item;

            Islands.TryGetValue(sitem, out Item);
            Item = Item ?? Enumerable.Empty <XElement>();

            try
            {
                ItemClass qItem = (from item in Item
                                   where item.Attribute("puid").Value == rev.Attribute("items_tag").Value
                                   select new ItemClass(item, srev, sMasterFormS, smasterRevFormS)).SingleOrDefault();


                //check if in another island
                if (qItem == null)
                {
                    qItem = (from item in _xml.Elements(_ns + sitem)
                             where item.Attribute("puid").Value == rev.Attribute("items_tag").Value
                             select new ItemClass(item, srev, sMasterFormS, smasterRevFormS)).Single();
                }

                return(qItem);
            }
            catch (System.Exception ex)
            {
                Global._errList.Add(new ErrorList.ErrorInfo(0, ErrorCodes.ITEM_NOT_FOUND, rev.Attribute("puid").Value, srev, TCTypes.ItemRevision, "<" + rev.Attribute("items_tag").Value + ">", rev.Attribute("item_revision_id").Value));

                return(null);
            }
        }
示例#10
0
    static private XElement[] _getMasterForm(XElement obj, string StorageClass)
    {
        //var islandElements = Islands[obj.Attribute("island_id").Value];
        IEnumerable <XElement> IM;

        Islands.TryGetValue("ImanRelation", out IM);
        IEnumerable <XElement> Form;

        Islands.TryGetValue("Form", out Form);
        IEnumerable <XElement> FormS;

        Islands.TryGetValue(StorageClass, out FormS);

        IM    = IM ?? Enumerable.Empty <XElement>();
        Form  = Form ?? Enumerable.Empty <XElement>();
        FormS = FormS ?? Enumerable.Empty <XElement>();

        var MasterForm = (from im in IM
                          join mForm in Form on im.Attribute("secondary_object").Value equals mForm.Attribute("puid").Value
                          join mFormS in FormS on mForm.Attribute("data_file").Value equals mFormS.Attribute("puid").Value into mf1
                          from mFormS in mf1.DefaultIfEmpty()
                          where obj.Attribute("puid").Value == im.Attribute("primary_object").Value&& im.Attribute("relation_type").Value == _IMAN_master_form
                          select new XElement[2] {
            mForm, mFormS
        }).SingleOrDefault();

        return(MasterForm);
    }
示例#11
0
        /// <summary>
        /// Used to get a random enemy from the current region
        /// </summary>
        /// <param name="currentRegion">The current region, used to determine what enemy to return</param>
        /// <returns>An instance of a random enemy of type IPixel</returns>
        public static IPixel GetEnemies(Islands island, RegionType currentRegion, Rarity rarity, int x, int y)
        {
            if (island == Islands.home)
            {
                possibleEnemies = GetPossible(rarity, currentRegion, x, y);
            }
            //if (currentRegion == RegionType.forest)
            //{
            //    var pixel = forestEnemies[rand.Next(0, forestEnemies.Count - 1)];
            //    IPixel pix = (IPixel)Activator.CreateInstance(pixel.GetType());

            //    return pix;
            //}

            IPixel pixel = null;

            if (possibleEnemies.Count > 1)
            {
                pixel = possibleEnemies[rand.Next(0, possibleEnemies.Count)];
            }
            else if (possibleEnemies.Count == 1)
            {
                pixel = possibleEnemies[0];
            }
            else
            {
                return(null);
            }
            IPixel pix = (IPixel)Activator.CreateInstance(pixel.GetType());

            return(pix);
        }
示例#12
0
    void CreateIslandConfiguration(Vector3 position)
    {
        Islands newIsland = new Islands();

        newIsland.position            = position;
        newIsland.islandConfiguration = islandBinary;

        islands.Add(newIsland);
    }
示例#13
0
        private Board BoardFromGrid()
        {
            int board_size = gameGrid.Rows.Count;

            int[][] grid = GetGrid(board_size);

            var islands = Islands.FromGrid(grid);

            return(Board.FromGrid(board_size, islands));
        }
示例#14
0
 // END CUT HERE
 // BEGIN CUT HERE
 public static void Main()
 {
     try {
     Islands ___test = new Islands();
     ___test.run_test(-1);
     } catch(Exception e) {
     //Console.WriteLine(e.StackTrace);
     Console.WriteLine(e.ToString());
     }
 }
示例#15
0
// END CUT HERE
// BEGIN CUT HERE
    public static void Main()
    {
        try {
            Islands ___test = new Islands();
            ___test.run_test(-1);
        } catch (Exception e) {
//Console.WriteLine(e.StackTrace);
            Console.WriteLine(e.ToString());
        }
    }
示例#16
0
        private void FillIslands(Islands islands)
        {
            foreach (var island in islands.GetAll())
            {
                var row    = island[0] - 1;
                var column = island[1] - 1;
                var size   = island[2];

                gameGrid.Rows[row].Cells[column].Value = size;
            }
        }
示例#17
0
        private void drawLandmass(SKCanvas canvas)
        {
            var features = pack.features;
            var chains   = map4Coastline.Paths;
            var paint    = new SKPaint()
            {
                IsAntialias = true
            };

            chains.Keys.forEach(f =>
            {
                var paths = chains[f];
                if (features[f].type == "lake")
                {
                    //landmask
                    paint.Style      = SKPaintStyle.Fill;
                    paint.Color      = Color.Black.SK();
                    paint.MaskFilter = null;
                    paths.ForEach(p => canvas.DrawPath(lineGenZ(p), paint));

                    //lakes
                    var lake    = Lakes.find(l => l.name == features[f].group);
                    paint.Style = SKPaintStyle.Fill;
                    paint.Color = lake.fill.ToColor().Opacity(lake.opacity).SK();
                    paths.ForEach(p => canvas.DrawPath(lineGenZ(p), paint));

                    paint.Style       = SKPaintStyle.Stroke;
                    paint.Color       = lake.stroke.ToColor().Opacity(lake.opacity).SK();
                    paint.StrokeWidth = lake.strokeWidth;
                    paths.ForEach(p => canvas.DrawPath(lineGenZ(p), paint));
                }
                else
                {
                    //landmask
                    paint.Style      = SKPaintStyle.Fill;
                    paint.Color      = Color.White.SK();
                    paint.MaskFilter = null;
                    paths.ForEach(p => canvas.DrawPath(lineGenZ(p), paint));

                    //coastline
                    var g             = features[f].group == "lake_island" ? "lake_island" : "sea_island";
                    var island        = Islands.find(l => l.name == g);
                    paint.Style       = SKPaintStyle.Stroke;
                    paint.Color       = island.stroke.ToColor().Opacity(island.opacity).SK();
                    paint.StrokeWidth = island.strokeWidth;
                    //! TODO 滤镜怎么实现
                    paint.MaskFilter = SKMaskFilter.CreateBlur(SKBlurStyle.Normal, 0.2f);
                    paths.ForEach(p => canvas.DrawPath(lineGenZ(p), paint));
                }
            });
        }
示例#18
0
        public void Moving_with_multiple_islands_added_moves_the_islands()
        {
            // Given
            var unused             = 0.0;
            var width              = 100;
            var height             = 200;
            var viewControlData    = new ViewControlData(unused, unused, unused, width, height);
            var releaseBranchName  = "ReleaseBranch";
            var unusedColour       = Color.FromRgb(255, 255, 255);
            var releaseArchipelago = new Branch(releaseBranchName, unusedColour);

            Islands islands = new Islands(viewControlData, releaseArchipelago);

            var newBranchNameOne = "bob";
            var newBranchOne     = new Branch(newBranchNameOne, unusedColour);

            islands.Add(newBranchOne);
            var newBranchNameTwo = "ben";
            var newBranchTwo     = new Branch(newBranchNameTwo, unusedColour);

            islands.Add(newBranchTwo);
            var newBranchNameThree = "bill";
            var newBranchThree     = new Branch(newBranchNameThree, unusedColour);

            islands.Add(newBranchThree);

            Assert.AreEqual(0.0, newBranchOne.Shape.CentrePoint.X);
            Assert.AreEqual(0.0, newBranchOne.Shape.CentrePoint.Y);

            Assert.AreEqual(0.0, newBranchTwo.Shape.CentrePoint.X);
            Assert.AreEqual(0.0, newBranchTwo.Shape.CentrePoint.Y);

            Assert.AreEqual(0.0, newBranchThree.Shape.CentrePoint.X);
            Assert.AreEqual(0.0, newBranchThree.Shape.CentrePoint.Y);

            // When
            islands.MoveAll();

            // Then
            Assert.AreNotEqual(0.0, newBranchOne.Shape.CentrePoint.X);
            Assert.AreNotEqual(0.0, newBranchOne.Shape.CentrePoint.Y);

            Assert.AreNotEqual(0.0, newBranchTwo.Shape.CentrePoint.X);
            Assert.AreNotEqual(0.0, newBranchTwo.Shape.CentrePoint.Y);

            Assert.AreNotEqual(0.0, newBranchThree.Shape.CentrePoint.X);
            Assert.AreNotEqual(0.0, newBranchThree.Shape.CentrePoint.Y);
        }
示例#19
0
        public void Moving_multiple_islands_with_distances_set_does_not_set_their_positions_to_be_the_same()
        {
            // Given
            var unused             = 0.0;
            var width              = 1000;
            var height             = 2000;
            var viewControlData    = new ViewControlData(unused, unused, unused, width, height);
            var releaseBranchName  = "ReleaseBranch";
            var unusedColour       = Color.FromRgb(255, 255, 255);
            var releaseArchipelago = new Branch(releaseBranchName, unusedColour);

            Islands islands = new Islands(viewControlData, releaseArchipelago);

            var newBranchOne   = new Branch("bob", unusedColour);
            var newBranchTwo   = new Branch("ben", unusedColour);
            var newBranchThree = new Branch("bill", unusedColour);

            newBranchOne.Distance   = 10;
            newBranchTwo.Distance   = 20;
            newBranchThree.Distance = 30;

            islands.Add(newBranchOne);
            islands.Add(newBranchTwo);
            islands.Add(newBranchThree);

            // When
            islands.MoveAll();

            // Then
            List <Branch> islandArray = new List <Branch>(new Branch[]
            {
                newBranchOne,
                newBranchTwo,
                newBranchThree
            }
                                                          );

            foreach (var island in islandArray)
            {
                var otherIslands = islandArray.Where(b => b != island);

                foreach (var comparingIsland in otherIslands)
                {
                    Assert.AreNotEqual(comparingIsland.Shape.CentrePoint.X, island.Shape.CentrePoint.X);
                    Assert.AreNotEqual(comparingIsland.Shape.CentrePoint.Y, island.Shape.CentrePoint.Y);
                }
            }
        }
示例#20
0
    public void ShowMap() {
        for (int i = 0; i < map.y; i++) {
            for(int j = 0; j < map.x; j++) {
                GameObject newTile = Instantiate(tile, new Vector2(j, i), Quaternion.identity, transform);
                newTile.name = newTile.name + "(" + j + "," + i + ")";
                if (spriteMap.Length > 0) {
                    float noise = 1f / spriteMap.Length;
                    float perlin = Mathf.Clamp01(Mathf.PerlinNoise((j/perlinFloat + seededRand) * perlinFreq, (i/perlinFloat + seededRand) * perlinFreq));
                    int noiseValue = (int)(perlin / noise);

                    Sprite temp = newTile.GetComponent<SpriteRenderer>().sprite = spriteMap[noiseValue];

                    tileMap[(int)(map.x * i + j)] = noiseValue;



                    float deltaX = temp.bounds.size.x * j + (temp.bounds.size.x / 2);
                    float deltaY = temp.bounds.size.y * i + (temp.bounds.size.y / 2);
                    newTile.transform.position = new Vector2(deltaX - (temp.bounds.size.x * map.x/2), deltaY - (temp.bounds.size.y * map.y/2));
                    tiles[(int)(map.x * i + j)] = newTile;
                }
            }
        }
        // Test:
        if (checkForLand) {
            isleList = Islands.FindIslands();
            for (int b = 0; b < isleList.Count; b++) {
                GameObject go = Instantiate(new GameObject(), transform);
                go.name = "Island " + b;
                go.AddComponent<BoxCollider2D>();
                for (int a = 0; a < isleList[b].islandPos.Length; a++) {
                    Vector2 temp = isleList[b].islandPos[a];
                    int index = (int)(map.x * temp.y + temp.x);
                    Color c = new Color(1, 1 - ((float)(b + 1f) / (float)(isleList.Count + 1f)), 1-((float)(b + 1f)/(float)(isleList.Count + 1f)));
                        tiles[index].GetComponent<SpriteRenderer>().color = c;
                    tiles[index].transform.parent = go.transform;
                }
            }
            //if (noiseValue > 2) {
            //    newTile.GetComponent<SpriteRenderer>().color = Color.red;
            //}
            //else {
            //    newTile.GetComponent<SpriteRenderer>().color = Color.green;
            //}
        }
    }
示例#21
0
        public void Highlighting_a_branch_that_does_not_exist_does_not_highlight_any_branches()
        {
            // Given
            var unused             = 0.0;
            var width              = 1000;
            var height             = 2000;
            var viewControlData    = new ViewControlData(unused, unused, unused, width, height);
            var releaseBranchName  = "ReleaseBranch";
            var unusedColour       = Color.FromRgb(255, 255, 255);
            var releaseArchipelago = new Branch(releaseBranchName, unusedColour);

            Islands islands = new Islands(viewControlData, releaseArchipelago);

            var branch = new Branch("existingBranch", unusedColour);

            // this is a bit of a kludge, really, we should be mocking
            double[] islandStrokeThicknessesBeforeHighlighting =
            {
                branch.Shape.MainIslandShape.Shape.StrokeThickness,
                releaseArchipelago.Shape.MainIslandShape.Shape.StrokeThickness
            };

            islands.Add(branch);

            // When
            bool exceptionRaised = false;

            try
            {
                islands.Highlight("name of a branch that does not exist");
            }
            catch (IndexOutOfRangeException)
            {
                exceptionRaised = true;
            }

            // Then
            Assert.IsTrue(exceptionRaised);

            Assert.AreEqual(islandStrokeThicknessesBeforeHighlighting[0], branch.Shape.MainIslandShape.Shape.StrokeThickness);
            Assert.AreEqual(islandStrokeThicknessesBeforeHighlighting[1], releaseArchipelago.Shape.MainIslandShape.Shape.StrokeThickness);
        }
示例#22
0
        public void On_creation_adds_and_moves_release_archipelago_to_the_centre_and_takes_into_account_the_padding_pixels()
        {
            // Given
            var unused             = 0.0;
            var width              = 100;
            var height             = 200;
            var viewControlData    = new ViewControlData(unused, unused, unused, width, height);
            var releaseBranchName  = "ReleaseBranch";
            var releaseArchipelago = new Branch(releaseBranchName, Color.FromRgb(255, 255, 255));

            // When
            Islands islands = new Islands(viewControlData, releaseArchipelago);

            // Then
            var actualLocation   = releaseArchipelago.Shape.CentrePoint;
            var expectedLocation = viewControlData.CentrePoint;

            Assert.AreEqual(expectedLocation.X, actualLocation.X);
            Assert.AreEqual(expectedLocation.Y, actualLocation.Y);
        }
示例#23
0
        public void Getting_all_island_names()
        {
            // Given
            var unused             = 0.0;
            var width              = 1000;
            var height             = 2000;
            var viewControlData    = new ViewControlData(unused, unused, unused, width, height);
            var releaseBranchName  = "ReleaseBranch";
            var unusedColour       = Color.FromRgb(255, 255, 255);
            var releaseArchipelago = new Branch(releaseBranchName, unusedColour);

            Islands islands = new Islands(viewControlData, releaseArchipelago);
            var     branch1 = new Branch("one", unusedColour);
            var     branch2 = new Branch("two", unusedColour);
            var     branch3 = new Branch("three", unusedColour);

            islands.Add(branch1);
            islands.Add(branch2);
            islands.Add(branch3);

            // When
            var nameList = islands.GetAllNames();

            // Then
            var expectedCount = 3;
            var actualCount   = nameList.Count;

            Assert.AreEqual(expectedCount, actualCount);

            var branchOneIsInTheList = nameList.Contains("one");

            Assert.IsTrue(branchOneIsInTheList);

            var branchTwoIsInTheList = nameList.Contains("two");

            Assert.IsTrue(branchTwoIsInTheList);

            var branchThreeIsInTheList = nameList.Contains("three");

            Assert.IsTrue(branchThreeIsInTheList);
        }
示例#24
0
 public IEnumerable <T> FindInRange <T>(SceneGraphNode node, int range, Func <T, bool> wherePredicate)
     where T : class, IHasNode
 {
     if (typeof(IIslandAddon).IsAssignableFrom(typeof(T)))
     {
         // Search the addons
         return(Islands.SelectMany(i => i.Addons).OfType <T>()
                .Where(r => Vector3.Distance(node.Position, r.Node.Position) < range));
     }
     if (typeof(ScatteredPlayer).IsAssignableFrom(typeof(T)))
     {
         // Search players (eg player)
         if (Vector3.Distance(node.Position, LocalPlayer.Position) < range)
         {
             return new[] { LocalPlayer as T }
         }
         ;
         return(new T[0]);
     }
     throw new NotImplementedException();
 }
示例#25
0
        public void Adding_multiple_islands_make_them_exist_in_the_collection()
        {
            // Given
            var unused             = 0.0;
            var width              = 100;
            var height             = 200;
            var viewControlData    = new ViewControlData(unused, unused, unused, width, height);
            var releaseBranchName  = "ReleaseBranch";
            var unusedColour       = Color.FromRgb(255, 255, 255);
            var releaseArchipelago = new Branch(releaseBranchName, unusedColour);

            Islands islands = new Islands(viewControlData, releaseArchipelago);

            // When
            var newBranchNameOne = "bob";
            var newBranch        = new Branch(newBranchNameOne, unusedColour);

            islands.Add(newBranch);

            var newBranchNameTwo = "ben";

            newBranch = new Branch(newBranchNameTwo, unusedColour);
            islands.Add(newBranch);

            var newBranchNameThree = "bill";

            newBranch = new Branch(newBranchNameThree, unusedColour);
            islands.Add(newBranch);

            // Then
            var exists = islands.Contains(newBranchNameOne);

            Assert.IsTrue(exists);

            exists = islands.Contains(newBranchNameTwo);
            Assert.IsTrue(exists);

            exists = islands.Contains(newBranchNameThree);
            Assert.IsTrue(exists);
        }
示例#26
0
        public void Getting_all_island_names_when_there_are_no_islands()
        {
            // Given
            var unused             = 0.0;
            var width              = 1000;
            var height             = 2000;
            var viewControlData    = new ViewControlData(unused, unused, unused, width, height);
            var releaseBranchName  = "ReleaseBranch";
            var unusedColour       = Color.FromRgb(255, 255, 255);
            var releaseArchipelago = new Branch(releaseBranchName, unusedColour);

            Islands islands = new Islands(viewControlData, releaseArchipelago);

            // When
            var nameList = islands.GetAllNames();

            // Then
            var expectedCount = 0;
            var actualCount   = nameList.Count;

            Assert.AreEqual(expectedCount, actualCount);
        }
示例#27
0
        public void Branch_moves_to_rotated_location_when_there_is_no_collision()
        {
            // Given
            CreateMockFactory();

            var unused             = 0.0;
            var width              = 1000;
            var height             = 2000;
            var viewControlData    = new ViewControlData(unused, unused, unused, width, height);
            var releaseBranchName  = "ReleaseBranch";
            var unusedColour       = Color.FromRgb(255, 255, 255);
            var releaseArchipelago = new Branch(releaseBranchName, unusedColour);

            Islands islands = new Islands(viewControlData, releaseArchipelago);

            var branch = new Branch("mr branch", unusedColour);

            branch.Distance = 50;
            islands.Add(branch);

            _mockCollisionDetector.Setup(m => m.GetNearestFreeLocation(It.IsAny <IslandShape>(),
                                                                       It.IsAny <IslandShape>())).Returns(
                (IslandShape possibleCollidingIslandShapeParameterPassedIn,
                 IslandShape releaseArchipelagoIslandShapeParameterPassedIn) =>
                possibleCollidingIslandShapeParameterPassedIn.CentrePoint);           // there is no collision, always returns given location

            // When
            islands.MoveAll();

            // Then
            var expectedRotatedLocation = new System.Windows.Point(
                (branch.Distance * viewControlData.PixelsPerArchipelagoUnitDistance) + viewControlData.CentrePoint.X,
                viewControlData.CentrePoint.Y);
            var branchCentre = branch.Shape.CentrePoint;

            Assert.AreEqual(expectedRotatedLocation.X, branchCentre.X);
            Assert.AreEqual(expectedRotatedLocation.Y, branchCentre.Y);
        }
示例#28
0
        public void Getting_an_islands_location()
        {
            // Given
            var unused             = 0.0;
            var width              = 1000;
            var height             = 2000;
            var viewControlData    = new ViewControlData(unused, unused, unused, width, height);
            var releaseBranchName  = "ReleaseBranch";
            var unusedColour       = Color.FromRgb(255, 255, 255);
            var releaseArchipelago = new Branch(releaseBranchName, unusedColour);

            Islands islands = new Islands(viewControlData, releaseArchipelago);
            var     branch  = new Branch("existingBranch", unusedColour);

            islands.Add(branch);

            // When
            var actualLocation = islands.GetLocation("existingBranch");

            // Then
            var expectedLocation = branch.Shape.CentrePoint;

            Assert.AreEqual(expectedLocation, actualLocation);
        }
示例#29
0
        public void Deleting_an_island_that_does_not_exist()
        {
            // Given
            var unused             = 0.0;
            var width              = 1000;
            var height             = 2000;
            var viewControlData    = new ViewControlData(unused, unused, unused, width, height);
            var releaseBranchName  = "ReleaseBranch";
            var unusedColour       = Color.FromRgb(255, 255, 255);
            var releaseArchipelago = new Branch(releaseBranchName, unusedColour);

            Islands islands = new Islands(viewControlData, releaseArchipelago);

            var branch = new Branch("existingBranch", unusedColour);

            islands.Add(branch);

            // When
            bool exceptionRaised = false;

            try
            {
                islands.Delete("branch-that-does-not-exist");
            }
            catch (IndexOutOfRangeException)
            {
                exceptionRaised = true;
            }

            // Then
            Assert.IsTrue(exceptionRaised);

            var islandExists = islands.Contains("branch-that-does-not-exist");

            Assert.IsFalse(islandExists);
        }
示例#30
0
        public void FillTo(Generation.World.TimelineLayer component)
        {
            component.Age = Age;

            component.WorldTiles = new Generation.World.WorldTile[WorldMapResolution, WorldMapResolution];

            for (int i = 0; i < WorldMapResolution; i++)
            {
                for (int j = 0; j < WorldMapResolution; j++)
                {
                    component.WorldTiles[i, j] = WorldTiles[i * WorldMapResolution + j];
                }
            }

            component.Civilizations = new List <Generation.World.Civilization>(Civilizations.Select(x => (Generation.World.Civilization)x));

            component.Continents = new List <Generation.World.Region>(Continents.Select(x => (Generation.World.Region)x));

            component.Islands = new List <Generation.World.Region>(Islands.Select(x => (Generation.World.Region)x));

            component.Mountains = new List <Generation.World.Region>(Mountains.Select(x => (Generation.World.Region)x));

            component.Forests = new List <Generation.World.Region>(Forests.Select(x => (Generation.World.Region)x));

            component.Deserts = new List <Generation.World.Region>(Deserts.Select(x => (Generation.World.Region)x));

            component.Swamps = new List <Generation.World.Region>(Swamps.Select(x => (Generation.World.Region)x));

            component.Chunks = Chunks;

            component.ElevationMap = new float[WorldMapResolution][];
            for (int i = 0; i < WorldMapResolution; i++)
            {
                component.ElevationMap[i] = new float[WorldMapResolution];
                for (int j = 0; j < WorldMapResolution; j++)
                {
                    component.ElevationMap[i][j] = ElevationMap[i * WorldMapResolution + j] / 255f;
                }
            }

            component.RiverMap = new bool[WorldMapResolution][];
            for (int i = 0; i < WorldMapResolution; i++)
            {
                component.RiverMap[i] = new bool[WorldMapResolution];
                for (int j = 0; j < WorldMapResolution; j++)
                {
                    component.RiverMap[i][j] = RiverMap[i * WorldMapResolution + j];
                }
            }


            component.RiverBorderMap = new bool[WorldMapResolution][];
            for (int i = 0; i < WorldMapResolution; i++)
            {
                component.RiverBorderMap[i] = new bool[WorldMapResolution];
                for (int j = 0; j < WorldMapResolution; j++)
                {
                    component.RiverBorderMap[i][j] = RiverBorderMap[i * WorldMapResolution + j];
                }
            }

            component.InlandWaterConnectivity = new TileForInlandWaterConnectivity[WorldMapResolution][];
            for (int i = 0; i < WorldMapResolution; i++)
            {
                component.InlandWaterConnectivity[i] = new TileForInlandWaterConnectivity[WorldMapResolution];
                for (int j = 0; j < WorldMapResolution; j++)
                {
                    component.InlandWaterConnectivity[i][j] = InlandWaterConnectivity[i * WorldMapResolution + j];
                }
            }



            component.BorderLines = new List <Generation.World.WaterBorderLine>();
            foreach (var borderLineStorage in BorderLines)
            {
                component.BorderLines.Add(borderLineStorage);
            }
        }
示例#31
0
        public void Moving_four_islands_with_distances_set_moves_each_island_to_a_corner()
        {
            // Given
            var unused             = 0.0;
            var width              = 1000;
            var height             = 2000;
            var viewControlData    = new ViewControlData(unused, unused, unused, width, height);
            var releaseBranchName  = "ReleaseBranch";
            var unusedColour       = Color.FromRgb(255, 255, 255);
            var releaseArchipelago = new Branch(releaseBranchName, unusedColour);

            Islands islands = new Islands(viewControlData, releaseArchipelago);

            var rightBranch  = new Branch("right", unusedColour);
            var bottomBranch = new Branch("bottom", unusedColour);
            var leftBranch   = new Branch("left", unusedColour);
            var topBranch    = new Branch("top", unusedColour);

            rightBranch.Distance  = 50;
            bottomBranch.Distance = 50;
            leftBranch.Distance   = 50;
            topBranch.Distance    = 50;

            // Locations are determinted by the order in which they're added, as we use the index of the
            //      underlying list.

            /*
             *  -------------------
             |        4        |
             |                 |
             |                 |
             | 3      C      1 |
             |                 |
             |                 |
             |        2        |
             |  -------------------
             */
            islands.Add(rightBranch);   // 1
            islands.Add(bottomBranch);  // 2
            islands.Add(leftBranch);    // 3
            islands.Add(topBranch);     // 4

            // When
            islands.MoveAll();

            // Then
            var centre            = viewControlData.CentrePoint;
            var rightBranchCentre = rightBranch.Shape.CentrePoint;

            rightBranchCentre.X = Math.Round(rightBranchCentre.X, 0, MidpointRounding.AwayFromZero);   // There may be some very small inaccuracy
            rightBranchCentre.Y = Math.Round(rightBranchCentre.Y, 0, MidpointRounding.AwayFromZero);   //   when we do the rotation.
            var isOnPositiveXRelativeToCentre = (rightBranchCentre.X > centre.X);
            var isOnEqualYToCentre            = (rightBranchCentre.Y == centre.Y);
            var rightBranchIsOnTheRight       = (isOnPositiveXRelativeToCentre && isOnEqualYToCentre);

            Assert.IsTrue(rightBranchIsOnTheRight, "rightBranchIsOnTheRight");

            var bottomBranchCentre = bottomBranch.Shape.CentrePoint;

            bottomBranchCentre.X = Math.Round(bottomBranchCentre.X, 0, MidpointRounding.AwayFromZero);
            bottomBranchCentre.Y = Math.Round(bottomBranchCentre.Y, 0, MidpointRounding.AwayFromZero);
            var isOnEqualXToCentre            = (bottomBranchCentre.X == centre.X);
            var isOnPositiveYRelativeToCentre = (bottomBranchCentre.Y > centre.Y);
            var bottomBranchIsOnTheBottom     = (isOnEqualXToCentre && isOnPositiveYRelativeToCentre);

            Assert.IsTrue(bottomBranchIsOnTheBottom, "bottomBranchIsOnTheBottom");

            var leftBranchCentre = leftBranch.Shape.CentrePoint;

            leftBranchCentre.X            = Math.Round(leftBranchCentre.X, 0, MidpointRounding.AwayFromZero);
            leftBranchCentre.Y            = Math.Round(leftBranchCentre.Y, 0, MidpointRounding.AwayFromZero);
            isOnPositiveXRelativeToCentre = (leftBranchCentre.X > centre.X);
            isOnEqualYToCentre            = (leftBranchCentre.Y == centre.Y);
            var leftBranchIsOnTheLeft = (!isOnPositiveXRelativeToCentre && isOnEqualYToCentre);

            Assert.IsTrue(leftBranchIsOnTheLeft, "leftBranchIsOnTheLeft");

            var topBranchCentre = topBranch.Shape.CentrePoint;

            topBranchCentre.X  = Math.Round(topBranchCentre.X, 0, MidpointRounding.AwayFromZero);
            topBranchCentre.Y  = Math.Round(topBranchCentre.Y, 0, MidpointRounding.AwayFromZero);
            isOnEqualXToCentre = (topBranchCentre.X == centre.X);
            var isOnNegativeYRelativeToCentre = (topBranchCentre.Y < centre.Y);
            var topBranchIsOnTheTop           = (isOnNegativeYRelativeToCentre && isOnEqualXToCentre);

            Assert.IsTrue(topBranchIsOnTheTop, "topBranchIsOnTheTop");
        }