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; }
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)); }
public bool IsEnded(Location l) { return At(l) == END; }
public bool IsEmpty(Location l) { return At(l) == EMPTY; }
public int At(Location l) { return board[l.Y, l.X]; }
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(); }