Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Threading.Tasks;
- namespace Block
- {
- public class Program
- {
- public static int resV = 20;
- public static int resH = 100;
- static void Main(string[] args)
- {
- char[,] area = new char[resV, resH];
- bool[,] lleno = new bool[resV, resH];
- List<Bloque> bloques = new List<Bloque>();
- bloques.Add(new Bloque());
- bool exit = false;
- bool der = false;
- bool izq = false;
- Task.Factory.StartNew(() =>
- {
- ConsoleKey ck = ConsoleKey.Spacebar;
- while (true)
- {
- izq = false;
- der = false;
- if (ck == ConsoleKey.P) exit = true;
- if (ck == ConsoleKey.RightArrow) der = true;
- if (ck == ConsoleKey.LeftArrow) izq = true;
- ck = Console.ReadKey(true).Key;
- }
- });
- while (!exit)
- {
- for (int i = 0; i < resV; i++)
- for (int j = 0; j < resH; j++)
- area[i, j] = ' ';
- Bloque ultimoB = bloques[bloques.Count - 1];
- if (ultimoB.Fin)
- {
- bloques.Add(new Bloque());
- }
- else
- {
- for (int i = 0; i < bloques.Count - 1; i++)
- {
- if (ultimoB.Colision(bloques[i])) ultimoB.Fin = true;
- }
- if (!ultimoB.Fin)
- {
- ultimoB.Bajar();
- if (izq)
- {
- ultimoB.Izq();
- izq = false;
- }
- else if (der)
- {
- ultimoB.Der();
- der = false;
- }
- }/*
- else // Se para el bloque
- {
- lleno[ultimoB.Y,ultimoB.X] = true;
- int eliminar = -1;
- for(int fila = 0; fila < resV; fila++)
- {
- if(lleno[fila,0]&& lleno[fila, 1] && lleno[fila, 2] && lleno[fila, 3] && lleno[fila, 4] &&
- lleno[fila, 5] && lleno[fila, 6] && lleno[fila, 7] && lleno[fila, 8] && lleno[fila, 9])
- {
- eliminar = fila;
- }
- }
- if (eliminar>-1)
- {
- foreach(Bloque b in bloques)
- {
- if (b.X == 19)
- {
- bloques.Remove(b);
- b.Dispose();
- }
- }
- }
- }*/
- }
- foreach (Bloque b in bloques)
- {
- area[b.Y, b.X] = '█';
- }
- string sc = "";
- for (int i = 0; i < resV; i++)
- {
- for (int j = 0; j < resH; j++)
- {
- sc += area[i, j];
- }
- sc += "\n";
- }
- Console.SetCursorPosition(0, 0);
- Console.WriteLine(sc);
- for(int i=0; i<resH; i++)
- {
- Console.Write("-");
- }
- //System.Threading.Thread.Sleep(1);
- }
- }
- }
- class Bloque : IDisposable
- {
- public int X { get; set; }
- public int Y { get; set; }
- public bool Fin { get; set; }
- public Bloque()
- {
- Random rnd = new Random();
- X = rnd.Next(Program.resH);
- Y = 0;
- Fin = false;
- }
- public void Bajar()
- {
- if (Y == Program.resV-1) Fin = true;
- else Y += 1;
- }
- public void Der()
- {
- if (X< Program.resH-1) X += 1;
- }
- public void Izq()
- {
- if (X>0) X -= 1;
- }
- public bool Colision(Bloque otro)
- {
- return otro.X == this.X && otro.Y == this.Y + 1;
- }
- public void Dispose()
- {
- }
- }
- }
Add Comment
Please, Sign In to add comment