Ejemplo n.º 1
0
        public bool IsValidMove(Base.ICreature creature, int dx, int dy)
        {
            int x = creature.XPos + dx;
            int y = creature.YPos + dy;

            if (x >= Console.WindowWidth || x <= 0)
            {
                return(false);
            }
            if (y >= Console.WindowHeight || y <= 0)
            {
                return(false);
            }
            if (LevelCreatures.Exists(c => c.XPos == x && c.YPos == y))
            {
                return(false);
            }
            if (LevelWalls.Exists(w => w.XPos == x && w.YPos == y))
            {
                return(false);
            }
            //if (LevelTiles.Exists(t => t.XPos == x && t.YPos == y && t.GetType() == typeof(Tiles.Water))) return false;

            return(true);
        }
Ejemplo n.º 2
0
 public void MoveCreature(Base.ICreature creature, int dx, int dy)
 {
     if (IsValidMove(creature, dx, dy))
     {
         DrawTile(GetTileUnderCreature(creature));
         creature.XPos += dx;
         creature.YPos += dy;
         DrawCreature(creature);
     }
 }
Ejemplo n.º 3
0
        public void Start()
        {
            PC = new Creatures.SampleCharacter();
            Initialize();
            DrawCreature(PC);

            while (true)
            {
                var key = Console.ReadKey(true).Key;

                switch (key)
                {
                case ConsoleKey.LeftArrow:
                    MoveCreature(PC, -1, 0);
                    break;

                case ConsoleKey.RightArrow:
                    MoveCreature(PC, +1, 0);
                    break;

                case ConsoleKey.DownArrow:
                    MoveCreature(PC, 0, +1);
                    break;

                case ConsoleKey.UpArrow:
                    MoveCreature(PC, 0, -1);
                    break;

                case ConsoleKey.Escape:
                    return;

                case ConsoleKey.F8:
                    break;

                case ConsoleKey.F7:
                    RoomTest();
                    PopulateTiles();
                    PopulateWalls();
                    //CutOutRooms();
                    CutoutForBSP();
                    DrawLevel();
                    DrawCreature(PC);
                    Console.CursorVisible = false;
                    break;

                case ConsoleKey.F5:
                    Initialize();
                    break;

                default:
                    break;
                }
            }
        }
Ejemplo n.º 4
0
        public Base.ITile GetTileUnderCreature(Base.ICreature creature)
        {
            var tile = LevelTiles.Find(t => t.XPos == creature.XPos && t.YPos == creature.YPos);

            return(tile); //?? new Tiles.Stone(creature.XPos, creature.YPos);
        }
Ejemplo n.º 5
0
 public void DrawCreature(Base.ICreature creature)
 {
     Console.SetCursorPosition(creature.XPos, creature.YPos);
     Console.ForegroundColor = creature.Color;
     Console.Write(creature.Icon);
 }