int FindgTile(Tiles.Tiledir dir, int idx) { int result = idx; switch (dir) { case Tiles.Tiledir.left: if (idx % GameData.MaxTile[GameData.iNowMap, 0] != 0) { result -= 1; } else { result = -1; } break; case Tiles.Tiledir.up: if (idx >= GameData.MaxTile[GameData.iNowMap, 0]) { result -= GameData.MaxTile[GameData.iNowMap, 0]; } else { result = -1; } break; case Tiles.Tiledir.right: if (idx % GameData.MaxTile[GameData.iNowMap, 0] != GameData.MaxTile[GameData.iNowMap, 0] - 1) { result += 1; } else { result = -1; } break; case Tiles.Tiledir.down: if (idx < GameData.MaxTile[GameData.iNowMap, 0] * (GameData.MaxTile[GameData.iNowMap, 1] - 1)) { result += GameData.MaxTile[GameData.iNowMap, 0]; } else { result = -1; } break; } return(result); }
void Result() { if (!m_bIsGoal) { return; } int idx = Getidx(m_tFinal.X, m_tFinal.Y); m_pPlayerMove.bIsMove = true; while (true) { if (idx == Getidx(m_tStart.X, m_tStart.Y)) { m_pPlayerMove.iBestCount = BestList.Count; m_pPlayerMove.bIsInit = true; return; } Tiles.Tiledir dir = TileList[idx].GetComponent <Tiles>().dir; BestList.Add(dir); switch (dir) { case Tiles.Tiledir.left: idx += 1; break; case Tiles.Tiledir.right: idx -= 1; break; case Tiles.Tiledir.up: idx += GameData.MaxTile[GameData.iNowMap, 0]; break; case Tiles.Tiledir.down: idx -= GameData.MaxTile[GameData.iNowMap, 0]; break; } } }
void TileInit(int now, int move, Tiles.Tiledir dir) { if (move == -1) { return; } Tiles movegTile = TileList[move].GetComponent <Tiles>(); Tiles nowgTile = TileList[now].GetComponent <Tiles>(); if (movegTile.bIsClose == true) { return; } if (!m_bIsFindRange) { if (movegTile.Z != 0) { if (Mathf.Abs(nowgTile.Z - movegTile.Z) <= m_iPlayerJump) { if (movegTile.bIsOpen) { if (movegTile.g > nowgTile.g + 1) { movegTile.g = nowgTile.g + 1; movegTile.f = movegTile.g + movegTile.h; movegTile.dir = dir; } } else { movegTile.g = nowgTile.g + 1; movegTile.h = Mathf.Abs(m_tFinal.X - movegTile.X) + Mathf.Abs(m_tFinal.Y - movegTile.Y); movegTile.f = movegTile.g + movegTile.h; movegTile.dir = dir; AddOpenList(move); //Debug.Log("X " + move % 12 + '\t' + "Y " + (move / 12) + '\t' + "G" + movegTile.g); } } } } else { if (movegTile.Z != 0) { if (Mathf.Abs(nowgTile.Z - movegTile.Z) <= m_iPlayerJump) { if (nowgTile.g == GameData.gNowPlayer.GetComponent <Status>().iMovingRange) { return; } if (movegTile.bIsOpen) { if (movegTile.g > nowgTile.g + 1) { movegTile.g = nowgTile.g + 1; } } else { movegTile.g = nowgTile.g + 1; Addm_MoveOpen(move); TileList[move].GetComponent <Tiles>().SetMoveRange(true); // Debug.Log("X " + move % 12 + '\t' + "Y " + (move / 12) + '\t' + "G" + movegTile.g); } } } } }