Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Threading;
- using System.Linq;
- using System.Collections.Generic;
- class Program
- {
- struct Player
- {
- public int x;
- public int y;
- public string c;
- public ConsoleColor color;
- }
- struct Text
- {
- public int x;
- public int y;
- public string c;
- public ConsoleColor color;
- }
- struct Rocks
- {
- public int x;
- public int y;
- public string c;
- public ConsoleColor color;
- }
- static void PrintOnPosition(int x, int y, string c, ConsoleColor color = ConsoleColor.Gray)
- {
- Console.SetCursorPosition(x, y);
- Console.ForegroundColor = color;
- Console.WriteLine(c);
- }
- static void TextPrinting(int x, int y, string c, ConsoleColor color = ConsoleColor.Gray)
- {
- Console.SetCursorPosition(x, y);
- Console.ForegroundColor = color;
- Console.WriteLine(c);
- }
- static void Main()
- {
- int playField = 20;
- int score = 0;
- int bonusScore = 0;
- Console.BufferHeight = Console.WindowHeight = 30;
- Console.BufferWidth = Console.WindowWidth = 30;
- Player PlayerInfo = new Player();
- PlayerInfo.x = 10;
- PlayerInfo.y = 20;
- PlayerInfo.c = "_0_";
- Random randomGenerator = new Random();
- switch (randomGenerator.Next(0, 5))
- {
- case 0: PlayerInfo.color = ConsoleColor.Gray;
- break;
- case 1: PlayerInfo.color = ConsoleColor.Green;
- break;
- case 2: PlayerInfo.color = ConsoleColor.Yellow;
- break;
- case 3: PlayerInfo.color = ConsoleColor.Blue;
- break;
- case 4: PlayerInfo.color = ConsoleColor.Red;
- break;
- case 5: PlayerInfo.color = ConsoleColor.White;
- break;
- }
- List<Rocks> rock = new List<Rocks>();
- // kakuvto kamuk hvane6 takuv cvqt da ti stava 4ove4eto i samo ot tezi cvetove kato subira6 da ti dava to4ki.
- while (true)
- {
- Rocks newRock = new Rocks();
- newRock.x = randomGenerator.Next(0, playField);
- newRock.y = 0;
- switch (randomGenerator.Next(0, 5))
- {
- case 0: newRock.color = ConsoleColor.Gray;
- break;
- case 1: newRock.color = ConsoleColor.Green;
- break;
- case 2: newRock.color = ConsoleColor.Yellow;
- break;
- case 3: newRock.color = ConsoleColor.Blue;
- break;
- case 4: newRock.color = ConsoleColor.Red;
- break;
- case 5: newRock.color = ConsoleColor.White;
- break;
- }
- switch (randomGenerator.Next(0, 11))
- {
- case 0: newRock.c = "^";
- break;
- case 1: newRock.c = "@";
- break;
- case 2: newRock.c = "*";
- break;
- case 3: newRock.c = "&";
- break;
- case 4: newRock.c = "+";
- break;
- case 5: newRock.c = "%";
- break;
- case 6: newRock.c = "$";
- break;
- case 7: newRock.c = "#";
- break;
- case 8: newRock.c = "!";
- break;
- case 9: newRock.c = ".";
- break;
- case 10: newRock.c = ";";
- break;
- }
- rock.Add(newRock);
- if (Console.KeyAvailable)
- {
- ConsoleKeyInfo pressedKey = Console.ReadKey(true);
- while (Console.KeyAvailable)
- {
- Console.ReadKey();
- }
- if (pressedKey.Key == ConsoleKey.LeftArrow)
- {
- if (PlayerInfo.x - 1 >= 0)
- {
- PlayerInfo.x--;
- }
- }
- else if (pressedKey.Key == ConsoleKey.RightArrow)
- {
- if (PlayerInfo.x + 1 < playField - 1)
- {
- PlayerInfo.x++;
- }
- }
- }
- //Moving Rocks
- 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.c = oldRocks.c;
- newRocks.color = oldRocks.color;
- if (newRocks.y == PlayerInfo.y + 1)
- {
- score++;
- }
- if (newRocks.y == PlayerInfo.y && newRocks.color == PlayerInfo.color && newRocks.x == PlayerInfo.x + 1)
- {
- Console.WriteLine();
- PrintOnPosition(1, 2, "Bonus Won!!", ConsoleColor.Red);
- bonusScore++;
- }
- else if (newRocks.y == PlayerInfo.y && newRocks.x == PlayerInfo.x + 1)
- {
- PrintOnPosition(1, 2, "Game Over!!", ConsoleColor.Red);
- Console.WriteLine();
- return;
- }
- if (newRocks.y <= PlayerInfo.y + 1)
- {
- newList.Add(newRocks);
- }
- }
- rock = newList;
- Console.Clear();
- //Redraw Playfield
- PrintOnPosition(PlayerInfo.x, PlayerInfo.y, PlayerInfo.c, PlayerInfo.color);
- foreach (var rocks in rock)
- {
- PrintOnPosition(rocks.x, rocks.y, rocks.c, rocks.color);
- }
- //Spawn text
- Text TextInfo = new Text();
- TextInfo.x = 1;
- TextInfo.y = 23;
- TextInfo.c = "Your score:"+score+" Bonus Score:"+bonusScore;
- TextInfo.color = ConsoleColor.Blue;
- TextPrinting(TextInfo.x, TextInfo.y, TextInfo.c, TextInfo.color);
- //Slow down moving rocks
- Thread.Sleep(200);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement