Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- namespace CombatSimCode
- {
- class Combat
- {
- static public bool Battle(int attackUnits, int defendUnits)
- {
- // Create random number genereator
- Random rand = new Random();
- // Dice totals
- int attackTotal = 0;
- int defendTotal = 0;
- // Attackers Dice
- int attackDice = 0;
- // Deneders Dice
- int defendDice = 0;
- // Get a random value for each unit that attacks
- for (int i = 0; i < attackUnits; i++)
- {
- attackDice = rand.Next(1, 7);
- // Add the result to the total
- attackTotal += attackDice;
- // Reset to 0 for the next dice
- attackDice = 0;
- }
- // Get a random value for every defender that defends
- for (int i = 0; i < defendUnits; i++)
- {
- defendDice = rand.Next(1, 7);
- // Add the result to the total
- defendTotal += defendDice;
- // Reset to 0 for the next dice
- defendDice = 0;
- }
- // Display---------------------------------------------------------------------
- // Display attackers result
- Console.Write("Attackers rolled: ");
- Console.WriteLine(attackTotal);
- // Display defenders result
- Console.Write("Defenders rolled: ");
- Console.WriteLine(defendTotal);
- // If the Attacker is higher he wins, if the defender is drawing or higher he wins
- if (attackTotal > defendTotal)
- {
- Console.WriteLine("Attackers Win!");
- return true;
- }
- else
- {
- Console.WriteLine("Defenders Win!");
- return false;
- }
- }
- static public void AssigningLand(bool attackSuccess, int attackingLandIndex, int defendingLandIndex, Land[] landArray)
- {
- // If attckers win
- if (attackSuccess)
- {
- // Swap Teams, if team 1 change to team 0
- if (landArray[defendingLandIndex].team == 1)
- {
- landArray[defendingLandIndex].team = 0;
- }
- else
- {
- // If team 0 then change to team 1
- landArray[defendingLandIndex].team = 1;
- }
- // The attacking units go into the defending land minus 1
- landArray[defendingLandIndex].units = landArray[attackingLandIndex].units - 1;
- // Leave one unit behind from the attacking team
- landArray[attackingLandIndex].units = 1;
- }
- // If the attack fails
- else
- {
- // Leave one unit behind from the attacking team
- landArray[attackingLandIndex].units = 1;
- }
- }
- }
- }
Add Comment
Please, Sign In to add comment