Example #1
0
        public bool FindPosition(int Left, int Right)
        {
            bool posFound = false;
            byte tries    = 0;

            while (!posFound && tries < 20)
            {
                short xPos = (short)(Game.rand.Next(Left + 1, Right - 1));
                short yPos = (short)(Game.rand.Next(5, 19));
                if (EngineFunctions.screenBufferArray[yPos, xPos].AsciiChar == ' ')
                {
                    posFound = true;
                    loc      = new EngineFunctions.COORD(xPos, yPos);
                    break;
                }
                tries++;
            }

            if (!posFound)
            {
                return(false);
            }
            else
            {
                return(true);
            }
        }
Example #2
0
 public Shop()
 {
     rand         = new Random();
     itemsForSale = new ItemType[3];
     prices       = new int[3];
     CanBuy       = true;
     location     = new EngineFunctions.COORD(0, 0);
 }
Example #3
0
        public void LoadGame(int slot, ref HUD hudInfo, ref Player pInfo, ref List <int> exploredRooms,
                             ref EngineFunctions.COORD room, ref List <Tuple <EngineFunctions.COORD, EngineFunctions.COORD> > unlockedDoors)
        {
            //try
            //{
            //    using (StreamReader reader = new StreamReader(saves[slot]))
            //    {
            //        reader.ReadLine();
            //        hudInfo = GetMap(reader.ReadLine());
            //        hudInfo.Bombs = Byte.Parse(reader.ReadLine());
            //        hudInfo.Keys = Byte.Parse(reader.ReadLine());
            //        hudInfo.MagicAmt = Byte.Parse(reader.ReadLine());
            //        hudInfo.Money = Int32.Parse(reader.ReadLine());

            //        string pos = reader.ReadLine();
            //        pInfo = new Player(new EngineFunctions.COORD(Int16.Parse(pos.Substring(0, pos.IndexOf(','))),
            //            Int16.Parse(pos.Substring(pos.IndexOf(',') + 1))));

            //        pInfo.curFacing = GetDirection(reader.ReadLine());

            //        string hp = reader.ReadLine();
            //        pInfo.CurHP = Int32.Parse(hp.Substring(0, hp.IndexOf('/')));
            //        pInfo.HP = Int32.Parse(hp.Substring(hp.IndexOf('/') + 1));

            //        pInfo.Sword = GetSword(reader.ReadLine());

            //        string mapLoc = reader.ReadLine();
            //        room = new EngineFunctions.COORD(Int16.Parse(mapLoc.Substring(0, mapLoc.IndexOf(','))),
            //            Int16.Parse(mapLoc.Substring(mapLoc.IndexOf(',') + 1)));

            //        string[] expred = reader.ReadLine().Split(' ');
            //        exploredRooms = new List<int>();
            //        for (int i = 0; i < expred.GetLength(0) - 1; i++)
            //        {
            //            exploredRooms.Add(Int32.Parse(expred[i]));
            //        }

            //        unlockedDoors = new List<Tuple<EngineFunctions.COORD, EngineFunctions.COORD>>();
            //        string d = reader.ReadLine();
            //        while (d != null && !d.Equals(""))
            //        {
            //            string[] rooms = d.Split(' ');
            //            unlockedDoors.Add(new Tuple<EngineFunctions.COORD,EngineFunctions.COORD>(
            //                new EngineFunctions.COORD(Int16.Parse(rooms[0].Substring(0, rooms[0].IndexOf(','))),
            //                    Int16.Parse(rooms[0].Substring(rooms[0].IndexOf(',') + 1))),
            //                new EngineFunctions.COORD(Int16.Parse(rooms[1].Substring(0, rooms[1].IndexOf(','))),
            //                    Int16.Parse(rooms[1].Substring(rooms[1].IndexOf(',') + 1)))));
            //            d = reader.ReadLine();
            //        }
            //    }
            //}
            //catch (IOException)
            //{

            //}
        }
Example #4
0
 public Particle(char c, int s, int l, ConsoleColor color, short x, short y)
 {
     PartChar = c;
     Speed    = s;
     Life     = l;
     Color    = color;
     Pos      = new EngineFunctions.COORD(x, y);
     timer    = new Stopwatch();
     KillFlag = false;
     Moved    = 0;
 }
Example #5
0
 public Player(EngineFunctions.COORD p)
 {
     playerInput = new Input();
     location    = p;
     CurHP       = HP;
     curFacing   = FaceDirection.Down;
     Sword       = SwordType.Wood;
     SwingSword  = false;
     CurItem     = ItemType.Magic;
     inputThread = new Thread(new ThreadStart(GetInput));
     inputThread.Start();
 }
Example #6
0
        private void LoadSaveGame(int slot)
        {
            List <int> exploredRooms = new List <int>();

            EngineFunctions.COORD room = new EngineFunctions.COORD();
            List <Tuple <EngineFunctions.COORD, EngineFunctions.COORD> > doors =
                new List <Tuple <EngineFunctions.COORD, EngineFunctions.COORD> >();
            Player p = player;

            Program.saver.LoadGame(slot, ref hud, ref p, ref exploredRooms, ref room, ref doors);

            player        = p;
            m             = new Map(room);
            RoomsExplored = exploredRooms.Count;
            m.SetExploredRooms(exploredRooms);
        }
        public static char GetCharacterAtPosition(EngineFunctions.COORD pos)
        {
            IntPtr        handler      = GetStdHandle(STD_OUTPUT_HANDLE);
            uint          width        = 1;
            StringBuilder sb           = new StringBuilder((int)width);
            COORD         readCoord    = new COORD(pos.X, pos.Y);
            uint          numCharsRead = 0;

            if (!ReadConsoleOutputCharacter(handler, sb, width, readCoord, out numCharsRead))
            {
                return((char)0);
            }
            else
            {
                return(sb.ToString()[0]);
            }
        }
Example #8
0
        public void MoveEnemy()
        {
            if (DateTime.Now.TimeOfDay.Subtract(timeSinceUpdate) > TimeSpan.FromSeconds(1))
            {
                timeSinceUpdate = DateTime.Now.TimeOfDay;
                EngineFunctions.COORD curPlayerPos = Game.player.location;

                // modify x position
                if (loc.X < curPlayerPos.X && loc.X < Console.WindowWidth - 3)
                {
                    if (!CheckCollision(FaceDirection.Right))
                    {
                        EngineFunctions.DrawToConsole(loc, ' ');
                        loc = new EngineFunctions.COORD((short)(loc.X + 1), loc.Y);
                    }
                }
                else if (loc.X > curPlayerPos.X && loc.X > 2)
                {
                    if (!CheckCollision(FaceDirection.Left))
                    {
                        EngineFunctions.DrawToConsole(loc, ' ');
                        loc = new EngineFunctions.COORD((short)(loc.X - 1), loc.Y);
                    }
                }

                // modify y position
                if (loc.Y < curPlayerPos.Y && loc.Y < Console.WindowHeight - 13)
                {
                    if (!CheckCollision(FaceDirection.Down))
                    {
                        EngineFunctions.DrawToConsole(loc, ' ');
                        loc = new EngineFunctions.COORD(loc.X, (short)(loc.Y + 1));
                    }
                }
                else if (loc.Y > curPlayerPos.Y && loc.Y > 2)
                {
                    if (!CheckCollision(FaceDirection.Up))
                    {
                        EngineFunctions.DrawToConsole(loc, ' ');
                        loc = new EngineFunctions.COORD(loc.X, (short)(loc.Y - 1));
                    }
                }
            }
            DrawEnemy();
        }
Example #9
0
        public void FindShopLocation()
        {
            EngineFunctions.CHAR_INFO[,] ar = EngineFunctions.screenBufferArray;
            bool locationFound = false;
            bool valid         = true;
            int  counter       = 0;

            while (!locationFound && counter < 20)
            {
                counter++;
                short xRand = (short)rand.Next(1, 76);
                short yRand = (short)rand.Next(1, 16);

                if (ar[yRand, xRand].AsciiChar != ' ')
                {
                    continue;
                }
                else
                {
                    for (short x = 0; x < 5; x++)
                    {
                        for (short y = 0; y < 4; y++)
                        {
                            if (ar[yRand + y, xRand + x].AsciiChar != ' ')
                            {
                                valid = false;
                            }
                        }
                    }
                    if (valid)
                    {
                        locationFound = true;
                        location      = new EngineFunctions.COORD(xRand, yRand);
                    }
                }
            }
            if (!locationFound)
            {
                IsShopVisible = false;
            }
        }
Example #10
0
        public void MoveToNextRoom(FaceDirection direction)
        {
            switch (direction)
            {
            default:
            case FaceDirection.Up:
                if (roomLocation.Y > 0)
                {
                    roomLocation = new EngineFunctions.COORD(roomLocation.X, (short)(roomLocation.Y - 1));
                }
                break;

            case FaceDirection.Down:
                if (roomLocation.Y < roomArray.GetLength(0))
                {
                    roomLocation = new EngineFunctions.COORD(roomLocation.X, (short)(roomLocation.Y + 1));
                }
                break;

            case FaceDirection.Left:
                if (roomLocation.X > 0)
                {
                    roomLocation = new EngineFunctions.COORD((short)(roomLocation.X - 1), roomLocation.Y);
                }
                break;

            case FaceDirection.Right:
                if (roomLocation.X < roomArray.GetLength(1))
                {
                    roomLocation = new EngineFunctions.COORD((short)(roomLocation.X + 1), roomLocation.Y);
                }
                break;
            }
            if (roomArray[roomLocation.Y, roomLocation.X] == null)
            {
                roomArray[roomLocation.Y, roomLocation.X] = new Room(roomByteArray[roomLocation.Y, roomLocation.X], true);
            }
        }
Example #11
0
        public void PlaceInNextRoom(FaceDirection exitDirection)
        {
            switch (exitDirection)
            {
            default:
            case FaceDirection.Up:
                location = new EngineFunctions.COORD(location.X, (short)(Console.WindowHeight - 10));
                break;

            case FaceDirection.Down:
                location = new EngineFunctions.COORD(location.X, (short)(0));
                break;

            case FaceDirection.Left:
                location = new EngineFunctions.COORD((short)(Console.WindowWidth - 1), location.Y);
                break;

            case FaceDirection.Right:
                location = new EngineFunctions.COORD(0, location.Y);
                break;
            }
            PlaceCharacterNewScreen();
        }
Example #12
0
 public void PlaceInMapAfterShop(EngineFunctions.COORD loc)
 {
     location = loc;
 }
Example #13
0
 public void UpdatePlayer(ref List <Enemy> e, out FaceDirection roomExit, List <FaceDirection> doors)
 {
     roomExit      = FaceDirection.noDir;
     enemiesInRoom = e;
     if (c == 'w')
     {
         curFacing = FaceDirection.Up;
         if (location.Y > 0)
         {
             if (!CheckCollision())
             {
                 location = new EngineFunctions.COORD(location.X, (short)(location.Y - 1));
                 if (location.Y == 0 && transition)
                 {
                     roomExit   = FaceDirection.Up;
                     transition = false;
                 }
                 else
                 {
                     transition = true;
                 }
             }
         }
     }
     if (c == 's')
     {
         curFacing = FaceDirection.Down;
         if (location.Y < Console.WindowHeight - 10)
         {
             if (!CheckCollision())
             {
                 location = new EngineFunctions.COORD(location.X, (short)(location.Y + 1));
                 if (location.Y == Console.WindowHeight - 10 && transition)
                 {
                     roomExit   = FaceDirection.Down;
                     transition = false;
                 }
                 else
                 {
                     transition = true;
                 }
             }
         }
     }
     if (c == 'a')
     {
         curFacing = FaceDirection.Left;
         if (location.X > 0)
         {
             if (!CheckCollision())
             {
                 location = new EngineFunctions.COORD((short)(location.X - 1), location.Y);
                 if (location.X == 0 && transition)
                 {
                     roomExit   = FaceDirection.Left;
                     transition = false;
                 }
                 else
                 {
                     transition = true;
                 }
             }
         }
     }
     if (c == 'd')
     {
         curFacing = FaceDirection.Right;
         if (location.X < Console.WindowWidth - 1)
         {
             if (!CheckCollision())
             {
                 location = new EngineFunctions.COORD((short)(location.X + 1), location.Y);
                 if (location.X == Console.WindowWidth - 1 && transition)
                 {
                     roomExit   = FaceDirection.Right;
                     transition = false;
                 }
                 else
                 {
                     transition = true;
                 }
             }
         }
     }
     if (c == 'q')
     {
         SwitchItem();
     }
     if (c == ' ')
     {
         if (Game.gameOver)
         {
             Game.ResetGame = true;
             Game.gameOver  = false;
             inputThread.Abort();
             inputThread.Join();
         }
         else
         {
             SwingSword = true;
         }
     }
     if ((int)(c) >= 49 && (int)(c) <= 52)
     {
         ShouldSave = true;
         SaveSlot   = (byte)(c - 49);
     }
     if (c == 'e')
     {
         if (location.X > Console.WindowWidth / 2 - 2 && location.X <= Console.WindowWidth / 2 + 2 &&
             location.Y == 1 && curFacing == FaceDirection.Up)
         {
             UseKey = true;
         }
         else if (location.X > Console.WindowWidth / 2 - 2 && location.X <= Console.WindowWidth / 2 + 2 &&
                  location.Y == (Console.WindowHeight - 11) && curFacing == FaceDirection.Down)
         {
             UseKey = true;
         }
         else if (location.Y > (Console.WindowHeight - 10) / 2 - 2 && location.Y <= (Console.WindowHeight - 10) / 2 + 2 &&
                  location.X == Console.WindowWidth - 1 && curFacing == FaceDirection.Right)
         {
             UseKey = true;
         }
         else if (location.Y > (Console.WindowHeight - 10) / 2 - 2 && location.Y <= (Console.WindowHeight - 10) / 2 + 2 &&
                  location.X == 1 && curFacing == FaceDirection.Left)
         {
             UseKey = true;
         }
         else
         {
             UseItem();
         }
     }
     e = enemiesInRoom;
     c = 'n';
 }
Example #14
0
 public Map()
 {
     roomLocation = new EngineFunctions.COORD(0, 0);
     ChangeMap();
 }
Example #15
0
        private List <Tuple <EngineFunctions.COORD, EngineFunctions.COORD> > FindDoor(EngineFunctions.COORD room)
        {
            List <Tuple <EngineFunctions.COORD, EngineFunctions.COORD> > l = new List <Tuple <EngineFunctions.COORD, EngineFunctions.COORD> >();

            foreach (Tuple <EngineFunctions.COORD, EngineFunctions.COORD> t in lockedDoors)
            {
                if ((t.Item1.X == room.X && t.Item1.Y == room.Y) ||
                    (t.Item2.X == room.X && t.Item2.Y == room.Y))
                {
                    l.Add(t);
                }
            }
            return(l);
        }
Example #16
0
 public Item(ItemType type, EngineFunctions.COORD loc)
 {
     Location = loc;
     IType    = type;
 }
Example #17
0
 public Map(EngineFunctions.COORD start)
 {
     roomLocation = start;
     ChangeMap();
 }
Example #18
0
 public MenuItem(string text, EngineFunctions.COORD position)
 {
     this.text     = text;
     this.position = position;
 }