Exemple #1
0
        public Program()
        {
            // Initialise player's location
            var r = new Random();

            playerLocation = new UPoint((uint)r.Next(0xffff), (uint)r.Next(0xffff));
            state          = State.Galaxy;
        }
Exemple #2
0
        public Zone(UPoint at)
        {
            this.at = at;
            // The seed is generated by combining the lowest 2 bytes of x and y into 1 unit.
            // This means that the universe will repeat every 65536 x and y b
            lehmer = new LehmerPRNG((at.X & 0xFFFF) << 16 | (at.Y & 0xFFFF));

            var isStar = lehmer.NextBool(CHANCE_OF_STAR);

            if (!isStar)
            {
                return;
            }

            this.Star = new Star(lehmer);
        }
Exemple #3
0
        public void RenderGalaxy()
        {
            var windowSize = new UPoint(80, 30);

            var windowOrigin = new UPoint(
                playerLocation.X - (windowSize.X / 2),
                playerLocation.Y - (windowSize.Y / 2));

            Console.WriteLine("Navigate the galaxy using the cursor keys.");
            Console.WriteLine("Press Enter to view system details.");
            Console.WriteLine();
            Console.WriteLine($"Current Location: X:{playerLocation.X}, Y:{playerLocation.Y}");
            Console.WriteLine();

            for (uint y = 0; y < windowSize.Y; y++)
            {
                for (uint x = 0; x < windowSize.X; x++)
                {
                    var currentUPoint = new UPoint(
                        x + windowOrigin.X,
                        y + windowOrigin.Y);
                    var zone = new Zone(currentUPoint);

                    if (currentUPoint.X == playerLocation.X &&
                        currentUPoint.Y == playerLocation.Y)
                    {
                        Console.Write(zone.HasStar ? "@" : "@");
                    }
                    else
                    {
                        Console.Write(zone.HasStar  ? "*" : " ");
                    }
                }
                Console.WriteLine();
            }
            Console.WriteLine();
            var current = new Zone(playerLocation);

            if (current.HasStar)
            {
                Console.WriteLine(current.Star !);
                if (current.Star !.HasPlanets)
                {
                    Console.WriteLine(" - Planetary bodies found.");
                }
            }
        }
Exemple #4
0
        private void HandleUserInput()
        {
            var key = Console.ReadKey();

            if (state == State.Galaxy)
            {
                switch (key.Key)
                {
                case ConsoleKey.LeftArrow:
                    playerLocation = new UPoint(playerLocation.X - 1, playerLocation.Y);
                    break;

                case ConsoleKey.RightArrow:
                    playerLocation = new UPoint(playerLocation.X + 1, playerLocation.Y);
                    break;

                case ConsoleKey.UpArrow:
                    playerLocation = new UPoint(playerLocation.X, playerLocation.Y - 1);
                    break;

                case ConsoleKey.DownArrow:
                    playerLocation = new UPoint(playerLocation.X, playerLocation.Y + 1);
                    break;

                case ConsoleKey.Enter:
                    state = State.System;
                    break;

                default:
                    break;
                }
            }
            else if (state == State.System)
            {
                if (key.Key == ConsoleKey.Enter)
                {
                    state = State.Galaxy;
                }
            }
        }