Beispiel #1
0
    public IEnumerator CaptureLandmark_BothPlayersKnowledgeAmountCorrect()
    {
        Setup();

        // capturing landmark
        Sector landmarkedSector = map.sectors[1];

        landmarkedSector.Initialize();
        Landmark landmark = landmarkedSector.GetLandmark();
        Player   playerA  = game.players[0];
        Player   playerB  = game.players[1];

        playerB.Capture(landmarkedSector);

        // ensure 'landmarkedSector' is a landmark of type Knowledge
        Assert.IsNotNull(landmarkedSector.GetLandmark());
        landmark.SetResourceType(Landmark.ResourceType.Knowledge);

        // get knowledge amounts for each player before capture
        int    attackerKnowledgeBeforeCapture = playerA.GetKnowledge();
        int    defenderKnowledgeBeforeCapture = playerB.GetKnowledge();
        Player previousOwner = landmarkedSector.GetOwner();

        playerA.Capture(landmarkedSector);

        // ensure sector is captured correctly
        Assert.AreSame(landmarkedSector.GetOwner(), playerA);
        Assert.IsTrue(playerA.ownedSectors.Contains(landmarkedSector));

        // ensure resources are transferred correctly
        Assert.IsTrue(attackerKnowledgeBeforeCapture + landmark.GetAmount() == playerA.GetKnowledge());
        Assert.IsTrue(defenderKnowledgeBeforeCapture - landmark.GetAmount() == previousOwner.GetKnowledge());

        yield return(null);
    }
    /// <summary>
    ///
    /// called when this player captures a sector
    /// updates this players attack and defence bonuses
    /// sets the sectors owner and updates its colour
    ///
    /// </summary>
    /// <param name="sector">The sector that is being captured by this player</param>
    public void Capture(Sector sector)
    {
        // capture the given sector


        // store a copy of the sector's previous owner
        Player previousOwner = sector.GetOwner();

        // add the sector to the list of owned sectors
        ownedSectors.Add(sector);

        // remove the sector from the previous owner's
        // list of sectors
        if (previousOwner != null)
        {
            previousOwner.ownedSectors.Remove(sector);
        }

        // set the sector's owner to this player
        sector.SetOwner(this);

        // if the sector contains a landmark
        if (sector.GetLandmark() != null)
        {
            Landmark landmark = sector.GetLandmark();

            // remove the landmark's resource bonus from the previous
            // owner and add it to this player
            if (landmark.GetResourceType() == Landmark.ResourceType.Attack)
            {
                this.attack += landmark.GetAmount();
                if (previousOwner != null)
                {
                    previousOwner.attack -= landmark.GetAmount();
                }
            }
            else if (landmark.GetResourceType() == Landmark.ResourceType.Defence)
            {
                this.defence += landmark.GetAmount();
                if (previousOwner != null)
                {
                    previousOwner.defence -= landmark.GetAmount();
                }
            }
        }

        if (sector.IsVC())
        {
            game.NextTurnState(); // update turn mode before game is saved
            sector.SetVC(false);  // set VC to false so game can only be triggered once
            SavedGame.Save("_tmp", game);
            SceneManager.LoadScene(2);
        }
    }
    public override void activatePunishment()
    {
        //This method is called when the card is activated. It first colours all enemy units green, then calculates the amount of PVC bonus
        //earnt by each player. The enemy player's bonuses are then reset.

        Map map = GetOwner().GetGame().gameMap.GetComponent <Map>();

        //Colour the units.
        foreach (Sector sector in map.sectors)
        {
            Unit unit = sector.GetUnit();
            if (unit != null && sector.GetOwner() != this.GetOwner())
            {
                unit.SetColor(new Color(0.62f, 0.71f, 0.47f));
                unit.gameObject.GetComponent <Renderer> ().material.color = unit.GetColor();
            }
        }


        //Calculate the amount of PVC bonus each of the players own and add it to the playerPvcBonuses list.
        foreach (Player player in map.game.players)
        {
            if (player != this.GetOwner())
            {
                int[] bonuses = new int[2];
                bonuses [0] = player.GetBeer();
                bonuses [1] = player.GetKnowledge();

                foreach (Sector sector in player.ownedSectors)
                {
                    Landmark landmark = sector.GetLandmark();
                    if (landmark != null)
                    {
                        if (landmark.GetResourceType() == Landmark.ResourceType.Beer)
                        {
                            bonuses [0] = bonuses [0] - landmark.GetAmount();
                        }
                        else if (landmark.GetResourceType() == Landmark.ResourceType.Knowledge)
                        {
                            bonuses [1] = bonuses [1] - landmark.GetAmount();
                        }
                    }
                }
                playerPvcBonuses [player] = bonuses;

                // Reset the players bonuses
                player.SetBeer(0);
                player.SetKnowledge(0);
            }
        }
        Debug.Log("Flu activated!");
    }
Beispiel #4
0
    public IEnumerator CaptureLandmark_NeutralLandmarkPlayerKnowledgeAmountCorrect()
    {
        Setup();

        // capturing landmark
        Sector landmarkedSector = map.sectors[1];

        landmarkedSector.Initialize();
        Landmark landmark = landmarkedSector.GetLandmark();
        Player   playerA  = game.players[0];

        // ensure 'landmarkedSector' is a landmark of type Knowledge
        Assert.IsNotNull(landmarkedSector.GetLandmark());
        landmark.SetResourceType(Landmark.ResourceType.Knowledge);

        // get player knowledge amount before capture
        int oldKnowledge = playerA.GetKnowledge();

        playerA.Capture(landmarkedSector);

        // ensure sector is captured correctly
        Assert.AreSame(landmarkedSector.GetOwner(), playerA);
        Assert.IsTrue(playerA.ownedSectors.Contains(landmarkedSector));

        // ensure resources are gained correctly
        Assert.IsTrue(playerA.GetKnowledge() - oldKnowledge == landmark.GetAmount());

        yield return(null);
    }
Beispiel #5
0
    public void Capture(Sector sector)
    {
        // capture the given sector


        // store a copy of the sector's previous owner
        Player previousOwner = sector.GetOwner();

        // add the sector to the list of owned sectors
        ownedSectors.Add(sector);

        // remove the sector from the previous owner's
        // list of sectors
        if (previousOwner != null)
        {
            previousOwner.ownedSectors.Remove(sector);
        }

        // set the sector's owner to this player
        sector.SetOwner(this);

        // if the sector contains a landmark
        if (sector.GetLandmark() != null)
        {
            Landmark landmark = sector.GetLandmark();

            // remove the landmark's resource bonus from the previous
            // owner and add it to this player
            if (landmark.GetResourceType() == Landmark.ResourceType.Beer)
            {
                this.beer += landmark.GetAmount();
                if (previousOwner != null)
                {
                    previousOwner.beer -= landmark.GetAmount();
                }
            }
            else if (landmark.GetResourceType() == Landmark.ResourceType.Knowledge)
            {
                this.knowledge += landmark.GetAmount();
                if (previousOwner != null)
                {
                    previousOwner.knowledge -= landmark.GetAmount();
                }
            }
        }
    }
Beispiel #6
0
    public void Capture(Sector sector)           // capture the given sector
    // store a copy of the sector's previous owner
    {
        Player previousOwner = sector.GetOwner();

        // add the sector to the list of owned sectors
        ownedSectors.Add(sector);

        // remove the sector from the previous owner's
        // list of sectors
        if (previousOwner != null)
        {
            previousOwner.ownedSectors.Remove(sector);
        }

        // set the sector's owner to this player
        sector.SetOwner(this);

        // if the sector contains a landmark
        if (sector.GetLandmark() != null)
        {
            Landmark landmark = sector.GetLandmark();

            // remove the landmark's resource bonus from the previous
            // owner and add it to this player
            if (landmark.GetResourceType() == Landmark.ResourceType.Beer)
            {
                this.beer += landmark.GetAmount();
                if (previousOwner != null)
                {
                    //ASSESSMENT4 ADDITION: avoid bonuses from becoming negative when FreshersFlu card is played.
                    previousOwner.beer = Mathf.Max(previousOwner.beer - landmark.GetAmount(), 0);
                }
            }
            else if (landmark.GetResourceType() == Landmark.ResourceType.Knowledge)
            {
                this.knowledge += landmark.GetAmount();
                if (previousOwner != null)
                {
                    //ASSESSMENT4 ADDITION: avoid bonuses from becoming negative when FreshersFlu card is played.
                    previousOwner.knowledge = Mathf.Max(previousOwner.knowledge - landmark.GetAmount(), 0);
                }
            }
        }
    }
    public override void deactivatePunishment()
    {
        Map map = GetOwner().GetGame().gameMap.GetComponent <Map>();

        //Deactivates the card's visual effect.
        foreach (Sector sector in map.sectors)
        {
            Unit unit = sector.GetUnit();
            if (unit != null && sector.GetOwner() != this.GetOwner())
            {
                unit.SetColor(Color.white);
                unit.gameObject.GetComponent <Renderer> ().material.color = unit.GetColor();
            }
        }
        //Returns the bonuses back to normal by recalculating how much bonus they should have.
        foreach (Player player in playerPvcBonuses.Keys)
        {
            //Reset the player's bonuses => any PVC bonus gained when the card is active is lost.
            player.SetBeer(0);
            player.SetKnowledge(0);

            int[] bonuses = playerPvcBonuses [player];
            foreach (Sector sector in player.ownedSectors)
            {
                Landmark landmark = sector.GetLandmark();
                if (landmark != null)
                {
                    if (landmark.GetResourceType() == Landmark.ResourceType.Beer)
                    {
                        bonuses [0] += landmark.GetAmount();
                    }
                    else if (landmark.GetResourceType() == Landmark.ResourceType.Knowledge)
                    {
                        bonuses [1] += landmark.GetAmount();
                    }
                }
            }
            // Set the players bonuses back to normal.
            player.SetBeer(player.GetBeer() + bonuses[0]);
            player.SetKnowledge(player.GetKnowledge() + bonuses [1]);
        }
        this.SetOwner(null);
    }