Advertisement
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;
- using System.Threading;
- using System.Threading.Tasks;
- namespace ConsoleApp1
- {
- class Program
- {
- static void Main(string[] args)
- {
- int tower = 50;
- var player = 50;
- Boolean first = ((new Random()).Next(0, 2) == 1 ? true : false);
- attack(tower, player, first);
- Console.ReadKey();
- }
- static void attack(int tower, int player, Boolean isPlayer) {
- Random r = new Random();
- int attackDamage;
- if (isPlayer)
- {
- attackDamage = r.Next(1, tower);
- }
- else {
- attackDamage = r.Next(1, player);
- }
- if(isPlayer){
- Console.WriteLine("Damage giving to Tower: " + attackDamage + " (" + (tower - attackDamage) + "/50)");
- }else {
- Console.WriteLine("Damage giving to Player: " + attackDamage + " (" + (player - attackDamage) + "/50)");
- }
- if(isPlayer)
- {
- tower -= attackDamage;
- if (tower <= 0)
- {
- Console.WriteLine("The Player has won!");
- return;
- }
- }
- else {
- player -= attackDamage;
- if (player <= 0) {
- Console.WriteLine("The Tower has won!");
- return;
- }
- }
- Thread.Sleep(1000);
- attack(tower, player, !isPlayer);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement