Skip to content
This repository has been archived by the owner on Feb 15, 2024. It is now read-only.

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
Segilmez06 authored Jan 29, 2022
1 parent 6da63dc commit 7a6d656
Show file tree
Hide file tree
Showing 2 changed files with 151 additions and 0 deletions.
141 changes: 141 additions & 0 deletions src/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
using System;
using System.Threading;
using System.Threading.Tasks;

namespace SharpRain
{
class Program
{
static void Main(string[] args)
{
Console.CursorVisible = false;
Console.Clear();

while (true)
{
new RainDrop(Console.BufferWidth, Console.BufferHeight);
Thread.Sleep(500);
}
}
}

class RainDrop
{
char[] chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890^&$%#@!*?;:".ToCharArray();
char GetNewChar()
{
return chars[new Random().Next(chars.Length)];
}

int rainSize = 0;
int max = 7;

int col = 0;
int row = 0;

int termW, termH;

static int lastCol;

public RainDrop(int _w, int _h)
{
termW = _w;
termH = _h;

var rand = new Random().Next(termW);
while (rand == lastCol)
{
rand = new Random().Next(termW);
}
col = rand;

Start();
}

public async void Start()
{
await Task.Run(() => { StartDropping(); });
}

async void StartDropping()
{
while (MoveDown())
{
Thread.Sleep(150);
}
}

bool MoveDown()
{
if (row + rainSize == termH)
{
rainSize--;
row++;

}
else
{
if (rainSize < max)
{
rainSize++;
}
else
{
row++;
}
}
if (row > 2)
{
for (int i = row - 3; i < row; i++)
{
Utils.WriteAt(col, i, " ", ConsoleColor.Green);
}

}
for (int i = 0; i < rainSize; i++)
{
if (i == rainSize - 1)
{
Utils.WriteAt(col, row + i, GetNewChar(), ConsoleColor.Cyan);
}
else
{
Utils.WriteAt(col, row + i, GetNewChar(), ConsoleColor.Green);
}
}
if (row == termH)
{
return false;
}
return true;
}
}

class Utils
{
static char c = (char)27;

public static void WriteAt(int left, int top, string text, ConsoleColor forecolor)
{
Console.ForegroundColor = forecolor;
Console.Write(c + "[" + top.ToString() + ";" + left.ToString() + "H" + text);
}

public static void WriteAt(int left, int top, char character, ConsoleColor forecolor)
{
WriteAt(left, top, character.ToString(), forecolor);
}

public static void WriteAt(int left, int top, string text, ConsoleColor forecolor, ConsoleColor backcolor)
{
Console.BackgroundColor = backcolor;
WriteAt(left, top, text, forecolor);
}

public static void WriteAt(int left, int top, char character, ConsoleColor forecolor, ConsoleColor backcolor)
{
Console.BackgroundColor = backcolor;
WriteAt(left, top, character.ToString(), forecolor);
}
}
}
10 changes: 10 additions & 0 deletions src/SharpRain.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net5.0</TargetFramework>
<Platforms>AnyCPU;x64</Platforms>
<StartupObject>SharpRain.Program</StartupObject>
</PropertyGroup>

</Project>

0 comments on commit 7a6d656

Please sign in to comment.