Advertisement
Gillito

Untitled

Jun 10th, 2015
187
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.69 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace ConsoleApplication38
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             Game game = new Game();
  14.  
  15.             Console.WriteLine("Welcome to Shlyapa Bojarskogo video game!");
  16.            
  17.             game.player1 = new Monk();
  18.             game.player2 = new Mage();
  19.  
  20.             do
  21.             {
  22.                 game.StartGame();
  23.                 Console.WriteLine(game.player1.Health);
  24.                 Console.WriteLine(game.player2.Health);
  25.                 Console.WriteLine();
  26.  
  27.                 if (game.player1.Health <= 0)
  28.                 {
  29.                     Console.WriteLine("Player 2 Wins!");
  30.                     break;
  31.                 }
  32.                 else if (game.player2.Health <= 0)
  33.                 {
  34.                     Console.WriteLine("Player 1 Wins!");
  35.                     break;
  36.                 }
  37.             }
  38.             while (true);
  39.  
  40.            
  41.         }
  42.     }
  43.  
  44.     class Game
  45.     {
  46.         public Character player1;
  47.         public Character player2;
  48.  
  49.         public void StartGame()
  50.         {
  51.             player1.ReceiveDamage(player2.Attack());
  52.             player2.ReceiveDamage(player1.Attack());
  53.         }
  54.     }
  55.  
  56.     class Character
  57.     {
  58.         public int Health = 100;
  59.  
  60.         public virtual int Attack()
  61.         {
  62.             return 0;
  63.         }
  64.  
  65.         public virtual void ReceiveDamage(int damage)
  66.         {
  67.             Health = Health - damage;
  68.         }
  69.     }
  70.  
  71.     class Warrior : Character
  72.     {
  73.         public override int Attack()
  74.         {
  75.             return 30;
  76.         }
  77.     }
  78.  
  79.     class Archer : Character
  80.     {
  81.         Random rnd = new Random();
  82.         public override int Attack()
  83.         {
  84.             if (rnd.Next(2) == 1)
  85.                 return 20;
  86.             else
  87.                 return 40;
  88.         }
  89.     }
  90.  
  91.     class Mage : Character
  92.     {
  93.         int magicBarier = 10;
  94.         public override void ReceiveDamage(int damage)
  95.         {
  96.             if (damage < magicBarier)
  97.                 magicBarier = 0;
  98.             Health = Health - damage + magicBarier;
  99.         }
  100.  
  101.         public override int Attack()
  102.         {
  103.             return 15;
  104.         }
  105.     }
  106.  
  107.     class Monk : Character
  108.     {
  109.         int heal = 0;
  110.         public void ReceiveDamage(int damage)
  111.         {
  112.             Random rnd = new Random();
  113.             if (rnd.Next(2) == 1)
  114.                 heal = 10;
  115.  
  116.             Health = Health - damage + heal;
  117.         }
  118.  
  119.         public override int Attack()
  120.         {
  121.             return 20;
  122.         }
  123.     }
  124. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement