Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Windows.Forms;
- namespace Digger
- {
- class Player : ICreature
- {
- CreatureCommand Move(int x, int y, int dx, int dy)
- {
- var newX = x + dx;
- var newY = y + dy;
- var result = new CreatureCommand();
- if (newX < Game.MapWidth && newX >= 0 &&
- newY < Game.MapHeight && newY >= 0)
- return new CreatureCommand() { DeltaX = dx, DeltaY = dy };
- return new CreatureCommand();
- }
- public CreatureCommand Act(int x, int y)
- {
- switch (Game.KeyPressed)
- {
- case Keys.Left: return Move(x, y, -1, 0);
- case Keys.Right: return Move(x, y, 1, 0);
- case Keys.Up: return Move(x, y, 0, -1);
- case Keys.Down: return Move(x, y, 0, 1);
- }
- return new CreatureCommand();
- }
- public bool DeadInConflict(ICreature enemy)
- {
- return false;
- }
- public int GetDrawingPriority()
- {
- return 0;
- }
- public string GetImageFileName()
- {
- return "Digger.png";
- }
- }
- class Terrain : ICreature
- {
- public CreatureCommand Act(int x, int y)
- {
- return new CreatureCommand();
- }
- public bool DeadInConflict(ICreature enemy)
- {
- return enemy is Player;
- }
- public int GetDrawingPriority()
- {
- return 1;
- }
- public string GetImageFileName()
- {
- return "Terrain.png";
- }
- }
- }
- using System.Windows.Forms;
- namespace Digger
- {
- class Player : ICreature
- {
- CreatureCommand Move(int x, int y, int dx, int dy)
- {
- var newX = x + dx;
- var newY = y + dy;
- var result = new CreatureCommand();
- if (newX < Game.MapWidth && newX >= 0 &&
- newY < Game.MapHeight && newY >= 0 &&
- !(Game.Map[newX,newY] is Sack))
- return new CreatureCommand() { DeltaX = dx, DeltaY = dy };
- return new CreatureCommand();
- }
- public CreatureCommand Act(int x, int y)
- {
- switch (Game.KeyPressed)
- {
- case Keys.Left: return Move(x, y, -1, 0);
- case Keys.Right: return Move(x, y, 1, 0);
- case Keys.Up: return Move(x, y, 0, -1);
- case Keys.Down: return Move(x, y, 0, 1);
- }
- return new CreatureCommand();
- }
- public bool DeadInConflict(ICreature enemy)
- {
- return enemy is Sack;
- }
- public int GetDrawingPriority()
- {
- return 0;
- }
- public string GetImageFileName()
- {
- return "Digger.png";
- }
- }
- class Terrain : ICreature
- {
- public CreatureCommand Act(int x, int y)
- {
- return new CreatureCommand();
- }
- public bool DeadInConflict(ICreature enemy)
- {
- return enemy is Player;
- }
- public int GetDrawingPriority()
- {
- return 1;
- }
- public string GetImageFileName()
- {
- return "Terrain.png";
- }
- }
- class Sack : ICreature
- {
- int falledFor;
- public CreatureCommand Act(int x, int y)
- {
- if (IsTileSolid(x, y + 1) || DidPlayerCatchedIt(x, y))
- {
- falledFor = 0;
- return new CreatureCommand();
- }
- if (IsTileSolid(x, y + 2) && falledFor > 0)
- return new CreatureCommand() { DeltaY = 1, TransformTo = new Gold() };
- falledFor++;
- return new CreatureCommand() { DeltaY = 1 };
- }
- public bool DidPlayerCatchedIt(int x, int y)
- {
- return Game.Map[x, y + 1] is Player && falledFor == 0;
- }
- public bool IsTileSolid(int x, int y)
- {
- if (Game.MapHeight <= y) return true;
- var tile = Game.Map[x, y];
- return tile is Terrain || tile is Gold || tile is Sack;
- }
- public bool DeadInConflict(ICreature enemy)
- {
- return false;
- //return enemy is Terrain || enemy is Sack || enemy is Gold;
- }
- public int GetDrawingPriority()
- {
- return 1;
- }
- public string GetImageFileName()
- {
- return "Sack.png";
- }
- }
- class Gold : ICreature
- {
- //int value = 1;
- public CreatureCommand Act(int x, int y)
- {
- return new CreatureCommand();
- }
- public bool DeadInConflict(ICreature enemy)
- {
- if (enemy is Player)
- {
- Game.Scores += 10;
- return true;
- }
- return enemy is Gold;
- }
- public int GetDrawingPriority()
- {
- return 1;
- }
- public string GetImageFileName()
- {
- return "Gold.png";
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement