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.Tasks;
- namespace MarchFour
- {
- class Program
- {
- static int userTempHealth;
- static int cpuTempHealth;
- static void Main(string[] args)
- {
- Random rnd = new Random();
- Player user = new Player("User", 100, 25);
- Player cpu = new Player("Computer", 100, 25);
- //user goes first
- //cpu goes second
- string attackingPlayer = "cpu";
- do
- {
- if (attackingPlayer == "cpu")
- {
- attackingPlayer = "user";
- }
- else if (attackingPlayer == "user")
- {
- attackingPlayer = "cpu";
- }
- //Inform user whos turn it is
- if (attackingPlayer == "user")
- {
- Console.WriteLine("It's your turn. Press any key to attack");
- Console.ReadKey();
- int currentAttack = ModifiedAttack(rnd, user);
- user.Health += -currentAttack;
- Console.WriteLine($"Your attack did {currentAttack} damage!");
- Console.WriteLine("Here are the current stats:\n");
- DisplayStats(user, cpu);
- Console.WriteLine("Press any key to continue");
- Console.Read();
- }
- if (attackingPlayer == "cpu")
- {
- Console.Write("It's cpu's turn. Brace for attack! Press any key to continue.");
- Console.ReadKey();
- }
- } while ( (user.Health >= 0) || (cpu.Health >= 0) );
- Console.WriteLine("Game has ended");
- do
- {
- DisplayStats(user, cpu);
- Console.ReadLine();
- user.Health += -20;
- cpu.Health += -20;
- DisplayStats(user, cpu);
- Console.ReadLine();
- for (int i = 0; i < 25; i++)
- {
- Console.WriteLine(ModifiedAttack(rnd, user));
- }
- //int tempNum = (int)Math.Round(3.45, 0);
- //Console.WriteLine(tempNum);
- //int currentAttack = Math.Round(25 * RandomAttack(rnd),0);
- Console.ReadLine();
- } while (true);
- }
- public static void DisplayStats(Player user, Player cpu)
- {
- //Display stats for user and cpu
- Console.WriteLine($"{"Player Name",-15} {"Health",-10} {"Attack",-10}");
- Console.WriteLine("");
- Console.WriteLine($"{user.Name,-15} {user.Health,-10} {user.BaseAttack,-10}");
- Console.WriteLine($"{cpu.Name,-15} {cpu.Health,-10} {cpu.BaseAttack,-10}");
- }
- //Takes in the Player class, randomly modifies its attack and returns the current attack.
- public static int ModifiedAttack(Random rnd, Player player)
- {
- int randomNumber = rnd.Next(-50, 50);
- if(randomNumber != 0)
- {
- double modifier = ((double)randomNumber) / 100;
- double attackAsDouble = (player.BaseAttack * modifier);
- int currentAttack = (int)attackAsDouble + player.BaseAttack;
- return currentAttack;
- }
- else
- {
- return player.BaseAttack;
- }
- }
- }
- }
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace MarchFour
- {
- class Player
- {
- public string Name { get; set; }
- public int Health { get; set; }
- public int BaseAttack { get; set; }
- public Player() { }
- public Player(string name, int health, int baseAttack)
- {
- this.Name = name;
- this.Health = health;
- this.BaseAttack = baseAttack;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement