Example #1
0
    public IEnumerator FreshersFluCard_ActivatePunishment_StoresPvcBonuses()
    {
        //Test that activate punishment correctly stores the amount of extra bonus gained from the PVC.
        Setup();
        game.InitializeMap();
        yield return(null);

        Player          testPlayer = players [0];
        FreshersFluCard testCard   = new FreshersFluCard(testPlayer);

        Player player2 = players [1];

        player2.SetKnowledge(player2.GetKnowledge() + 4);          //Give player2 an extra 4 knowledge points.

        testCard.activatePunishment();

        Dictionary <Player, int[]> pvcBonuses = testCard.GetPvcBonuses();

        Assert.AreEqual(0, pvcBonuses [player2] [0]);
        Assert.AreEqual(4, pvcBonuses [player2] [1]);
    }
Example #2
0
    public void Save()
    {
        Debug.Log("Entered Save Function");
        //Delete previous save data if exists
        if (File.Exists(Application.persistentDataPath + "/gameInformation.dat"))
        {
            File.Delete(Application.persistentDataPath + "/gameInformation.dat");
        }

        using (StreamWriter writer = new StreamWriter(Application.persistentDataPath + "/gameInformation.dat", true))
        {
            Debug.Log(Application.persistentDataPath);

            //write game state
            writer.WriteLine("Current Player:" + game.currentPlayer.name);
            writer.WriteLine("Turn state:" + game.GetTurnState());

            //write player info
            foreach (Player player in game.players)
            {
                writer.WriteLine(player.name + "Beer:" + player.GetBeer());
                writer.WriteLine(player.name + "Knowledge:" + player.GetKnowledge());
                writer.WriteLine(player.name + "IsHuman:" + player.IsHuman());
                writer.WriteLine(player.name + "IsActive:" + player.IsActive());

                // ASSESSMENT 4 ADDITION (22/03/2018)
                writer.Write(player.name + "PunishmentCards:");

                List <Card> cards = player.GetPunishmentCards();

                for (int i = 0; i < cards.Count; i++)
                {
                    writer.Write(cards[i].GetType().Name);

                    if (i + 1 != cards.Count)
                    {
                        writer.Write(",");
                    }
                }

                writer.WriteLine();
                //------------------------------------
            }

            // write sector info
            Sector[] sectors = map.GetComponentsInChildren <Sector>();

            foreach (Sector sector in sectors)
            {
                //write sector name and owner name
                writer.WriteLine(sector.name + ":");
                if (sector.GetOwner() == null)
                {
                    writer.WriteLine("owner:null");
                }
                else
                {
                    writer.WriteLine("owner:" + sector.GetOwner().name);
                }

                //write viceChance info
                if (sector.GetLandmark() == null)
                {
                    writer.WriteLine("viceChance:null");
                }
                else
                {
                    if (sector.GetLandmark().GetResourceType() == Landmark.ResourceType.ViceChancellor)
                    {
                        writer.WriteLine("viceChance:" + sector.GetLandmark().GetResourceType());
                    }
                    else
                    {
                        writer.WriteLine("viceChance:" + sector.GetLandmark().GetResourceType().ToString());
                    }
                }

                //write unit info
                if (sector.GetUnit() == null)
                {
                    writer.WriteLine("unit:null");
                }
                else
                {
                    //ASSESSMENT 4 ADDITION (22/03/2018)
                    Color  unitColor = sector.GetUnit().GetColor();
                    string ownerName = sector.GetUnit().GetOwner().name;
                    int    unitLevel = sector.GetUnit().GetLevel();

                    writer.WriteLine("unitOwner:" + ownerName + ":" + unitLevel + ":" + unitColor.r + ":" + unitColor.g + ":" + unitColor.b);
                    //----------------------------------
                }
            }

            // ASSESSMENT 4 ADDITION (22/03/2018)
            // Save active cards and their state
            List <Card> activeCards = game.cardDeck.GetActiveCards();
            writer.WriteLine("activeCards:" + activeCards.Count);

            foreach (Card activeCard in activeCards)
            {
                writer.WriteLine(activeCard.GetType().Name + ":" + activeCard.GetOwner().name + ":" + activeCard.GetTurnCount());

                switch (activeCard.GetType().Name)
                {
                case "FreshersFluCard":
                    FreshersFluCard            card             = (FreshersFluCard)activeCard;
                    Dictionary <Player, int[]> playerPvcBonuses = card.GetPvcBonuses();

                    foreach (KeyValuePair <Player, int[]> entry in playerPvcBonuses)
                    {
                        writer.WriteLine(entry.Key.name + ":" + entry.Value[0] + ":" + entry.Value[1]);
                    }

                    break;
                }
            }
            //------------------------------------
        }

        Debug.Log("Saved!");
    }