Beispiel #1
0
    public void pirateTakesItems()
    {
        string returnedPortDetails = dm.returnPortDetails(mapManager.lastPortChosen.portName);

        string[] port = returnedPortDetails.Split(',');

        System.Random random     = new System.Random();
        int           pirateCrew = 0;

        //calculate how many pirate crew there are
        switch (port[3])
        {
        case "low":
            pirateCrew = random.Next(1, 4);
            break;

        case "medium":
            pirateCrew = random.Next(3, 6);
            break;

        case "high":
            pirateCrew = random.Next(5, 10);
            break;
        }

        //get the game data and get the crew you own within it

        string returnedGameData = dm.returnGameData();

        //Split it by commas
        gameData = returnedGameData.Split(',');

        crewHired    = Int32.Parse(gameData[2]);
        silverOwned  = Int32.Parse(gameData[3]);
        potteryOwned = Int32.Parse(gameData[4]);

        int itemsPirateWillTake = pirateCrew - crewHired;

        int potteryItemstoTake = 0;

        //If the pirates have more crew
        if (itemsPirateWillTake > 0)
        {
            //if you have more silver than what they will take
            if (silverOwned - itemsPirateWillTake >= 0)
            {
                //Adjust silver
                silverOwned = silverOwned - itemsPirateWillTake;

                //Take a record of how may silver items were taken
                howManySilverPiratesTook = itemsPirateWillTake;

                //Set the pottery pieces to zero
                howManyPotteryPiratesTook = 0;
            }
            else
            {
                //determine how many more items to take and turn to positive
                potteryItemstoTake = (silverOwned - itemsPirateWillTake) * -1;

                //if you have more pottery than what they will take
                if (potteryOwned - potteryItemstoTake >= 0)
                {
                    //Adjust pottery
                    potteryOwned = potteryOwned - potteryItemstoTake;

                    //Take a record of how may pottery items were taken
                    howManyPotteryPiratesTook = potteryItemstoTake;
                }
                else
                {
                    //Take a record of how may pottery items were taken
                    howManyPotteryPiratesTook = potteryOwned;

                    //adjust pottery
                    potteryOwned = 0;
                }


                //Take a record of how may silver items were taken
                howManySilverPiratesTook = silverOwned;

                //if pirate took all your silver then set it to zero
                silverOwned = 0;
            }
        }
    }