Advertisement
Gillito

Untitled

Jun 9th, 2015
209
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.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.             game.player1 = new Warrior();
  15.             game.player2 = new Archer();
  16.  
  17.             do
  18.             {
  19.                 game.StartGame();
  20.                 //Console.WriteLine(game.player1.Health);
  21.                 //Console.WriteLine(game.player2.Health);
  22.  
  23.                 if (game.player1.Health <= 0)
  24.                 {
  25.                     Console.WriteLine("Player 2 Wins!");
  26.                     break;
  27.                 }
  28.                 else if (game.player2.Health <= 0)
  29.                 {
  30.                     Console.WriteLine("Player 1 Wins!");
  31.                     break;
  32.                 }
  33.             }
  34.             while (game.player1.Health > 0 || game.player2.Health > 0);
  35.  
  36.            
  37.         }
  38.     }
  39.  
  40.     class Game
  41.     {
  42.         public Character player1;
  43.         public Character player2;
  44.  
  45.         public void StartGame()
  46.         {
  47.             player2.Health = player2.Health - player1.Attack();
  48.  
  49.             player1.Health = player1.Health - player2.Attack();
  50.         }
  51.     }
  52.  
  53.     class Character
  54.     {
  55.         public int Health = 100;
  56.  
  57.         public virtual int Attack()
  58.         {
  59.             return 0;
  60.         }
  61.     }
  62.  
  63.     class Warrior : Character
  64.     {
  65.         public override int Attack()
  66.         {
  67.             return 20;
  68.         }
  69.     }
  70.  
  71.     class Archer : Character
  72.     {
  73.         public override int Attack()
  74.         {
  75.                 return 60;
  76.         }
  77.     }
  78. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement