Advertisement
Guest User

Untitled

a guest
Jun 28th, 2017
58
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.Drawing;
  6.  
  7. namespace Quest
  8. {
  9.     abstract class Weapon : Mover
  10.     {
  11.         // protected Game game;
  12.         private bool pickedUp;
  13.         public bool PickedUp { get { return pickedUp; } }
  14.         //private Point Location { get { return location; } }
  15.  
  16.         public Weapon(Game game, Point location) : base(game, location)
  17.         {
  18.             //this.game = game;
  19.             //this.location = location;
  20.             pickedUp = false;
  21.         }
  22.  
  23.         public void PickUpWeapon() { pickedUp = true; }
  24.  
  25.         public abstract string Name { get; }
  26.  
  27.         public abstract void Attack(Direction direction, Random random);
  28.  
  29.         protected bool DamageEnemy(Direction direction, int radius,
  30.                                    int damage, Random random)
  31.         {
  32.  
  33.             Point target = game.PlayerLocation;
  34.             for (int distance = 0; distance < radius; distance++)
  35.             {
  36.                 foreach (Enemy enemy in game.Enemies)
  37.                 {
  38.                     if (Nearby(enemy.Location, target, radius))
  39.                     {
  40.                         enemy.Hit(damage, random);
  41.                         return true;
  42.                     }
  43.                 }
  44.                 target = Move(direction, target, game.Boundaries);
  45.             }
  46.             return false;
  47.         }
  48.  
  49.         public Point Move(Direction direction, Point target, Rectangle boundaries) {
  50.        
  51.         Point newLocation = target;
  52.         /*
  53.         switch (direction) {
  54.             case Direction.Up:
  55.                 if (newLocation.Y >= boundaries.Top)
  56.                 newLocation.Y -= MoveInterval;
  57.                 break;
  58.             case Direction.Down:
  59.                 if (newLocation.Y + MoveInterval >= boundaries.Bottom)
  60.                 newLocation.Y += MoveInterval;
  61.                 break;
  62.             case Direction.Left:
  63.                 if (newLocation.X - MoveInterval >= boundaries.Left)
  64.                 newLocation.X -= MoveInterval;
  65.                 break;
  66.             case Direction.Right:
  67.                 if (newLocation.X + MoveInterval <= boundaries.Right)
  68.                 newLocation.X += MoveInterval;
  69.                 break;
  70.             default: break;
  71.             }
  72.        */
  73.         return newLocation;  //this is not correct
  74.         }
  75.  
  76.         public bool Nearby(Point locationToCheck, Point target, int distance)
  77.         {
  78.             if (Math.Abs(target.X - locationToCheck.X) < distance &&
  79.                (Math.Abs(target.Y - locationToCheck.Y) < distance))
  80.             {
  81.                 return true;
  82.             }
  83.             else
  84.             {
  85.                 return false;
  86.             }
  87.         }
  88.        
  89.     }
  90. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement