/* 작물 수확 */
    void FarmingProcess()
    {
        if (!m_BlockManager.IS_Focus)
        {
            return;
        }

        // 블록 포커스 상태에서 마우스 클릭
        else
        {
            if (Input.GetMouseButtonDown(0))
            {
                if (m_BlockManager.Hit_Info.transform.tag != "Crops")
                {
                    return;
                }

                // 작물의 부모오브젝트(FarmLand Pivot)에 접근해서 심겨져 있지 않은 상태(NONE)로 변경
                m_FarmLand          = m_BlockManager.Hit_Info.transform.GetComponentInParent <FarmLand>();
                m_FarmLand.IS_Plant = false;

                SetSlotInfomation(Inven.SlotList);

                GameObject.Destroy(m_BlockManager.Hit_Info.transform.parent.gameObject);
            }
        }
    }
    void ObjectManagement(GameObject p_obj)
    {
        // 선택한 블록 하위로 씨앗 오브젝트를 넣고 위치 설정 후 리턴
        if (p_obj == Seed)
        {
            m_FarmLand = m_BlockManager.Hit_Info.transform.GetComponent <FarmLand>();

            if (m_FarmLand.LandState == LANDSTATE.PLANTED)
            {
                return;
            }

            m_FarmLand.IS_Plant = true;

            GrowCrops seedinfo = p_obj.GetComponent <GrowCrops>();
            seedinfo.PlantState = E_PLANTSTATE.PLANT;

            Vector3    seedpos  = Vector3.up * SeedYpos;
            GameObject copyseed = GameObject.Instantiate(p_obj);
            copyseed.SetActive(true);
            copyseed.transform.SetParent(m_BlockManager.Hit_Info.transform);
            copyseed.transform.position = m_BlockManager.Hit_Info.transform.position + seedpos;

            return;
        }

        /* 선택한 위치에 블록 복사,생성 후 해당 위치에 있던 블록 삭제 */
        GameObject copyobj = GameObject.Instantiate(p_obj);

        copyobj.SetActive(true);
        copyobj.transform.SetParent(m_BlockManager.FarmField);
        copyobj.transform.position = m_BlockManager.Hit_Info.transform.position;

        GameObject.Destroy(m_BlockManager.Hit_Info.transform.gameObject);
    }
    void Start()
    {
        GameState = GAMESTATE.NONE;

        DirtBlock.SetActive(false);
        FarmLand.SetActive(false);
        Seed.SetActive(false);
    }
    void FocusUpdate()
    {
        if (GameManager.GameState == GAMESTATE.NONE || GameManager.GameState == GAMESTATE.STOP_WORK)
        {
            return;
        }

        // 메인카메라 에서 스크린 좌표의 마우스 위치로 레이 생성
        Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);

        // https://mentum.tistory.com/253 LayerMask
        int layermask = 1 << LayerMask.NameToLayer("Select");

        layermask = ~layermask; // "Select" 레이어만 제외

        float maxdistance = Mathf.Abs(FarmField.position.magnitude - Camera.main.transform.position.magnitude);

        if (Physics.Raycast(ray, out Hit_Info, maxdistance, layermask))
        {
            IS_Focus = true;

            FarmLand farmland = Hit_Info.transform.GetComponent <FarmLand>();

            if (GameManager.GameState == GAMESTATE.WEEDING && Hit_Info.transform.tag != "Grass" ||
                GameManager.GameState == GAMESTATE.PLOWING && Hit_Info.transform.tag != "Dirt" ||
                GameManager.GameState == GAMESTATE.PLANTING && Hit_Info.transform.tag != "FarmLand" ||
                GameManager.GameState == GAMESTATE.PLANTING && farmland.LandState == LANDSTATE.PLANTED ||
                GameManager.GameState == GAMESTATE.FARMING && Hit_Info.transform.tag != "Crops")
            {
                IS_Focus = false;
            }

            //Debug.Log(Hit_Info.transform);
            Debug.DrawRay(ray.origin, ray.direction * maxdistance, Color.red);

            /* 작물 오브젝트 */
            if (GameManager.GameState == GAMESTATE.FARMING && Hit_Info.transform.tag == "Crops")
            {
                Vector3 ypos = Vector3.up * 0.5f;
                CropsSelect.transform.position = Hit_Info.transform.position + ypos;

                Select.SetActive(false);
                SelectUnable.SetActive(false);
                CropsSelect.SetActive(true);
            }

            /* 선택 불가능한 오브젝트 */
            else if (!IS_Focus)
            {
                SelectUnable.transform.position = Hit_Info.transform.position;

                Select.SetActive(false);
                SelectUnable.SetActive(true);
                CropsSelect.SetActive(false);
            }

            /* 선택 가능한 오브젝트 */
            else
            {
                Select.transform.position = Hit_Info.transform.position;

                Select.SetActive(true);
                SelectUnable.SetActive(false);
                CropsSelect.SetActive(false);
            }
        }
        else
        {
            IS_Focus = false;
            Select.SetActive(false);
            SelectUnable.SetActive(false);
            CropsSelect.SetActive(false);
        }
    }
예제 #5
0
    static void Main()
    {
        //int n = int.Parse(Console.ReadLine());
        using (FileStream fs = new FileStream("Tests/HelptheFarmer.test",FileMode.Open,FileAccess.Read)) {
            StreamReader sr = new StreamReader (fs);
            int n = int.Parse (sr.ReadLine ());
            Cell[,] cells = new Cell[n, n];
            for (int i=0; i<n; i++) {
                //string[] row = Console.ReadLine().Split(' ');
                string[] row = sr.ReadLine ().Split (' ');
                for (int j=0; j<n; j++) {
                    string cell = row [j];
                    cells [i, j] = new Cell (int.Parse (cell), i, j);
                }
            }

            FarmLand land = new FarmLand (n, cells);
            land.NavigateAndAssignFlows ();
            Console.WriteLine (land.FindBasins ());
        }
    }