コード例 #1
0
    // Start is called before the first frame update
    void Awake()
    {
        controller = GameObject.FindGameObjectWithTag("GameController").GetComponent <GameController>();

        populatedPiece   = null;
        populatedTrap    = null;
        populatorFaction = TerritoryHolder.Neutral;
        sprite           = GetComponent <SpriteRenderer>();
        particle         = GetComponent <ParticleSystem>();
        particle.Stop();
        sprite.color = startColor;
    }
コード例 #2
0
    //HELPER FUNCTIONS

    private void createPiecePrefab()
    {
        if (populatedPiece == null)
        {
            populatedPiece = Instantiate(piecePrefab, new Vector3(this.transform.position.x, this.transform.position.y, -3), Quaternion.identity);
        }

        if (controller.playerTurn == PlayerTurn.Attack)
        {
            print("111");
            populatorFaction = TerritoryHolder.Attack;
            GamePieceController pieceControl = populatedPiece.GetComponent <GamePieceController>();
            pieceControl.populateSlot(controller.getUpNext());
        }
        else
        {
            populatorFaction = TerritoryHolder.Defense;
            GamePieceController pieceControl = populatedPiece.GetComponent <GamePieceController>();
            pieceControl.populateSlot(controller.getUpNext());
        }
    }
コード例 #3
0
    public void destroyPiece(bool isNeutral)
    {
        print("destroy");
        Destroy(populatedPiece);

        populatedPiece = null;

        if (isNeutral)
        {
            populatorFaction = TerritoryHolder.Neutral;
        }
        else
        {
            if (populatorFaction == TerritoryHolder.Defense)
            {
                populatorFaction = TerritoryHolder.Attack;
            }
            else
            {
                populatorFaction = TerritoryHolder.Defense;
            }
        }
    }
コード例 #4
0
    private void OnMouseDown()
    {
        //print("click");


        //print(controller.gameMode);

        switch (controller.gameMode)
        {
        case GameMode.SelectTerritory:

            //controller.switchPlayer(); //temp for testing
            //print(controller.action);
            if (controller.action == Action.SelectOwn)     //If supposed to select own territory
            {
                //print("assignSelected");
                controller.selectedSpace = this.gameObject;
                controller.gameMode      = GameMode.SelectAdjacent;
            }
            else       //If supposed to place new troop on territory
            {
                //if (populatedPiece == null)
                //{
                if (controller.playerTurn == PlayerTurn.Defense)         //Defense's turn
                {
                    if (this.name != "Blank Space Key" && this.populatorFaction != TerritoryHolder.Attack)
                    {
                        if (controller.defensePlacement == DefensePlacement.Troop)
                        {
                            createPiecePrefab();
                            controller.incrementDefenseTroopPlacementCount();
                        }
                        else
                        {
                            if (populatedTrap == null)
                            {
                                createTrapPrefab();
                                controller.incrementDefenseTrapPlacementCount();
                            }
                        }
                    }
                }
                else                                                                                                   //Attack's turn
                {
                    if (this.gameObject.name == "Blank Space Key" && this.populatorFaction != TerritoryHolder.Defense) //Can only spawn on bottom space
                    {
                        createPiecePrefab();
                        controller.setAttackPlacedTroop();
                    }
                }


                //}
            }

            //oldColor already set from hover
            sprite.color = hoverColor;
            break;

        case GameMode.SelectAdjacent:
            if (controller.selectedSpace == this.gameObject)    //if click again to deselect
            {
                controller.gameMode = GameMode.SelectTerritory;
                sprite.color        = oldColor;
                particle.Stop();
            }
            else
            {
                print("test");
                //print(populatorFaction);

                List <GameObject> list = new List <GameObject> {
                };
                list.AddRange(controller.selectedSpace.GetComponent <TerritoryHandler>().adjacentTerritories);
                if (list.Contains(this.gameObject))     //if clicked on currently adjacent spot
                {
                    print("pressed");
                    if (this.populatorFaction == TerritoryHolder.Neutral)     //if no one holds this spot.
                    {
                        print("should not go");
                        controller.movePiece(transform.position);

                        particle.Stop();
                        populatedPiece = controller.selectedSpace.GetComponent <TerritoryHandler>().populatedPiece;
                        print("faction " + controller.selectedSpace.GetComponent <TerritoryHandler>().populatorFaction);
                        populatorFaction = controller.selectedSpace.GetComponent <TerritoryHandler>().populatorFaction;
                        controller.selectedSpace.GetComponent <TerritoryHandler>().populatorFaction = TerritoryHolder.Neutral;

                        if (controller.playerTurn == PlayerTurn.Attack && populatedTrap != null)
                        {
                            print("Trap!");
                            Destroy(populatedTrap);
                            destroyPiece(true);
                            controller.hasMergedPieces(true);     //not actually merged but does what we want;
                        }

                        if (this.gameObject == GameObject.FindGameObjectWithTag("Finish"))
                        {
                            controller.presentWinner(PlayerTurn.Attack);
                        }
                    }
                    else
                    {
                        if (controller.playerTurn == PlayerTurn.Attack)
                        {
                            if (this.populatorFaction == TerritoryHolder.Defense)
                            {
                                print("defense inst");
                                controller.conductFight(controller.selectedSpace, this.gameObject);
                            }
                            else       //if their own spot
                            {
                                mergePieces();
                            }
                        }
                        else       //if playerTurn is Defense
                        {
                            if (this.populatorFaction == TerritoryHolder.Attack)
                            {
                                controller.conductFight(controller.selectedSpace, this.gameObject);
                            }
                            else     //if their own spot
                            {
                                mergePieces();
                            }
                        }
                    }
                }
            }
            break;
        }
    }