예제 #1
0
파일: Road.cs 프로젝트: simhawk/Aurora
    public void placeRoadWithActiveCiv()
    {
        puff.Play();

        this.isPlaced = true;
        civType       = GameManager.Instance.activePlayer.civType;
        MeshRenderer mesh = gameObject.GetComponentInChildren <MeshRenderer>();

        mesh.enabled = true;

        switch (this.civType)
        {
        case CivType.Fisherman: mesh.material = Resources.Load("Materials/Road_Fisherman") as Material; break;

        case CivType.Knight: mesh.material = Resources.Load("Materials/Road_Knight") as Material; break;

        case CivType.Noble: mesh.material = Resources.Load("Materials/Road_Noble") as Material; break;

        case CivType.Samurai: mesh.material = Resources.Load("Materials/Road_Samurai") as Material; break;

        case CivType.Viking: mesh.material = Resources.Load("Materials/Road_Viking") as Material; break;

        default:  mesh.material = Resources.Load("Materials/Road_Viking") as Material; break;
        }
    }
예제 #2
0
 public void placeSettlementWithActiveCiv(bool isUpgraded)
 {
     puff.Play();
     this.isUpgraded = isUpgraded;
     civType         = GameManager.Instance.activePlayer.civType;
     ReplaceSettlement();
     MakeBaseVisible();
 }
예제 #3
0
    public void placeSettlementWithRandomCiv(bool isUpgraded)
    {
        puff.Play();
        this.isUpgraded = isUpgraded;
        System.Array civilizations = CivType.GetValues(typeof(CivType));
        CivType      randomCiv     = (CivType)civilizations.GetValue(random.Next(0, civilizations.Length));

        this.civType = randomCiv;
        ReplaceSettlement();
        MakeBaseVisible();
    }
예제 #4
0
 public Player getPlayerWithCiv(CivType civType)
 {
     foreach (Player p in players)
     {
         if (p.civType == civType)
         {
             return(p);
         }
     }
     Debug.Log("Error, could not find the player with civType:" + civType.ToString());
     return(players[0]);
 }
예제 #5
0
파일: Road.cs 프로젝트: simhawk/Aurora
 // Start is called before the first frame update
 void Start()
 {
     civType = CivType.Noble;
 }
예제 #6
0
    private void StateMachine()
    {
        if (Input.GetMouseButtonUp(0))
        {
            HideRollPanel();
        }
        Vector3 mousePoint = getMousePointOnPlane();

        Debug.Log(mousePoint.ToString());
        // StateMachine
        switch (gameState)
        {
        case GameState.InitialSettlementPlacement:
        {
            if (Input.GetMouseButtonUp(0))
            {
                Settlement closestSettlement = findClosestSettlementToAndDeselectAll(mousePoint, objectDistanceThreshold);
                if (closestSettlement != null && closestSettlement.isPlaceable())
                {
                    closestSettlement.placeSettlementWithActiveCiv(false);
                    this.gameState = GameState.InitialRoadPlacement;
                }
            }
            break;
        }

        case GameState.InitialRoadPlacement:
        {
            if (Input.GetMouseButtonUp(0))
            {
                Road closestRoad = findClosestRoadToAndDeselectAll(mousePoint, objectDistanceThreshold);
                if (closestRoad != null && closestRoad.isPlaceable())
                {
                    closestRoad.placeRoadWithActiveCiv();

                    bool endingPlayersTurn = getActivePlayerIndex() == players.Length - 1;
                    bool firstPlayersTurn  = getActivePlayerIndex() == 0;

                    if (selectingBackward)
                    {
                        if (!firstPlayersTurn)
                        {
                            SetPreviousActivePlayer();
                        }
                    }
                    else
                    {
                        if (endingPlayersTurn)
                        {
                            selectingBackward = true;
                        }
                        else
                        {
                            SetNextActivePlayer();
                        }
                    }

                    if (AllInitialRoadsAndSettlementsComplete())
                    {
                        this.gameState = GameState.ResourceRoll;
                    }
                    else
                    {
                        this.gameState = GameState.InitialSettlementPlacement;
                    }
                }
            }
            break;
        }

        case GameState.ResourceRoll:
        {
            // Wait for the player to click on the dice roll! don't really have to
            // do too much here unless you want cool animations as soon as they roll the dice
            break;
        }


        case GameState.ResourceRollDone:
        {
            // Show UI for rolling the number
            RollPanel.SetActive(true);
            TextMeshProUGUI number = rollPanelNumber.GetComponent <TextMeshProUGUI>();
            number.text = this.rollResults.Item1.ToString();
            TextMeshProUGUI subtext = rollpanelSubtext.GetComponent <TextMeshProUGUI>();
            subtext.text = this.rollResults.Item1 == 7 ? "Place the Thief or Terra" : "Collect your Resources!";



            if (this.rollResults.Item1 == 7)
            {
                Invoke("HideRollPanel", rollpanelDelay);
                gameState = GameState.PlaceThief;
                break;
            }

            Hex[] hexes = FindObjectsOfType(typeof(Hex)) as Hex[];
            foreach (Hex hex in hexes)
            {
                // skip if the roll number doesn't match up or if the thief is on the hex
                if (hex.getNumber() != rollResults.Item1 || hex.isThiefOnHex)
                {
                    continue;
                }

                Resource hexResource = hex.resource;

                List <Settlement> settlements = hex.GetAdjacentSettlements();
                foreach (Settlement settlement in settlements)
                {
                    if (!settlement.IsPlaced())
                    {
                        continue;
                    }
                    CivType civType     = settlement.GetCivType();
                    int     numberToAdd = settlement.IsUpgraded() ? 2 : 1;
                    getPlayerWithCiv(civType).addToResourceBank(hexResource, numberToAdd);
                }
            }

            printResourcesForPlayer(0);
            printResourcesForPlayer(1);
            printResourcesForPlayer(2);
            printResourcesForPlayer(3);

            //TODO: change this to the correct state(trading)
            gameState = GameState.Trading;
            break;
        }

        case GameState.Trading:
        {
            // TODO: do stuff for trading
            gameState = GameState.BuildOrDevelopmentCard;
            break;
        }

        case GameState.BuildOrDevelopmentCard:
        {
            if (Input.GetMouseButtonUp(0) && buildType != BuildType.NotSelected)
            {
                if (buildType == BuildType.Road)
                {
                    Road closestRoad = findClosestRoadToAndDeselectAll(mousePoint, objectDistanceThreshold);
                    if (closestRoad != null && closestRoad.isPlaceable())
                    {
                        closestRoad.isSelected = true;
                    }
                }
                else if (buildType == BuildType.City)
                {
                    Settlement closestSettlement = findClosestSettlementToAndDeselectAll(mousePoint, objectDistanceThreshold);
                    if (closestSettlement != null && !closestSettlement.IsUpgraded() && closestSettlement.IsPlaced())
                    {
                        closestSettlement.isSelected = true;
                    }
                }
                else if (buildType == BuildType.Settlement)
                {
                    Settlement closestSettlement = findClosestSettlementToAndDeselectAll(mousePoint, objectDistanceThreshold);
                    if (closestSettlement != null && closestSettlement.isPlaceable())
                    {
                        closestSettlement.isSelected = true;
                    }
                }
            }
            break;
        }

        case GameState.BuildingSelected:
        {
            // TODO: do stuff for Build or Development
            break;
        }



        case GameState.PlaceThief:
        {
            if (InputController.DetectedThief())
            {
                Vector3 thiefPoint = getThiefPointOnPlane();
                Hex     closestHex = findClosestHexToAndDeselectAll(thiefPoint, 4.0f);

                if (closestHex != null && !closestHex.isThiefOnHex)
                {
                    selectedHex = closestHex;
                    closestHex.isSelectedThief = true;
                    HelpingText.AdditionalText = HelpingText.AdditionalText + "Detected Thief";
                    placingThief = true;
                }
                else
                {
                    placingThief = false;
                }
                placingRobin = false;
            }
            else if (InputController.DetectedRobinHood())
            {
                Vector3 robinLocation = getRobinHoodPointOnPlane();
                Hex     closestHex    = findClosestHexToAndDeselectAll(robinLocation, 4.0f);

                if (closestHex != null && !closestHex.isRobinOnHex)
                {
                    selectedHex = closestHex;
                    closestHex.isSelectedRobin = true;
                    HelpingText.AdditionalText = HelpingText.AdditionalText + "Detected Robin";
                    placingRobin = true;
                }
                else
                {
                    placingRobin = false;
                }
                placingThief = false;
            }
            else
            {
                HelpingText.AdditionalText = HelpingText.AdditionalText + "not detected";
                placingThief = false;
                placingRobin = false;
            }
            break;
        }

        case GameState.PlaceThiefDone:
        {
            Hex[] hexes = FindObjectsOfType(typeof(Hex)) as Hex[];

            // reset thief
            if (placingThief)
            {
                foreach (Hex hex in hexes)
                {
                    hex.isSelectedThief = false;
                    hex.isThiefOnHex    = false;
                }
                if (selectedHex != null)
                {
                    selectedHex.isThiefOnHex = true;
                }
            }
            else if (placingRobin)
            {
                foreach (Hex hex in hexes)
                {
                    hex.isSelectedRobin = false;
                    hex.isRobinOnHex    = false;
                }
                if (selectedHex != null)
                {
                    selectedHex.isRobinOnHex = true;
                    //reset old robin if there
                    List <Hex> adj = selectedHex.GetAdjacentHexes();
                    foreach (Hex hex in hexes)
                    {
                        //put all non adjacent hexes back to normal
                        if (!adj.Contains(hex))
                        {
                            hex.resource          = hex.originalResource;
                            hex.displayedResource = hex.originalResource;
                        }
                    }

                    // update adjacent hexes with their displayed value
                    foreach (Hex hex in adj)
                    {
                        hex.resource = hex.displayedResource;
                        hex.InstantiateHexWith(hex.resource);
                    }
                }
            }

            gameState = GameState.Trading;
            break;
        }
        }
    }