Esempio n. 1
0
    private static void CheckAroundGrids(FarmGrid farmGrid, List <FarmGrid.Grid> fieldGrids, int centerGridIndex, List <int> aroundGridIndexs, bool isIgnorePutedFlag)
    {
        FarmGrid.GridPosition gridPosition = farmGrid.IndexToPosition(centerGridIndex);
        int num = FarmDigimonUtility.CheckGrid(farmGrid, fieldGrids, gridPosition.x, gridPosition.y - 1, isIgnorePutedFlag);

        if (num != -1)
        {
            aroundGridIndexs.Add(num);
        }
        num = FarmDigimonUtility.CheckGrid(farmGrid, fieldGrids, gridPosition.x, gridPosition.y + 1, isIgnorePutedFlag);
        if (num != -1)
        {
            aroundGridIndexs.Add(num);
        }
        num = FarmDigimonUtility.CheckGrid(farmGrid, fieldGrids, gridPosition.x - 1, gridPosition.y, isIgnorePutedFlag);
        if (num != -1)
        {
            aroundGridIndexs.Add(num);
        }
        num = FarmDigimonUtility.CheckGrid(farmGrid, fieldGrids, gridPosition.x + 1, gridPosition.y, isIgnorePutedFlag);
        if (num != -1)
        {
            aroundGridIndexs.Add(num);
        }
    }
Esempio n. 2
0
        public Game(float startMoney, Vector2Int farmGridSize, ListNaturalResourceValue startResources)
        {
            ChangeMoney(startMoney);
            _farmGrid = new FarmGrid(farmGridSize);

            _resources = startResources;
        }
Esempio n. 3
0
    private static int CheckGrid(FarmGrid farmGrid, List <FarmGrid.Grid> fieldGrids, int checkGridX, int checkGridY, bool isIgnorePutedFlag)
    {
        int gridIndex = farmGrid.GetGridIndex(checkGridX, checkGridY);

        if (gridIndex != -1 && FarmUtility.IsPassableGrid(fieldGrids, gridIndex, isIgnorePutedFlag))
        {
            return(gridIndex);
        }
        return(-1);
    }
        void LoadFarm(BinaryReader reader)
        {
            this.LoadedFarm = new FarmGrid();
            var chunk = reader.ReadBytes(Tile.ChunkSize);

            while (chunk.Length > 0)
            {
                this.LoadedFarm.AddTile(Tile.CreateTile(chunk, this.LoadedFarm));
                chunk = reader.ReadBytes(Tile.ChunkSize);
            }
        }
Esempio n. 5
0
 public static bool GetAroundGridIndexsForPath(FarmGrid farmGrid, int centerGridIndex, FarmDigimonUtility.PathInfo[] path, List <int> aroundGridIndexs)
 {
     FarmGrid.GridPosition gridPosition = farmGrid.IndexToPosition(centerGridIndex);
     for (int i = 0; i < path.Length; i++)
     {
         FarmGrid.GridPosition gridPosition2 = farmGrid.IndexToPosition(path[i].gridIndex);
         if ((gridPosition2.x == gridPosition.x - 1 && gridPosition2.y == gridPosition.y) || (gridPosition2.x == gridPosition.x + 1 && gridPosition2.y == gridPosition.y) || (gridPosition2.x == gridPosition.x && gridPosition2.y == gridPosition.y - 1) || (gridPosition2.x == gridPosition.x && gridPosition2.y == gridPosition.y + 1))
         {
             aroundGridIndexs.Add(path[i].gridIndex);
         }
     }
     return(0 < aroundGridIndexs.Count);
 }
Esempio n. 6
0
 private bool ChoosePath(FarmGrid farmGrid, List <FarmDigimonUtility.PathInfo> path, int startGridIndex, int targetPathCount, List <int> choosePath)
 {
     FarmDigimonUtility.PathInfo[] array = path.Where((FarmDigimonUtility.PathInfo x) => x.checkPoint == targetPathCount).ToArray <FarmDigimonUtility.PathInfo>();
     if (array != null)
     {
         List <int> list = new List <int>();
         if (FarmDigimonUtility.GetAroundGridIndexsForPath(farmGrid, startGridIndex, array, list))
         {
             choosePath.Add(list[0]);
             return(true);
         }
     }
     return(false);
 }
Esempio n. 7
0
        public Game(float startMoney, Vector2Int farmGridSize, List <NaturalResourceValue> startResources = null)
        {
            ChangeMoney(startMoney);
            _farmGrid = new FarmGrid(farmGridSize);

            _resources           = new ListNaturalResourceValue();
            _resources.Resources = startResources;

            if (_resources.Resources == null)
            {
                _resources.Resources.Add(new NaturalResourceValue(NaturalResourcesType.Eggs, 0));
                _resources.Resources.Add(new NaturalResourceValue(NaturalResourcesType.Hay, 0));
                _resources.Resources.Add(new NaturalResourceValue(NaturalResourcesType.Milk, 0));
            }
        }
 public void Load(string filename)
 {
     if (File.Exists(filename))
     {
         using (BinaryReader reader = new BinaryReader(File.Open(filename, FileMode.Open)))
         {
             LoadPlayerState(reader);
             LoadFarm(reader);
         }
     }
     if (this.LoadedFarm == null)
     {
         this.LoadedFarm = new FarmGrid();
     }
 }
        public void SaveAndLoadTest1()
        {
            var farm1In = new FarmGrid();
            var tile1   = Tile.CreateTile(TileType.Dirt, 1, 2, farm1In, true, TileType.Blueberry1);

            farm1In.AddTile(tile1);
            SaveFileManager.Instance.Save("test1.dat", farm1In);

            SaveFileManager.Instance.Load("test1.dat");
            var farm1Out = SaveFileManager.Instance.LoadedFarm;

            Assert.IsTrue(farm1Out.AllTiles().Length == 1);
            Assert.IsTrue(farm1Out.GetTile(1, 2) != null);
            Assert.IsTrue(farm1Out.GetTile(1, 2).CompareTo(tile1) == 0);
            Assert.IsTrue(farm1Out.GetTile(0, 0) == null);
        }
 public void Save(string filename = "farm.dat", FarmGrid farm = null)
 {
     using (BinaryWriter writer = new BinaryWriter(File.Open(filename, FileMode.Create)))
     {
         writer.Write(PlayerState.Instance.ToBytes());
         // if not specified, get farm scene instance's farm
         if (farm == null)
         {
             farm = FarmScene.Instance.FindEntity("farm").GetComponent <FarmGrid>();
         }
         foreach (var tile in farm.AllTiles())
         {
             writer.Write(tile.ToBytes());
         }
     }
 }
Esempio n. 11
0
    private Vector3 GetExtendBuildPosition(FarmObjectSetting farmObjectSetting, FarmObject prevFarmObject)
    {
        FarmObjectSetting.ExtendBuildPositionSearchResult extendBuildPositionSearchResult = farmObjectSetting.SearchExtendBuildGrid(prevFarmObject);
        FarmGrid grid               = FarmRoot.Instance.Field.Grid;
        int      gridIndex          = grid.GetGridIndex(extendBuildPositionSearchResult.grid);
        Vector3  positionGridCenter = grid.GetPositionGridCenter(gridIndex, true);

        if (!extendBuildPositionSearchResult.isOutsideMap)
        {
            GUICameraControll component = FarmRoot.Instance.Camera.GetComponent <GUICameraControll>();
            if (null != component)
            {
                base.StartCoroutine(component.MoveCameraToLookAtPoint(positionGridCenter, 0f));
            }
        }
        return(positionGridCenter);
    }
        public void SaveAndLoadTest2()
        {
            var bytes = new byte[PlayerState.ChunkSize];

            BitConverter.GetBytes(9999).CopyTo(bytes, 0);
            BitConverter.GetBytes(98765.4321f).CopyTo(bytes, 4);
            bytes[8]  = 21;
            bytes[9]  = 2;
            bytes[10] = 202;
            PlayerState.Instance.LoadFromBytes(bytes);
            var farm2In = new FarmGrid();
            var tile1   = Tile.CreateTile(TileType.Dirt, 0, 0, farm2In);

            farm2In.AddTile(tile1);
            var tile2 = Tile.CreateTile(TileType.Grass, 0, 1, farm2In);

            farm2In.AddTile(tile2);
            var tile3 = Tile.CreateTile(TileType.Grass, 1, 0, farm2In);

            farm2In.AddTile(tile3);
            var tile4 = Tile.CreateTile(TileType.Dirt, 1, 1, farm2In);

            farm2In.AddTile(tile4);
            SaveFileManager.Instance.Save("test2.dat", farm2In);

            SaveFileManager.Instance.Load("test2.dat");
            Assert.IsTrue(PlayerState.Instance.Money == 9999);
            Assert.IsTrue(PlayerState.Instance.TimeOfDay == 98765.4321f);
            Assert.IsTrue(PlayerState.Instance.Day == 21);
            Assert.IsTrue((byte)PlayerState.Instance.Season == 2);
            Assert.IsTrue(PlayerState.Instance.Year == 202);
            var farm2Out = SaveFileManager.Instance.LoadedFarm;

            Assert.IsTrue(farm2Out.AllTiles().Length == 4);
            Assert.IsTrue(farm2Out.GetTile(0, 0).CompareTo(tile1) == 0);
            Assert.IsTrue(farm2Out.GetTile(0, 1).CompareTo(tile2) == 0);
            Assert.IsTrue(farm2Out.GetTile(1, 0).CompareTo(tile3) == 0);
            Assert.IsTrue(farm2Out.GetTile(1, 1).CompareTo(tile4) == 0);
        }
Esempio n. 13
0
 private void Awake()
 {
     base.gameObject.tag = "Farm.Field";
     this.farmGrid       = new FarmGrid(this);
 }
Esempio n. 14
0
 private bool CheckHitBuild(FarmGrid farmGrid, List <FarmGrid.Grid> grids)
 {
     return(false);
 }