Advertisement
Guest User

Untitled

a guest
Feb 17th, 2020
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.92 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 Inheritance.MapObjects
  8. {
  9.     public interface IOwnerable
  10.     {
  11.         int Owner { get; set; }
  12.     }
  13.  
  14.     public interface ILootable
  15.     {
  16.         Treasure Treasure { get; set; }
  17.     }
  18.  
  19.     public interface IAttackble
  20.     {
  21.         Army Army { get; set; }
  22.     }
  23.  
  24.  
  25.     public class Dwelling : IOwnerable
  26.     {
  27.         public int Owner { get; set; }
  28.     }
  29.  
  30.     public class Mine : IOwnerable, IAttackble, ILootable
  31.     {
  32.         public int Owner { get; set; }
  33.         public Army Army { get; set; }
  34.         public Treasure Treasure { get; set; }
  35.     }
  36.  
  37.     public class Creeps : IAttackble, ILootable
  38.     {
  39.         public Army Army { get; set; }
  40.         public Treasure Treasure { get; set; }
  41.     }
  42.  
  43.     public class Wolfs : IAttackble
  44.     {
  45.         public Army Army { get; set; }
  46.     }
  47.  
  48.     public class ResourcePile : ILootable
  49.     {
  50.         public Treasure Treasure { get; set; }
  51.     }
  52.  
  53.     public static class Interaction
  54.     {
  55.         public static void Make(Player player, object mapObject)
  56.         {
  57.             if (mapObject is IAttackble)
  58.             {
  59.                 if (player.CanBeat((mapObject as IAttackble).Army))
  60.                 {
  61.                     if (mapObject is IOwnerable) (mapObject as IOwnerable).Owner = player.Id;
  62.                     if (mapObject is ILootable)  player.Consume((mapObject as ILootable).Treasure);
  63.                 }
  64.                 else player.Die();
  65.             }
  66.             else if (mapObject is IOwnerable)
  67.             {
  68.                 (mapObject as IOwnerable).Owner = player.Id;
  69.                 if (mapObject is ILootable) player.Consume((mapObject as ILootable).Treasure);
  70.             }
  71.             else if (mapObject is ILootable)
  72.                 player.Consume((mapObject as ILootable).Treasure);
  73.         }
  74.     }
  75. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement