Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading;
- using System.Collections;
- namespace _11.FallingRocksGame
- {
- class Rock
- {
- public int X, Y;
- public char symbol;
- public byte colorNumber;
- public void setPositions(int x,int y)
- {
- this.X = x;
- this.Y = y;
- }
- public void Falling()
- {
- this.Y++;
- }
- public Rock(int x, int y,char symbol, byte colorNumber)
- {
- this.colorNumber = colorNumber;
- this.symbol = symbol;
- this.X = x;
- this.Y = y;
- }
- }
- class FallingRocksGame
- {
- static void Main(string[] args)
- {
- double timer = 200;
- int gameLevel = 1;
- Random randomGenerator = new Random();
- char[] rockForms = {'^', '@', '*', '&', '+', '%', '$', '#', '!', '.', ';', '-'};
- int points = 0;
- Queue<Rock> RocksElements = new Queue<Rock>();
- ArrayList StricksRocksX = new ArrayList();
- int dwarfPositionX = Console.WindowWidth / 2;
- int dwarfPositionY = Console.WindowHeight - 1;
- int fallinLines = 0;
- int lastLevelLines = 0;
- bool endLevel = false;
- while(true)
- {
- points++;
- StricksRocksX.Clear();
- Console.ForegroundColor = (ConsoleColor)15;
- Console.SetCursorPosition(dwarfPositionX, dwarfPositionY);
- Console.WriteLine("(0)");
- if (fallinLines < Console.WindowHeight - 1)
- {
- for (int i = 0; i < gameLevel; i++)
- {
- RocksElements.Enqueue(new Rock(randomGenerator.Next(0, Console.WindowWidth - 1), 1,
- rockForms[randomGenerator.Next(0, rockForms.Length - 1)],(byte)randomGenerator.Next(1,15)));
- }
- fallinLines++;
- }
- foreach (Rock rock in RocksElements)
- {
- if (rock.Y >= Console.WindowHeight - 1)
- {
- rock.setPositions(randomGenerator.Next(0, Console.WindowWidth - 1), 1);
- }
- else
- {
- rock.Falling();
- }
- if (!endLevel || rock.Y >= lastLevelLines)
- {
- Console.SetCursorPosition(rock.X, rock.Y);
- Console.ForegroundColor = (ConsoleColor)rock.colorNumber;
- Console.Write(rock.symbol);
- }
- if (rock.Y == dwarfPositionY)
- {
- StricksRocksX.Add(rock.X);
- }
- }
- int keyClick = 0;
- for (int i = 0; i < 15; i++)
- {
- if (Console.KeyAvailable)
- {
- ConsoleKeyInfo pressedKey = Console.ReadKey();
- if (pressedKey.Key == ConsoleKey.RightArrow && keyClick < 7)
- {
- dwarfPositionX++;
- keyClick++;
- }
- if (pressedKey.Key == ConsoleKey.LeftArrow && keyClick < 7)
- {
- dwarfPositionX--;
- keyClick++;
- }
- if (pressedKey.Key == ConsoleKey.Spacebar)
- {
- Console.Clear();
- Console.ForegroundColor = ConsoleColor.White;
- Console.WriteLine("Your points is {0}", points);
- return;
- }
- }
- }
- foreach (int strick in StricksRocksX)
- {
- if (strick >= dwarfPositionX && strick <= dwarfPositionX + 2)
- {
- Console.Clear();
- Console.ForegroundColor = ConsoleColor.White;
- Console.WriteLine("Your points is {0} in level {1}", points,gameLevel);
- return;
- }
- }
- if (dwarfPositionX >= Console.WindowWidth - 2)
- {
- dwarfPositionX = 2;
- }
- if (dwarfPositionX <= 1)
- {
- dwarfPositionX = Console.WindowWidth - 3;
- }
- Thread.Sleep((int)timer);
- Console.Clear();
- timer -= 0.5;
- if (timer < 100)
- {
- lastLevelLines++;
- endLevel = true;
- }
- if (lastLevelLines >= Console.WindowHeight - 1)
- {
- endLevel = false;
- lastLevelLines = 0;
- RocksElements.Clear();
- fallinLines = 0;
- gameLevel++;
- timer = 200;
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement