Add README

This commit is contained in:
CreepyCrafter24 2020-03-29 15:20:34 +02:00
commit 4d28d1abf0
34 changed files with 1147 additions and 0 deletions

607
.gitignore vendored Normal file
View File

@ -0,0 +1,607 @@

# Created by https://www.gitignore.io/api/rider,csharp,windows,visualstudio
# Edit at https://www.gitignore.io/?templates=rider,csharp,windows,visualstudio
### Csharp ###
## Ignore Visual Studio temporary files, build results, and
## files generated by popular Visual Studio add-ons.
##
## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore
# User-specific files
*.rsuser
*.suo
*.user
*.userosscache
*.sln.docstates
# User-specific files (MonoDevelop/Xamarin Studio)
*.userprefs
# Mono auto generated files
mono_crash.*
# Build results
[Dd]ebug/
[Dd]ebugPublic/
[Rr]elease/
[Rr]eleases/
x64/
x86/
[Aa][Rr][Mm]/
[Aa][Rr][Mm]64/
bld/
[Bb]in/
[Oo]bj/
[Ll]og/
# Visual Studio 2015/2017 cache/options directory
.vs/
# Uncomment if you have tasks that create the project's static files in wwwroot
#wwwroot/
# Visual Studio 2017 auto generated files
Generated\ Files/
# MSTest test Results
[Tt]est[Rr]esult*/
[Bb]uild[Ll]og.*
# NUnit
*.VisualState.xml
TestResult.xml
nunit-*.xml
# Build Results of an ATL Project
[Dd]ebugPS/
[Rr]eleasePS/
dlldata.c
# Benchmark Results
BenchmarkDotNet.Artifacts/
# .NET Core
project.lock.json
project.fragment.lock.json
artifacts/
# StyleCop
StyleCopReport.xml
# Files built by Visual Studio
*_i.c
*_p.c
*_h.h
*.ilk
*.obj
*.iobj
*.pch
*.pdb
*.ipdb
*.pgc
*.pgd
*.rsp
*.sbr
*.tlb
*.tli
*.tlh
*.tmp
*.tmp_proj
*_wpftmp.csproj
*.log
*.vspscc
*.vssscc
.builds
*.pidb
*.svclog
*.scc
# Chutzpah Test files
_Chutzpah*
# Visual C++ cache files
ipch/
*.aps
*.ncb
*.opendb
*.opensdf
*.sdf
*.cachefile
*.VC.db
*.VC.VC.opendb
# Visual Studio profiler
*.psess
*.vsp
*.vspx
*.sap
# Visual Studio Trace Files
*.e2e
# TFS 2012 Local Workspace
$tf/
# Guidance Automation Toolkit
*.gpState
# ReSharper is a .NET coding add-in
_ReSharper*/
*.[Rr]e[Ss]harper
*.DotSettings.user
# JustCode is a .NET coding add-in
.JustCode
# TeamCity is a build add-in
_TeamCity*
# DotCover is a Code Coverage Tool
*.dotCover
# AxoCover is a Code Coverage Tool
.axoCover/*
!.axoCover/settings.json
# Visual Studio code coverage results
*.coverage
*.coveragexml
# NCrunch
_NCrunch_*
.*crunch*.local.xml
nCrunchTemp_*
# MightyMoose
*.mm.*
AutoTest.Net/
# Web workbench (sass)
.sass-cache/
# Installshield output folder
[Ee]xpress/
# DocProject is a documentation generator add-in
DocProject/buildhelp/
DocProject/Help/*.HxT
DocProject/Help/*.HxC
DocProject/Help/*.hhc
DocProject/Help/*.hhk
DocProject/Help/*.hhp
DocProject/Help/Html2
DocProject/Help/html
# Click-Once directory
publish/
# Publish Web Output
*.[Pp]ublish.xml
*.azurePubxml
# Note: Comment the next line if you want to checkin your web deploy settings,
# but database connection strings (with potential passwords) will be unencrypted
*.pubxml
*.publishproj
# Microsoft Azure Web App publish settings. Comment the next line if you want to
# checkin your Azure Web App publish settings, but sensitive information contained
# in these scripts will be unencrypted
PublishScripts/
# NuGet Packages
*.nupkg
# NuGet Symbol Packages
*.snupkg
# The packages folder can be ignored because of Package Restore
**/[Pp]ackages/*
# except build/, which is used as an MSBuild target.
!**/[Pp]ackages/build/
# Uncomment if necessary however generally it will be regenerated when needed
#!**/[Pp]ackages/repositories.config
# NuGet v3's project.json files produces more ignorable files
*.nuget.props
*.nuget.targets
# Microsoft Azure Build Output
csx/
*.build.csdef
# Microsoft Azure Emulator
ecf/
rcf/
# Windows Store app package directories and files
AppPackages/
BundleArtifacts/
Package.StoreAssociation.xml
_pkginfo.txt
*.appx
*.appxbundle
*.appxupload
# Visual Studio cache files
# files ending in .cache can be ignored
*.[Cc]ache
# but keep track of directories ending in .cache
!?*.[Cc]ache/
# Others
ClientBin/
~$*
*~
*.dbmdl
*.dbproj.schemaview
*.jfm
*.pfx
*.publishsettings
orleans.codegen.cs
# Including strong name files can present a security risk
# (https://github.com/github/gitignore/pull/2483#issue-259490424)
#*.snk
# Since there are multiple workflows, uncomment next line to ignore bower_components
# (https://github.com/github/gitignore/pull/1529#issuecomment-104372622)
#bower_components/
# RIA/Silverlight projects
Generated_Code/
# Backup & report files from converting an old project file
# to a newer Visual Studio version. Backup files are not needed,
# because we have git ;-)
_UpgradeReport_Files/
Backup*/
UpgradeLog*.XML
UpgradeLog*.htm
ServiceFabricBackup/
*.rptproj.bak
# SQL Server files
*.mdf
*.ldf
*.ndf
# Business Intelligence projects
*.rdl.data
*.bim.layout
*.bim_*.settings
*.rptproj.rsuser
*- [Bb]ackup.rdl
*- [Bb]ackup ([0-9]).rdl
*- [Bb]ackup ([0-9][0-9]).rdl
# Microsoft Fakes
FakesAssemblies/
# GhostDoc plugin setting file
*.GhostDoc.xml
# Node.js Tools for Visual Studio
.ntvs_analysis.dat
node_modules/
# Visual Studio 6 build log
*.plg
# Visual Studio 6 workspace options file
*.opt
# Visual Studio 6 auto-generated workspace file (contains which files were open etc.)
*.vbw
# Visual Studio LightSwitch build output
**/*.HTMLClient/GeneratedArtifacts
**/*.DesktopClient/GeneratedArtifacts
**/*.DesktopClient/ModelManifest.xml
**/*.Server/GeneratedArtifacts
**/*.Server/ModelManifest.xml
_Pvt_Extensions
# Paket dependency manager
.paket/paket.exe
paket-files/
# FAKE - F# Make
.fake/
# CodeRush personal settings
.cr/personal
# Python Tools for Visual Studio (PTVS)
__pycache__/
*.pyc
# Cake - Uncomment if you are using it
# tools/**
# !tools/packages.config
# Tabs Studio
*.tss
# Telerik's JustMock configuration file
*.jmconfig
# BizTalk build output
*.btp.cs
*.btm.cs
*.odx.cs
*.xsd.cs
# OpenCover UI analysis results
OpenCover/
# Azure Stream Analytics local run output
ASALocalRun/
# MSBuild Binary and Structured Log
*.binlog
# NVidia Nsight GPU debugger configuration file
*.nvuser
# MFractors (Xamarin productivity tool) working folder
.mfractor/
# Local History for Visual Studio
.localhistory/
# BeatPulse healthcheck temp database
healthchecksdb
# Backup folder for Package Reference Convert tool in Visual Studio 2017
MigrationBackup/
### Rider ###
# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and WebStorm
# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839
# User-specific stuff
.idea/**/workspace.xml
.idea/**/tasks.xml
.idea/**/usage.statistics.xml
.idea/**/dictionaries
.idea/**/shelf
# Generated files
.idea/**/contentModel.xml
# Sensitive or high-churn files
.idea/**/dataSources/
.idea/**/dataSources.ids
.idea/**/dataSources.local.xml
.idea/**/sqlDataSources.xml
.idea/**/dynamic.xml
.idea/**/uiDesigner.xml
.idea/**/dbnavigator.xml
# Gradle
.idea/**/gradle.xml
.idea/**/libraries
# Gradle and Maven with auto-import
# When using Gradle or Maven with auto-import, you should exclude module files,
# since they will be recreated, and may cause churn. Uncomment if using
# auto-import.
# .idea/modules.xml
# .idea/*.iml
# .idea/modules
# *.iml
# *.ipr
# CMake
cmake-build-*/
# Mongo Explorer plugin
.idea/**/mongoSettings.xml
# File-based project format
*.iws
# IntelliJ
out/
# mpeltonen/sbt-idea plugin
.idea_modules/
# JIRA plugin
atlassian-ide-plugin.xml
# Cursive Clojure plugin
.idea/replstate.xml
# Crashlytics plugin (for Android Studio and IntelliJ)
com_crashlytics_export_strings.xml
crashlytics.properties
crashlytics-build.properties
fabric.properties
# Editor-based Rest Client
.idea/httpRequests
# Android studio 3.1+ serialized cache file
.idea/caches/build_file_checksums.ser
### Windows ###
# Windows thumbnail cache files
Thumbs.db
Thumbs.db:encryptable
ehthumbs.db
ehthumbs_vista.db
# Dump file
*.stackdump
# Folder config file
[Dd]esktop.ini
# Recycle Bin used on file shares
$RECYCLE.BIN/
# Windows Installer files
*.cab
*.msi
*.msix
*.msm
*.msp
# Windows shortcuts
*.lnk
### VisualStudio ###
# User-specific files
# User-specific files (MonoDevelop/Xamarin Studio)
# Mono auto generated files
# Build results
# Visual Studio 2015/2017 cache/options directory
# Uncomment if you have tasks that create the project's static files in wwwroot
# Visual Studio 2017 auto generated files
# MSTest test Results
# NUnit
# Build Results of an ATL Project
# Benchmark Results
# .NET Core
# StyleCop
# Files built by Visual Studio
# Chutzpah Test files
# Visual C++ cache files
# Visual Studio profiler
# Visual Studio Trace Files
# TFS 2012 Local Workspace
# Guidance Automation Toolkit
# ReSharper is a .NET coding add-in
# JustCode is a .NET coding add-in
# TeamCity is a build add-in
# DotCover is a Code Coverage Tool
# AxoCover is a Code Coverage Tool
# Visual Studio code coverage results
# NCrunch
# MightyMoose
# Web workbench (sass)
# Installshield output folder
# DocProject is a documentation generator add-in
# Click-Once directory
# Publish Web Output
# Note: Comment the next line if you want to checkin your web deploy settings,
# but database connection strings (with potential passwords) will be unencrypted
# Microsoft Azure Web App publish settings. Comment the next line if you want to
# checkin your Azure Web App publish settings, but sensitive information contained
# in these scripts will be unencrypted
# NuGet Packages
# NuGet Symbol Packages
# The packages folder can be ignored because of Package Restore
# except build/, which is used as an MSBuild target.
# Uncomment if necessary however generally it will be regenerated when needed
# NuGet v3's project.json files produces more ignorable files
# Microsoft Azure Build Output
# Microsoft Azure Emulator
# Windows Store app package directories and files
# Visual Studio cache files
# files ending in .cache can be ignored
# but keep track of directories ending in .cache
# Others
# Including strong name files can present a security risk
# (https://github.com/github/gitignore/pull/2483#issue-259490424)
# Since there are multiple workflows, uncomment next line to ignore bower_components
# (https://github.com/github/gitignore/pull/1529#issuecomment-104372622)
# RIA/Silverlight projects
# Backup & report files from converting an old project file
# to a newer Visual Studio version. Backup files are not needed,
# because we have git ;-)
# SQL Server files
# Business Intelligence projects
# Microsoft Fakes
# GhostDoc plugin setting file
# Node.js Tools for Visual Studio
# Visual Studio 6 build log
# Visual Studio 6 workspace options file
# Visual Studio 6 auto-generated workspace file (contains which files were open etc.)
# Visual Studio LightSwitch build output
# Paket dependency manager
# FAKE - F# Make
# CodeRush personal settings
# Python Tools for Visual Studio (PTVS)
# Cake - Uncomment if you are using it
# tools/**
# !tools/packages.config
# Tabs Studio
# Telerik's JustMock configuration file
# BizTalk build output
# OpenCover UI analysis results
# Azure Stream Analytics local run output
# MSBuild Binary and Structured Log
# NVidia Nsight GPU debugger configuration file
# MFractors (Xamarin productivity tool) working folder
# Local History for Visual Studio
# BeatPulse healthcheck temp database
# Backup folder for Package Reference Convert tool in Visual Studio 2017
# End of https://www.gitignore.io/api/rider,csharp,windows,visualstudio

0
.idea/.gitignore vendored Normal file
View File

View File

@ -0,0 +1,2 @@
# Default ignored files
/workspace.xml

View File

@ -0,0 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="DiscordProjectSettings">
<option name="show" value="true" />
</component>
<component name="ProjectNotificationSettings">
<option name="askShowProject" value="false" />
</component>
</project>

View File

@ -0,0 +1,4 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="Encoding" addBOMForNewFiles="with BOM under Windows, with no BOM otherwise" />
</project>

View File

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ContentModelUserStore">
<attachedFolders />
<explicitIncludes />
<explicitExcludes />
</component>
</project>

View File

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/.idea/.idea.SimpleConsoleGame/riderModule.iml" filepath="$PROJECT_DIR$/.idea/.idea.SimpleConsoleGame/riderModule.iml" />
</modules>
</component>
</project>

View File

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="RiderProjectSettingsUpdater">
<option name="vcsConfiguration" value="1" />
</component>
</project>

View File

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$" vcs="Git" />
</component>
</project>

View File

@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="RIDER_MODULE" version="4">
<component name="NewModuleRootManager">
<content url="file://$MODULE_DIR$/../.." />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>

2
.idea/.idea.Snakity/.idea/.gitignore vendored Normal file
View File

@ -0,0 +1,2 @@
# Default ignored files
/workspace.xml

View File

@ -0,0 +1 @@
Snakity

View File

@ -0,0 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="DiscordProjectSettings">
<option name="show" value="true" />
</component>
<component name="ProjectNotificationSettings">
<option name="askShowProject" value="false" />
</component>
</project>

View File

@ -0,0 +1,4 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="Encoding" addBOMForNewFiles="with BOM under Windows, with no BOM otherwise" />
</project>

View File

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ContentModelUserStore">
<attachedFolders />
<explicitIncludes />
<explicitExcludes />
</component>
</project>

View File

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/.idea/.idea.Snakity/riderModule.iml" filepath="$PROJECT_DIR$/.idea/.idea.Snakity/riderModule.iml" />
</modules>
</component>
</project>

View File

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="RiderProjectSettingsUpdater">
<option name="vcsConfiguration" value="1" />
</component>
</project>

View File

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$" vcs="Git" />
</component>
</project>

View File

@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="RIDER_MODULE" version="4">
<component name="NewModuleRootManager">
<content url="file://$MODULE_DIR$/../.." />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>

1
README.md Normal file
View File

@ -0,0 +1 @@
# Snakity

25
Snakity.sln Normal file
View File

@ -0,0 +1,25 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.29920.165
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Snakity", "Snakity\Snakity.csproj", "{068FEE48-B365-4AB4-9F64-0CCA55DCDF94}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{068FEE48-B365-4AB4-9F64-0CCA55DCDF94}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{068FEE48-B365-4AB4-9F64-0CCA55DCDF94}.Debug|Any CPU.Build.0 = Debug|Any CPU
{068FEE48-B365-4AB4-9F64-0CCA55DCDF94}.Release|Any CPU.ActiveCfg = Release|Any CPU
{068FEE48-B365-4AB4-9F64-0CCA55DCDF94}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {022F010F-BECC-4830-BC68-9139364EDE36}
EndGlobalSection
EndGlobal

View File

@ -0,0 +1,18 @@
using System;
namespace Snakity.Graphics
{
static class ColorSelector
{
public static ConsoleColor Get(char c)
{
return c switch
{
SpecialChars.Player => ConsoleColor.Green,
SpecialChars.Wall => ConsoleColor.Gray,
SpecialChars.Enemy => ConsoleColor.Yellow,
_ => ConsoleColor.White
};
}
}
}

View File

@ -0,0 +1,56 @@
using System;
namespace Snakity.Graphics
{
public static class DiffDraw
{
public static char[,] Screen { get; private set; } = new char[0, 0];
private static char[,] _last = new char[0,0];
public static int Width => Screen.GetLength(0);
public static int Height => Screen.GetLength(1);
public static void Draw()
{
Console.CursorTop = 0;
Console.CursorLeft = 0;
int width = Width;
int height = Height;
for (int y = 0; y < height; y++)
{
for (int x = 0; x < width; x++)
{
char tmp1 = Screen[x, y];
if (tmp1 == _last[x, y]) continue;
Console.ForegroundColor = ColorSelector.Get(tmp1);
Console.CursorLeft = x;
Console.Write(tmp1);
}
Console.WriteLine();
Console.CursorLeft = 0;
}
_last = Screen;
}
public static char Get(Point p) => Get(p.X, p.Y);
public static char Get(int x, int y) => Screen[x, y];
public static void Set(Point p, char c) => Set(p.X, p.Y, c);
public static void Set(int x, int y, char c) => Screen[x, y] = c;
public static void Clear() => Clear(Width, Height);
public static void Clear(int width, int height)
{
Screen = new char[width, height];
_last = _last.Resize(width, height);
}
public static void Clear(char[,] content)
{
Screen = content;
_last = _last.Resize(Width, Height);
}
}
}

31
Snakity/Graphics/Label.cs Normal file
View File

@ -0,0 +1,31 @@
using System.Linq;
namespace Snakity.Graphics
{
public class Label
{
public Point Position;
public string Text;
public Label(Point position, string text)
{
Position = position;
Text = text;
}
public void Render()
{
string[] lines = Text.Split('\n').Select(s => s.EndsWith('\r') ? s.Remove(s.Length - 1) : s).ToArray();
for (int i = 0; i < lines.Length; i++)
{
for (int j = 0; j < lines[i].Length; j++)
{
int tmpX = Position.X + j;
int tmpY = Position.Y + i;
if (tmpX < DiffDraw.Width && tmpY < DiffDraw.Height)
DiffDraw.Set(tmpX, tmpY, lines[i][j]);
}
}
}
}
}

View File

@ -0,0 +1,19 @@
using System;
using System.Collections.Generic;
namespace Snakity.Graphics
{
public static class Renderer
{
public static readonly List<Tuple<Point,Point>> Player = new List<Tuple<Point,Point>>();
public static readonly List<Point> Enemies = new List<Point>();
public static readonly List<Label> Labels = new List<Label>();
public static void Render()
{
foreach (Label label in Labels) label.Render();
foreach (Point point in Enemies) DiffDraw.Set(point, SpecialChars.Enemy);
foreach (Tuple<Point,Point> point in Player) DiffDraw.Set(point.Item1, SpecialChars.Player);
}
}
}

View File

@ -0,0 +1,10 @@
namespace Snakity.Graphics
{
public static class SpecialChars
{
public const char Player = '▮';
public const char Wall = '#';
public const char Enemy = '@';
public const char Space = '\0';
}
}

31
Snakity/LevelLoader.cs Normal file
View File

@ -0,0 +1,31 @@
using System;
using System.Linq;
using Snakity.Graphics;
namespace Snakity
{
public static class LevelLoader
{
public static Tuple<char[,], bool[,]> Load(string level)
{
string[] levelArr = level.Replace(' ', SpecialChars.Space).Split('\n');
int width = levelArr.Select(s => s.Length).OrderBy(s => s).Last();
int height = levelArr.Length;
char[,] tmp = new char[width, height];
bool[,] spawnable = new bool[width, height];
for (int x = 0; x < width; x++)
for (int y = 0; y < height; y++)
tmp[x, y] = SpecialChars.Space;
for (int i = 0; i < levelArr.Length; i++)
{
string s = levelArr[i];
for (int j = 0; j < s.Length; j++)
{
tmp[j, i] = s[j] == '.' ? SpecialChars.Space : s[j];
spawnable[j, i] = s[j] == '.';
}
}
return new Tuple<char[,], bool[,]>(tmp, spawnable);
}
}
}

43
Snakity/Levels.cs Normal file
View File

@ -0,0 +1,43 @@
namespace Snakity
{
public static class Levels
{
public static readonly string[] levels =
{
@"
######################
#.........#..........#
#.........#..........#
#....................#
#....................#
#.........#..........#
#.........#..........#
######################",
@"
#############################
#...........................#
#.....##....................#
#.....##.......##...........#
#..............##.....##....#
#........##...........##....#
#........##................##
#..........................##
###..............##.........#
###..............##.........#
#############################",
@"
######################
#....................#
#....................#
#....####....####....#
#....####....####....#
#....................#
#....................#
#....####....####....#
#....####....####....#
#....................#
#....................#
######################"
};
}
}

38
Snakity/Loop/Enemy.cs Normal file
View File

@ -0,0 +1,38 @@
using System;
using System.Linq;
using Snakity.Graphics;
namespace Snakity.Loop
{
public static class Enemy
{
private static DateTime _lastCheck = DateTime.Now;
private static readonly TimeSpan Delay = new TimeSpan(1000000);
public static bool Compute(bool[,] spawnMap)
{
bool increase = false;
foreach (Point point in Renderer.Enemies.Where(enemy => Renderer.Player.Any(s => s.Item1 == enemy)).ToList())
{
Renderer.Enemies.Remove(point);
increase = true;
}
DateTime tmp = DateTime.Now;
while (tmp - _lastCheck > Delay)
{
_lastCheck += Delay;
if (Program.Rnd.Next(50) != 0 && Renderer.Enemies.Count > 0) continue;
Point tmp1 = new Point(Program.Rnd.Next(DiffDraw.Width), Program.Rnd.Next(DiffDraw.Height));
int attempts = 0;
while (!spawnMap[tmp1.X, tmp1.Y] && attempts < 5)
{
tmp1.X = Program.Rnd.Next(DiffDraw.Width);
tmp1.Y = Program.Rnd.Next(DiffDraw.Height);
attempts++;
}
if (attempts < 5)
Renderer.Enemies.Add(tmp1);
}
return increase;
}
}
}

64
Snakity/Loop/Input.cs Normal file
View File

@ -0,0 +1,64 @@
using System;
using System.Windows.Forms;
using CC_Functions.W32;
using Snakity.Graphics;
namespace Snakity.Loop
{
public static class Input
{
private static DateTime _lastCheck = DateTime.Now;
public static TimeSpan Delay = new TimeSpan(3000000);
private static bool _shouldIncrease = false;
public static void Get()
{
Point headDelta = new Point(0, 0);
if ((KeyboardReader.IsKeyDown(Keys.W) || KeyboardReader.IsKeyDown(Keys.Up)))
headDelta.Y--;
if ((KeyboardReader.IsKeyDown(Keys.A) || KeyboardReader.IsKeyDown(Keys.Left)))
headDelta.X--;
if ((KeyboardReader.IsKeyDown(Keys.S) || KeyboardReader.IsKeyDown(Keys.Down)))
headDelta.Y++;
if ((KeyboardReader.IsKeyDown(Keys.D) || KeyboardReader.IsKeyDown(Keys.Right)))
headDelta.X++;
if (headDelta != new Point(0, 0) && (Renderer.Player.Count < 2 || headDelta != Renderer.Player[1].Item1 - Renderer.Player[0].Item1))
Renderer.Player[0] = new Tuple<Point, Point>(Renderer.Player[0].Item1, headDelta);
}
public static bool Move(bool increaseScore)
{
DateTime tmp = DateTime.Now;
if (increaseScore) _shouldIncrease = true;
while (tmp - _lastCheck > Delay)
{
_lastCheck += Delay;
Point head = Renderer.Player[0].Item1;
Point headDelta = Renderer.Player[0].Item2;
if (headDelta.Y == -1 && (head.Y == 0 || !CheckPoint(head + new Point(0, -1))))
return true;
if (headDelta.X == -1 && (head.X == 0 || !CheckPoint(head + new Point(-1, 0))))
return true;
if (headDelta.Y == 1 && (head.Y >= DiffDraw.Height - 1 || !CheckPoint(head + new Point(0, 1))))
return true;
if (headDelta.X == 1 && (head.X >= DiffDraw.Width - 1 || !CheckPoint(head + new Point(1, 0))))
return true;
Renderer.Player.Insert(0, new Tuple<Point, Point>(Renderer.Player[0].Item1 + headDelta, headDelta));
if (_shouldIncrease)
{
_shouldIncrease = false;
Delay = Delay.Subtract(new TimeSpan((int) (800 * Delay.TotalMilliseconds)));
}
else
{
Renderer.Player.RemoveAt(Renderer.Player.Count - 1);
}
}
return false;
}
public static void ResetSpeed() => Delay = new TimeSpan(3000000);
private static bool CheckPoint(Point point) =>
DiffDraw.Get(point) == SpecialChars.Space || DiffDraw.Get(point) == SpecialChars.Enemy;
}
}

54
Snakity/Loop/Program.cs Normal file
View File

@ -0,0 +1,54 @@
using System;
using System.Threading;
using System.Windows.Forms;
using CC_Functions.W32;
using Snakity.Graphics;
using Label = Snakity.Graphics.Label;
namespace Snakity.Loop
{
static class Program
{
private static int _score = 0;
public static Random Rnd = new Random();
public static void Main(string[] args)
{
DiffDraw.Clear(5, 5);
Label scoreLabel = new Label(new Point(0, 0), "");
Renderer.Labels.Add(scoreLabel);
(char[,] level, bool[,] spawnable) =
LevelLoader.Load(Levels.levels[Rnd.Next(Levels.levels.Length)]);
Renderer.Player.Add(new Tuple<Point, Point>(new Point(2, 2), new Point(0, 1)));
bool hasIncreased = false;
while (true)
{
DiffDraw.Clear((char[,])level.Clone());
scoreLabel.Text = $"Score: {_score}; d={Input.Delay.TotalMilliseconds}";
Renderer.Render();
Input.Get();
bool down = KeyboardReader.IsKeyDown(Keys.R);
if (Input.Move(hasIncreased) || down)
{
DiffDraw.Clear();
DiffDraw.Draw();
(level, spawnable) = LevelLoader.Load(Levels.levels[Rnd.Next(Levels.levels.Length)]);
Renderer.Player.Clear();
Renderer.Enemies.Clear();
Input.ResetSpeed();
Renderer.Player.Add(new Tuple<Point, Point>(new Point(2, 2), new Point(0, 1)));
DiffDraw.Clear((char[,])level.Clone());
if (down)
while (KeyboardReader.IsKeyDown(Keys.R))
Thread.Sleep(100);
}
Renderer.Render();
hasIncreased = Enemy.Compute(spawnable);
if (hasIncreased)
_score++;
DiffDraw.Draw();
if (KeyboardReader.IsKeyDown(Keys.Escape))
return;
}
}
}
}

19
Snakity/Point.cs Normal file
View File

@ -0,0 +1,19 @@
namespace Snakity
{
public struct Point
{
public int X;
public int Y;
public Point(int x, int y)
{
X = x;
Y = y;
}
public static bool operator ==(Point left, Point right) => left.X == right.X && left.Y == right.Y;
public static bool operator !=(Point left, Point right) => left.X != right.X || left.Y != right.Y;
public static Point operator +(Point left, Point right) => new Point(left.X + right.X, left.Y + right.Y);
public static Point operator -(Point left, Point right) => new Point(left.X - right.X, left.Y - right.Y);
}
}

18
Snakity/Resizer.cs Normal file
View File

@ -0,0 +1,18 @@
using System;
namespace Snakity
{
public static class Resizer
{
public static T[,] Resize<T>(this T[,] original, int rows, int cols)
{
T[,] newArray = new T[rows,cols];
int minRows = Math.Min(rows, original.GetLength(0));
int minCols = Math.Min(cols, original.GetLength(1));
for(int i = 0; i < minRows; i++)
for(int j = 0; j < minCols; j++)
newArray[i, j] = original[i, j];
return newArray;
}
}
}

12
Snakity/Snakity.csproj Normal file
View File

@ -0,0 +1,12 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp3.1</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="CC-Functions.W32" Version="1.1.7388.28729" />
</ItemGroup>
</Project>