コード例 #1
0
        public void Setup()
        {
            var world = new SimpleWorld();

            town1center         = world.GetVoxel(0, 0);
            borderVoxel         = world.GetVoxel(1, 0);
            borderToBorderVoxel = world.GetVoxel(2, 0);
            town2BorderToTown1  = world.GetVoxel(0, 1);
            town2center         = world.GetVoxel(0, 2);

            var service = new TownCenterService(null, new GenericDatastoreRecord(null, 1));

            town1 = service.CreateTown(town1center);
            town2 = service.CreateTown(town2center);

            town1.AddVoxel(town1center);
            town2.AddVoxel(town2center);
            town2.AddVoxel(town2BorderToTown1);

            tool = new TownBorderPlayerTool(service);
        }
コード例 #2
0
        /// <summary>
        /// Adds given voxel to the town border, and takes it from its current town if one exists
        /// Does nothing in case invalid border addition, and returns false
        /// </summary>
        public bool TryAddBorder(IVoxel voxel, Town town)
        {
            if (!town.IsAtBorder(voxel))
            {
                return(false);
            }

            var oldTown = townCenterService.GetTownForVoxel(voxel);

            if (oldTown != null)
            {
                if (!oldTown.CanRemove(voxel))
                {
                    return(false);                          //Do not remove last
                }
                oldTown.RemoveVoxel(voxel);
            }
            town.AddVoxel(voxel);

            return(true);
        }