Advertisement
Gillito

Untitled

Jun 9th, 2015
192
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.14 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 Archer();
  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.Health =  - player2.Attack();
  52.             player2.Health =  - player1.Attack();
  53.         }
  54.     }
  55.  
  56.     class Character
  57.     {
  58.         public int Health = 100;
  59.         public virtual int Attack()
  60.         {
  61.             return 0;
  62.         }
  63.  
  64.         public virtual void GetDamage(int damage);
  65.  
  66.     }
  67.  
  68.     class Warrior : Character
  69.     {
  70.         public override int Attack()
  71.         {
  72.             return 30;
  73.         }
  74.     }
  75.  
  76.     class Archer : Character
  77.     {
  78.         Random rnd = new Random();
  79.         public override int Attack()
  80.         {
  81.             if (rnd.Next(2) == 1)
  82.                 return 20;
  83.             else
  84.                 return 30;
  85.         }
  86.     }
  87.  
  88.     class Mage : Character
  89.     {
  90.         public override void GetDamage(int damage)
  91.         {
  92.             Health = Health - damage;
  93.         }
  94.  
  95.         public override int Attack()
  96.         {
  97.             return 15;
  98.         }
  99.     }
  100. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement