예제 #1
0
        static void GenerateLineOfRocks()
        {
            char[] rocks = { '^', '@', '*', '&', '+', '%', '$', '#', '!', '.', ';' };
            int sizeOfRocks, posOfRock;
            int numOfRocks = rnd.Next(1, difficulty);

            for (int i = 0; i < numOfRocks; i++)
            {
                Stone stone = new Stone();
                sizeOfRocks = rnd.Next(1, 4);
                stone.color = rnd.Next(0, 4);
                stone.sign = rocks[rnd.Next(0, rocks.GetLength(0) - 1)];
                posOfRock = rnd.Next(0, 77);

                for (int j = 0; j < sizeOfRocks; j++)
                {
                    array[0, posOfRock] = stone;
                    writeStoneAtPos(stone, 0, posOfRock);
                    posOfRock++;
                }
            }
        }
예제 #2
0
        static int Game(int rockCount, int sleepTime)
        {
            char[] rockSymbols = new char[10] { '#', '+', '&', '!', '=', '$', '~', '^', '?', '%' }; // symbols for the rocks, can be changed
            sbyte rocksSpeed = 1;
            double score = 0;
            int finalScore = 0;
            Random randomGenerator = new Random();
            Stone[] rocks = new Stone[rockCount];

            Stone dwarf = new Stone();
            dwarf.X = Console.WindowWidth / 2;
            dwarf.Y = Console.WindowHeight - 1;

            for (int i = 0; i < rockCount; i++)
            {
                rocks[i].X = randomGenerator.Next(1, (Console.WindowWidth - 1));
                rocks[i].Y = randomGenerator.Next(1, (Console.WindowHeight - 5));
                rocks[i].Color = (ConsoleColor)randomGenerator.Next(10, 16);
                rocks[i].Symbol = rockSymbols[randomGenerator.Next(1, rockSymbols.Length)];
            }

            while (true)
            {
                if (rocksSpeed % 23 == 0)
                {
                    for (int i = 0; i < rockCount; i++)
                    {
                        if (rocks[i].Y == (Console.WindowHeight - 1))
                        {
                            Console.SetCursorPosition(rocks[i].X, rocks[i].Y);
                            Console.Write(" ");
                            rocks[i].X = randomGenerator.Next(1, (Console.WindowWidth - 1));
                            rocks[i].Y = randomGenerator.Next(0, 3);
                            rocks[i].Color = (ConsoleColor)randomGenerator.Next(10, 16);
                            rocks[i].Symbol = rockSymbols[randomGenerator.Next(1, rockSymbols.Length)];
                        }
                        else
                        {
                            Console.SetCursorPosition(rocks[i].X, rocks[i].Y);
                            Console.Write(" ");
                            rocks[i].Y++;
                        }

                        Console.SetCursorPosition(rocks[i].X, rocks[i].Y);
                        Console.ForegroundColor = rocks[i].Color;
                        Console.Write(rocks[i].Symbol);
                    }
                }

                if (Console.KeyAvailable)
                {
                    Console.SetCursorPosition(dwarf.X - 1, dwarf.Y);
                    Console.Write("   ");
                    ConsoleKeyInfo pressedKey = Console.ReadKey();
                    if (pressedKey.Key == ConsoleKey.RightArrow)
                        dwarf.X++;
                    if (pressedKey.Key == ConsoleKey.LeftArrow)
                        dwarf.X--;
                }

                if ((dwarf.X == Console.WindowWidth - 2) || (dwarf.X < 1))
                {
                    return (finalScore * 10);
                }

                for (int i = 0; i < rockCount; i++)
                {
                    if (((dwarf.X == rocks[i].X) && (dwarf.Y == rocks[i].Y)) ||
                        ((dwarf.X == rocks[i].X - 1) && (dwarf.Y == rocks[i].Y)) ||
                        ((dwarf.X == rocks[i].X + 1) && (dwarf.Y == rocks[i].Y)))
                    {
                        Console.ForegroundColor = ConsoleColor.Red;
                        Console.SetCursorPosition(dwarf.X - 1, dwarf.Y);
                        Console.Write("\\@/");
                        return (finalScore * 10);
                    }
                }

                Console.ForegroundColor = ConsoleColor.Cyan;
                Console.SetCursorPosition(dwarf.X - 1, dwarf.Y);
                Console.Write("\\☺/");

                Thread.Sleep(sleepTime);
                rocksSpeed++;
                score += 0.02;
                finalScore = (int)score;
            }
        }
예제 #3
0
        static void writeStoneAtPos(Stone stone, int x, int y)
        {
            try
            {
                if (stone.color == 0)
                    Console.ForegroundColor = ConsoleColor.White;
                else if (stone.color == 1)
                    Console.ForegroundColor = ConsoleColor.Yellow;
                else if (stone.color == 2)
                    Console.ForegroundColor = ConsoleColor.Gray;
                else if (stone.color == 3)
                    Console.ForegroundColor = ConsoleColor.Cyan;
                else if (stone.color == 4)
                    Console.ForegroundColor = ConsoleColor.Green;

                Console.SetCursorPosition(y, x);
                Console.Write(stone.sign);
            }
            catch (ArgumentOutOfRangeException e)
            {
                Console.Clear();
                Console.WriteLine(e.Message);
            }
        }
예제 #4
0
        static void MoveRocksDown()
        {
            Stone[,] temp = new Stone[25, 80];

            for (int i = 0; i < array.GetLength(0); i++)
                for (int j = 0; j < array.GetLength(1); j++)
                    if (i != 24)
                        temp[i + 1, j] = array[i, j];

            array = temp;

            Console.MoveBufferArea(0, 0, y, 24, 0, 1); //Move rocks down a line
            Console.MoveBufferArea(y + 3, 0, 80 - (y + 3), 24, y + 3, 1);
            Console.MoveBufferArea(y, 0, 3, 23, y, 1);
        }