This repository has been archived by the owner on Feb 15, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6da63dc
commit 7a6d656
Showing
2 changed files
with
151 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |