Пример #1
0
        public bool IsHittedBy(Rocks rock)
        {
            if (this.XPos == rock.XPos && this.YPos + 1 == rock.YPos)
            {
                return true;
            }

            return false;
        }
Пример #2
0
        static Rocks GenerateRocks()
        {
            rockPositionX = randomNumber.Next(0, Console.WindowWidth);
            rockPositionY = 0;

            char rockType = rockTypes[randomNumber.Next(0, rockTypes.Length)];

            Rocks rock = new Rocks(rockType, rockPositionX, rockPositionY);

            return(rock);
        }
Пример #3
0
        static void Main()
        {
            int playfiledwidth = 61;
            int score          = 0;

            Console.BufferHeight = Console.WindowHeight = 20;
            Console.BufferWidth  = Console.WindowWidth = 61;
            Rocks dwarf = new Rocks();

            dwarf.x     = 30;
            dwarf.y     = Console.WindowHeight - 1;
            dwarf.ch    = "(.)Y(.)";
            dwarf.color = ConsoleColor.Magenta;

            List <Rocks> rock            = new List <Rocks>();
            Random       randomGenerator = new Random();

            while (true)
            {
                {
                    Rocks newRock = new Rocks();
                    switch (randomGenerator.Next(1, 11))
                    {
                    case 0: newRock.color = ConsoleColor.DarkRed;
                        break;

                    case 1: newRock.color = ConsoleColor.Gray;
                        break;

                    case 2: newRock.color = ConsoleColor.Green;
                        break;

                    case 3: newRock.color = ConsoleColor.Yellow;
                        break;

                    case 4: newRock.color = ConsoleColor.DarkGray;
                        break;

                    case 5: newRock.color = ConsoleColor.Blue;
                        break;

                    case 6: newRock.color = ConsoleColor.DarkBlue;
                        break;

                    case 7: newRock.color = ConsoleColor.DarkGreen;
                        break;

                    case 8: newRock.color = ConsoleColor.DarkRed;
                        break;

                    case 9: newRock.color = ConsoleColor.White;
                        break;

                    case 10: newRock.color = ConsoleColor.DarkCyan;
                        break;
                    }
                    newRock.x = randomGenerator.Next(0, playfiledwidth);
                    newRock.y = 2;
                    switch (randomGenerator.Next(1, 11))
                    {
                    case 0: newRock.ch = "^";
                        break;

                    case 1: newRock.ch = "@";
                        break;

                    case 2: newRock.ch = "*";
                        break;

                    case 3: newRock.ch = "&";
                        break;

                    case 4: newRock.ch = "+";
                        break;

                    case 5: newRock.ch = "%";
                        break;

                    case 6: newRock.ch = "$";
                        break;

                    case 7: newRock.ch = "#";
                        break;

                    case 8: newRock.ch = "!";
                        break;

                    case 9: newRock.ch = ".";
                        break;

                    case 10: newRock.ch = ";";
                        break;
                    }
                    rock.Add(newRock);
                }
                //---------------------------------------------------
                if (Console.KeyAvailable)
                {
                    ConsoleKeyInfo pressedKey = Console.ReadKey(true);
                    while (Console.KeyAvailable)
                    {
                        Console.ReadKey();
                    }
                    if (pressedKey.Key == ConsoleKey.LeftArrow)
                    {
                        if (dwarf.x >= 1)
                        {
                            dwarf.x = dwarf.x - 1;
                        }
                    }
                    else if (pressedKey.Key == ConsoleKey.RightArrow)
                    {
                        if (dwarf.x <= 59 - dwarf.ch.Length)
                        {
                            dwarf.x = dwarf.x + 1;
                        }
                    }
                }
                List <Rocks> newList = new List <Rocks>();
                for (int i = 0; i < rock.Count; i++)
                {
                    Rocks oldRocks = rock[i];
                    Rocks newRocks = new Rocks();
                    newRocks.x     = oldRocks.x;
                    newRocks.y     = oldRocks.y + 1;
                    newRocks.ch    = oldRocks.ch;
                    newRocks.color = oldRocks.color;

                    if (newRocks.y == dwarf.y && newRocks.x == dwarf.x + 3)
                    {
                        Position(dwarf.x + 2, dwarf.y, "_!_", ConsoleColor.Red);
                        StringPosition(1, 2, "Game Over!!", ConsoleColor.Red);
                        Console.WriteLine();
                        return;
                    }
                    if (newRocks.y < Console.WindowHeight)
                    {
                        newList.Add(newRocks);
                    }
                }
                rock = newList;
                Console.Clear();
                Position(dwarf.x, dwarf.y, dwarf.ch, dwarf.color);
                foreach (var rocks in rock)
                {
                    Position(rocks.x, rocks.y, rocks.ch, rocks.color);
                }
                StringPosition(1, 1, "Score:" + score, ConsoleColor.Gray);
                Thread.Sleep(150);
                score++;
            }
        }
Пример #4
0
        // V6 Supercharged
        private static void Engine(List<Rocks> rocks, Dwarf dwarf)
        {
            while (lives > 0)
            {
                // Control the asteroid creation
                Rocks newRock = new Rocks(UI.PickUpChar(), ConsoleColor.Cyan);
                rocks.Add(newRock);

                // Move the asteroids
                for (int index = 0; index < rocks.Count; index++)
                {
                    rocks[index].Clear();
                    rocks[index].Move();
                }

                Collisions(rocks, dwarf);
                Control(dwarf);
                dwarf.Draw();

                UI.DrawInterface(lives, score); // draw score and lives in separated cells

                // Slow down the game
                Thread.Sleep(gameSpeed);
            }
        }
        static Rocks GenerateRocks()
        {
            rockPositionX = randomNumber.Next(0, Console.WindowWidth);
            rockPositionY = 0;

            char rockType = rockTypes[randomNumber.Next(0, rockTypes.Length)];

            Rocks rock = new Rocks(rockType, rockPositionX, rockPositionY);
            return rock;
        }