Skip to content

Instantly share code, notes, and snippets.

@Dr4g0
Last active December 19, 2015 19:19
Show Gist options
  • Save Dr4g0/6005773 to your computer and use it in GitHub Desktop.
Save Dr4g0/6005773 to your computer and use it in GitHub Desktop.
using System;
using System.Text;
using System.Threading;
class ConsoleGame
{
static Random randomPosition = new Random();
static char[,] matrix;
static void Main()
{
//Console.BackgroundColor = ConsoleColor.Black;
//Console.ForegroundColor = ConsoleColor.Gray;
//Console.Clear();
Console.OutputEncoding = Encoding.Unicode;
Console.CursorVisible = false;
int windowHeight = Console.BufferHeight = Console.WindowHeight = 30;
int playfield = windowHeight - 7; //last 10 rows for score, lives, bonuses, etc.
int windowWidth = Console.BufferWidth = Console.WindowWidth = 50;
Console.SetCursorPosition(0, playfield);
Console.WriteLine(new String('═', windowWidth));
matrix = new char[playfield, windowWidth];
GenerateRightColumnOfSymbols(playfield, windowWidth, matrix);
}
static void GenerateRightColumnOfSymbols(int playfield, int windowWidth, char[,] matrix)
{
Random randomEnemySymbol = new Random();
int symbolPosition = randomPosition.Next(0, playfield - 1);
char[] popeyeBonusSymbols = { 'S' };
Random bonusSymbol = new Random();
int indexBonusSymbol = bonusSymbol.Next(0, popeyeBonusSymbols.Length);
char[] symbols = { '#', '@', '*', (char)0xF, popeyeBonusSymbols[indexBonusSymbol] };
int indexEnemySymbol = randomEnemySymbol.Next(0, symbols.Length);
matrix[symbolPosition, windowWidth - 1] = symbols[indexEnemySymbol];
MovingToNextColumnEnemySymbols(symbolPosition, symbols[indexEnemySymbol], matrix);
}
static void MovingToNextColumnEnemySymbols(int symbolPosition, char symbol, char[,] matrix)
{
while (true)
{
PrintMatrix(matrix);
Thread.Sleep(150);
for (int rows = 0; rows < matrix.GetLength(0); rows++)
{
for (int col = 0; col < matrix.GetLength(1) - 1; col++)
{
matrix[rows, col] = matrix[rows, col + 1];
matrix[rows, col + 1] = '\0';
}
}
GenerateRightColumnOfSymbols(matrix.GetLength(0), matrix.GetLength(1), matrix);
}
}
static void PrintMatrix(char[,] matrix)
{
//Console.Clear();
Console.SetCursorPosition(0, 0);
for (int rows = 0; rows < matrix.GetLength(0); rows++)
{
for (int col = 0; col < matrix.GetLength(1); col++)
{
Console.Write(matrix[rows, col]);
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment