Advertisement
Gillito

Untitled

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