Not a member of Pastebin yet?
                        Sign Up,
                        it unlocks many cool features!                    
                - using System;
 - using System.Collections.Generic;
 - using System.IO;
 - using System.Linq;
 - using System.Text;
 - using System.Threading;
 - using System.Threading.Tasks;
 - class EscapeFloor
 - {
 - struct Player
 - {
 - public int X1;
 - public int X2;
 - public int Y1;
 - public int Y2;
 - public int Points;
 - public string[] Skin;
 - }
 - struct PowerUps
 - {
 - public string Symbol;
 - public int X;
 - public int Y;
 - public ConsoleColor Color;
 - public PowerUps(string symbol, int x, int y, ConsoleColor color)
 - {
 - this.Symbol = symbol;
 - this.X = x;
 - this.Y = y;
 - this.Color = color;
 - }
 - }
 - static void Main()
 - {
 - int numberOfFloors = 30;
 - Console.BufferHeight = Console.WindowHeight = numberOfFloors;
 - Console.BufferWidth = Console.WindowWidth = 50;
 - Random rng = new Random();
 - StringBuilder floor = new StringBuilder();
 - Player player1 = new Player();
 - string scoreFileDir = Directory.GetCurrentDirectory() + @"\score.txt";
 - string[] floors = new string[Console.WindowHeight + 1];
 - int floorsLength = Console.BufferWidth - 20;
 - int emptyRows = 3;
 - PowerUps[] powerUp = new PowerUps[3];
 - powerUp[0] = new PowerUps("@", 1, 1, ConsoleColor.Green);
 - powerUp[1] = new PowerUps("$", 1, 1, ConsoleColor.Yellow);
 - powerUp[2] = new PowerUps("!", 1, 1, ConsoleColor.Red);
 - int fallingCounter = 0;
 - bool hasFallen = false;
 - bool isGameOver = false;
 - int[] holePosition = new int[numberOfFloors];
 - int[,] playfield = new int[Console.BufferHeight, Console.BufferWidth - 20];
 - string[] difficulty = { "Easy", "Medium", "Hard" };
 - string[] skin = { "_O_", " | ", @"/ \" };
 - player1.Skin = skin;
 - int holeWidth = 8;
 - int holeX = 0;
 - int floorsCounter = 0;
 - int levelSpeed = 350;
 - int currentPlayerRow = 0;
 - /**/
 - player1.X1 = playfield.GetLength(1) / 2; //start at the horizontal center of the playfield
 - player1.X2 = player1.X1 + player1.Skin.Length - 1;
 - player1.Y1 = playfield.GetLength(0) - 15;
 - player1.Y2 = player1.Y1 + player1.Skin.Length - 1;
 - /**/
 - for (int i = 0; i < playfield.GetLength(0); i++)
 - {
 - Console.SetCursorPosition(playfield.GetLength(1), i);
 - Console.Write("|");
 - }
 - while (!isGameOver)
 - {
 - for (int i = 1; i < player1.Skin.Length; i++)
 - {
 - for (int j = 0; j < player1.Skin.Length; j++)
 - {
 - playfield[player1.Y1 + i, player1.X1 + j] = 2;
 - }
 - }
 - //row generator
 - if (floorsCounter % 4 == 0)
 - {
 - holeX = rng.Next(0, playfield.GetLength(1) - 5);
 - for (int i = 0; i < playfield.GetLength(1); i++)
 - {
 - if (i >= holeX && i < holeX + holeWidth)
 - {
 - playfield[playfield.GetLength(0) - 1, i] = 3;
 - }
 - else
 - {
 - playfield[playfield.GetLength(0) - 1, i] = 1;
 - }
 - }
 - floorsCounter = 0;
 - }
 - //rows moving
 - for (int Y = 0; Y < playfield.GetLength(0); Y++)
 - {
 - for (int X = 0; X < playfield.GetLength(1); X++)
 - {
 - //destroying the row when it reaches the top
 - if (playfield[0, X] != 0)
 - {
 - for (int i = 0; i < playfield.GetLength(1); i++)
 - {
 - playfield[0, X] = 0;
 - Console.SetCursorPosition(X, 0);
 - Console.Write(" ");
 - }
 - }
 - if (playfield[Y, X] == 3)
 - {
 - playfield[Y - 1, X] = 3;
 - playfield[Y, X] = 0;
 - }
 - if (playfield[Y, X] == 1)
 - {
 - Console.SetCursorPosition(X, Y - 1);
 - Console.Write("=");
 - playfield[Y - 1, X] = 1;
 - Console.SetCursorPosition(X, Y);
 - Console.Write(" ");
 - playfield[Y, X] = 0;
 - //print character
 - PrintCharacter(player1);
 - }
 - if (playfield[Y, X] == 0)
 - {
 - Console.SetCursorPosition(X, Y);
 - Console.Write(" ");
 - }
 - }
 - }
 - floorsCounter++;
 - Thread.Sleep(levelSpeed);
 - //move through holes
 - for (int i = 0; i < player1.Skin.Length; i++)
 - {
 - if (playfield[player1.Y2 + 1, player1.X1 + i] == 1 && player1.Y2 < 26)
 - {
 - for (int j = 0; j < player1.Skin[0].Length; j++)
 - {
 - Console.SetCursorPosition(player1.X1 + j, player1.Y1 - 1);
 - Console.Write(" ");
 - }
 - player1.Y1--;
 - break;
 - }
 - else if (playfield[player1.Y2 + 1, player1.X1 + i] != 1 && player1.Y2 < 26)
 - {
 - for (int j = 0; j < player1.Skin.Length; j++)
 - {
 - playfield[player1.Y1, player1.X1 + j] = 0;
 - }
 - player1.Y1++;
 - break;
 - }
 - }
 - player1.Y2 = player1.Y1 + 2;
 - if (playfield[player1.Y2 + 1, player1.X1] == 3 && playfield[player1.Y2 + 1, player1.X2] == 3)
 - {
 - player1.Points = player1.Points + 20;
 - }
 - if (Console.KeyAvailable == true)
 - {
 - ConsoleKeyInfo pressedKey = Console.ReadKey(true);
 - while (Console.KeyAvailable) Console.ReadKey(true);
 - if (pressedKey.Key == ConsoleKey.LeftArrow)
 - {
 - //boundaries
 - if (player1.X1 - 1 >= 0 && playfield[player1.Y2 - 1, player1.X1 - 1] == 0)
 - {
 - player1.X1--;
 - player1.X2 = player1.X1 + player1.Skin.Length - 1;
 - for (int i = 0; i < player1.Skin.Length; i++) //extract to clear left or right side
 - { //extract to clear left or right side
 - Console.SetCursorPosition(player1.X1, player1.Y1 + i); //extract to clear left or right side
 - Console.Write(player1.Skin[i]); //extract to clear left or right side
 - Console.SetCursorPosition(player1.X2, player1.Y1 + i); //extract to clear left or right side
 - Console.Write(" "); //extract to clear left or right side
 - playfield[player1.Y1 + i, player1.X2 + 1] = 0;
 - }
 - }
 - }
 - else if (pressedKey.Key == ConsoleKey.RightArrow)
 - {
 - //boundaries
 - if (player1.X2 + 1 != playfield.GetLength(1) && playfield[player1.Y2 - 1, player1.X2 + 1] == 0)
 - {
 - player1.X1++;
 - player1.X2 = player1.X1 + player1.Skin.Length - 1;
 - for (int i = 0; i < player1.Skin.Length; i++)
 - {
 - Console.SetCursorPosition(player1.X1, player1.Y1 + i);
 - Console.Write(player1.Skin[i]);
 - Console.SetCursorPosition(player1.X1 , player1.Y1 + i);
 - Console.Write(" ");
 - playfield[player1.Y1 + i, player1.X1 - 1] = 0;
 - }
 - }
 - }
 - }
 - for (int i = 0; i < playfield.GetLength(0); i++)
 - {
 - Console.SetCursorPosition(playfield.GetLength(0), i);
 - Console.ForegroundColor = ConsoleColor.White;
 - Console.Write("|");
 - }
 - Console.SetCursorPosition(playfield.GetLength(1) + 2, 5); //row 5
 - Console.Write("Score: {0}", player1.Points);
 - Console.SetCursorPosition(playfield.GetLength(1) + 2, 15); //row 15
 - Console.Write("Speed: {0}", levelSpeed);
 - if (player1.Points < 200)
 - {
 - Console.SetCursorPosition(playfield.GetLength(1) + 2, 10); //row 10
 - Console.ForegroundColor = ConsoleColor.Green;
 - Console.Write("Difficulty: {0} ", difficulty[0]);
 - Console.ResetColor();
 - }
 - else if (player1.Points <= 400)
 - {
 - levelSpeed = 12;
 - holeWidth = 5;
 - Console.SetCursorPosition(playfield.GetLength(1) + 2, 10); //row 10
 - Console.ForegroundColor = ConsoleColor.Yellow;
 - Console.Write("Difficulty: {0} ", difficulty[1]);
 - Console.ResetColor();
 - }
 - else if (player1.Points >= 400)
 - {
 - levelSpeed = 100;
 - holeWidth = 3;
 - Console.SetCursorPosition(playfield.GetLength(1) + 2, 10); //row 10
 - Console.ForegroundColor = ConsoleColor.Red;
 - Console.Write("Difficulty: {0} ", difficulty[2]);
 - Console.ResetColor();
 - }
 - if (player1.Y1 == 0)
 - {
 - isGameOver = true;
 - }
 - player1.Points++;
 - }/**/
 - Console.Clear();
 - Console.WriteLine("Game Over!");
 - Console.WriteLine("Your score is: {0}", player1.Points);
 - Console.Write("Your name: ");
 - string name = Console.ReadLine();
 - string score = player1.Points.ToString() + " - " + name;
 - using (StreamWriter w = File.AppendText(scoreFileDir))
 - {
 - w.WriteLine(score);
 - }
 - Thread.Sleep(2000);
 - }
 - private static void PrintCharacter(Player player1)
 - {
 - for (int j = 0; j < player1.Skin.Length; j++)
 - {
 - Console.SetCursorPosition(player1.X1, player1.Y1 + j);
 - Console.Write(player1.Skin[j]);
 - }
 - }
 - }
 
Advertisement
 
                    Add Comment                
                
                        Please, Sign In to add comment