Ejemplo n.º 1
0
        public RPGGameModel()
        {
            Random = new Random();
            Board = new Board();
            Hero = new Actor();
            Hero.Name = "Nameless Hero";
            Hero.Location = Board.GetStartPoint();
            Hero.HP = 200;
            Hero.EP = 10;

            Monster = new Actor();
            Monster.Name = "A Monstor";
            Monster.HP = 200;
            Monster.EP = 30;
            Location l = new Location(Random.Next(0, Board.GetWidth()), Random.Next(0, Board.GetHeight()));
            while(!Board.IsEmpty(l))
            {
                l = new Location(Random.Next(0, Board.GetWidth()), Random.Next(0, Board.GetHeight()));
            }
            Monster.Location= l;
        }
Ejemplo n.º 2
0
 public bool IsMovableTo(Location l)
 {
     if (l.X < 0 && l.X > GetWidth() - 1 && l.Y < 0 && l.Y > GetHeight() - 1) return false;
     return (IsEmpty(l) ||  IsEnded(l));
 }
Ejemplo n.º 3
0
 public bool IsEnded(Location l)
 {
     return At(l) == END;
 }
Ejemplo n.º 4
0
 public bool IsEmpty(Location l)
 {
     return At(l) == EMPTY;
 }
Ejemplo n.º 5
0
 public int At(Location l)
 {
     return board[l.Y, l.X];
 }
Ejemplo n.º 6
0
        public void MoveHero(int direction)
        {
            int xx = Hero.Location.X;
            int yy = Hero.Location.Y;

            switch(direction)
            {
                case UP:
                    yy = Hero.Location.Y - 1;
                    break;
                case DOWN:
                    yy = Hero.Location.Y + 1;
                    break;
                case LEFT:
                    xx = Hero.Location.X - 1;
                    break;
                case RIGHT:
                    xx = Hero.Location.X + 1;
                    break;
            }
            Location newLoc = new Location(xx, yy);

            if (!board.IsMovableTo(newLoc))
            {
                status = CANTMOVE;
            }
            else
            {
                hero.Location = newLoc;
                if (hero.Location == monster.Location)
                {
                    status = MONSTER;
                } else if (board.IsEnded(hero.Location))
                {
                    status = ENDED;
                } else
                {
                    status = MOVED;

                }

            }
            NotifyAll();
        }