commit 9bf43c3b8f857d77d0e68356c19e7c7058aaef26 Author: TheoryOfNekomata Date: Tue Apr 27 23:01:25 2021 +0800 Initial commit Add files from Visual Studio. diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..8fb9eb1 --- /dev/null +++ b/.gitignore @@ -0,0 +1,361 @@ +### 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/ +[Ww][Ii][Nn]32/ +[Aa][Rr][Mm]/ +[Aa][Rr][Mm]64/ +bld/ +[Bb]in/ +[Oo]bj/ +[Ll]og/ +[Ll]ogs/ + +# 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/ + +# ASP.NET Scaffolding +ScaffoldingReadMe.txt + +# StyleCop +StyleCopReport.xml + +# Files built by Visual Studio +*_i.c +*_p.c +*_h.h +*.ilk +*.meta +*.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 + +# TeamCity is a build add-in +_TeamCity* + +# DotCover is a Code Coverage Tool +*.dotCover + +# AxoCover is a Code Coverage Tool +.axoCover/* +!.axoCover/settings.json + +# Coverlet is a free, cross platform Code Coverage Tool +coverage*[.json, .xml, .info] + +# 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/ + +# Ionide (cross platform F# VS Code tools) working folder +.ionide/ + +# Fody - auto-generated XML schema +FodyWeavers.xsd diff --git a/GameOfLife/GameOfLife.csproj b/GameOfLife/GameOfLife.csproj new file mode 100644 index 0000000..7b05c62 --- /dev/null +++ b/GameOfLife/GameOfLife.csproj @@ -0,0 +1,9 @@ + + + + WinExe + netcoreapp3.1 + true + + + \ No newline at end of file diff --git a/GameOfLife/MainForm.Designer.cs b/GameOfLife/MainForm.Designer.cs new file mode 100644 index 0000000..0aab3aa --- /dev/null +++ b/GameOfLife/MainForm.Designer.cs @@ -0,0 +1,60 @@ + +namespace GameOfLife +{ + partial class MainForm + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + this.components = new System.ComponentModel.Container(); + this.timer = new System.Windows.Forms.Timer(this.components); + this.SuspendLayout(); + // + // MainForm + // + this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.BackColor = System.Drawing.Color.Black; + this.ClientSize = new System.Drawing.Size(800, 450); + this.DoubleBuffered = true; + this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None; + this.Name = "MainForm"; + this.StartPosition = System.Windows.Forms.FormStartPosition.Manual; + this.Load += new System.EventHandler(this.MainForm_Load); + this.Paint += new System.Windows.Forms.PaintEventHandler(this.MainForm_Paint); + this.KeyPress += new System.Windows.Forms.KeyPressEventHandler(this.MainForm_KeyPress); + this.MouseClick += new System.Windows.Forms.MouseEventHandler(this.MainForm_MouseClick); + this.MouseMove += new System.Windows.Forms.MouseEventHandler(this.MainForm_MouseMove); + this.ResumeLayout(false); + + } + + #endregion + + private System.Windows.Forms.Timer timer; + } +} + diff --git a/GameOfLife/MainForm.cs b/GameOfLife/MainForm.cs new file mode 100644 index 0000000..1ba9281 --- /dev/null +++ b/GameOfLife/MainForm.cs @@ -0,0 +1,183 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace GameOfLife +{ + public partial class MainForm : Form + { + private Point mouseLocation; + + private bool[,] newCells; + private bool[,] toggleCells; + private bool[,] oldCells; + + private Random random; + + private int gridSize = 4; + + private int magicCells = 0; + + private double density = 0.45; + + public MainForm(Rectangle bounds) + { + InitializeComponent(); + random = new Random(); + Bounds = bounds; + newCells = new bool[bounds.Width / gridSize, bounds.Height / gridSize]; + toggleCells = new bool[bounds.Width / gridSize, bounds.Height / gridSize]; + oldCells = new bool[bounds.Width / gridSize, bounds.Height / gridSize]; + + for (var x = 0; x < newCells.GetLength(0); x++) { + for (var y = 0; y < newCells.GetLength(1); y++) { + newCells[x, y] = random.NextDouble() <= density; + oldCells[x, y] = false; + toggleCells[x, y] = true; + } + } + } + + private void MainForm_Load(object sender, EventArgs e) + { + Cursor.Hide(); + TopMost = true; + + timer.Interval = 50; + timer.Tick += new EventHandler(timer_Tick); + timer.Start(); + } + + private void MainForm_MouseMove(object sender, MouseEventArgs e) + { + if (!mouseLocation.IsEmpty) + { + // Terminate if mouse is moved a significant distance + if (Math.Abs(mouseLocation.X - e.X) > 5 || + Math.Abs(mouseLocation.Y - e.Y) > 5) + Application.Exit(); + } + + // Update current mouse location + mouseLocation = e.Location; + + } + + private void MainForm_MouseClick(object sender, MouseEventArgs e) + { + Application.Exit(); + } + + private void MainForm_KeyPress(object sender, KeyPressEventArgs e) + { + Application.Exit(); + } + + private int GetAliveNeighbors(bool[,] cells, int x, int y) { + int prevX = x == cells.GetLowerBound(0) ? cells.GetUpperBound(0) : x - 1; + int nextX = x == cells.GetUpperBound(0) ? cells.GetLowerBound(0) : x + 1; + int prevY = y == cells.GetLowerBound(1) ? cells.GetUpperBound(1) : y - 1; + int nextY = y == cells.GetUpperBound(1) ? cells.GetLowerBound(1) : y + 1; + + int aliveNeighbors = 0; + if (cells[prevX, prevY]) { + aliveNeighbors += 1; + } + if (cells[x, prevY]) + { + aliveNeighbors += 1; + } + if (cells[nextX, prevY]) + { + aliveNeighbors += 1; + } + if (cells[prevX, y]) + { + aliveNeighbors += 1; + } + if (cells[nextX, y]) + { + aliveNeighbors += 1; + } + if (cells[prevX, nextY]) + { + aliveNeighbors += 1; + } + if (cells[x, nextY]) + { + aliveNeighbors += 1; + } + if (cells[nextX, nextY]) + { + aliveNeighbors += 1; + } + return aliveNeighbors; + } + + private void timer_Tick(object sender, EventArgs e) { + for (var x = 0; x < newCells.GetLength(0); x++) + { + for (var y = 0; y < newCells.GetLength(1); y++) + { + oldCells[x, y] = newCells[x, y]; + } + } + + for (var x = 0; x < newCells.GetLength(0); x++) + { + for (var y = 0; y < newCells.GetLength(1); y++) + { + int neighbors = GetAliveNeighbors(oldCells, x, y); + bool shouldLive = false; + if (oldCells[x, y] && neighbors == 2) + { + shouldLive = true; + } else if (!oldCells[x, y] && neighbors == 3) { + shouldLive = true; + } + + newCells[x, y] = shouldLive; + toggleCells[x, y] = oldCells[x, y] == newCells[x, y]; + } + } + + for (var i = 0; i < magicCells; i++) { + int magicX = random.Next(0, newCells.GetUpperBound(0)); + int magicY = random.Next(0, newCells.GetUpperBound(1)); + + newCells[magicX, magicY] = true; + toggleCells[magicX, magicY] = oldCells[magicX, magicY] == newCells[magicX, magicY]; + } + + Redraw(CreateGraphics()); + } + + private void Redraw(Graphics graphics) { + graphics.FillRectangle(Brushes.Black, Bounds); + for (var x = 0; x < newCells.GetLength(0); x++) + { + for (var y = 0; y < newCells.GetLength(1); y++) + { + if (newCells[x, y]) + { + graphics.FillRectangle(Brushes.White, x * gridSize, y * gridSize, gridSize, gridSize); + } + //else if (!newCells[x, y]) { + // graphics.FillRectangle(Brushes.Black, x * gridSize, y * gridSize, gridSize, gridSize); + //} + } + } + } + + private void MainForm_Paint(object sender, PaintEventArgs e) + { + Redraw(e.Graphics); + } + } +} diff --git a/GameOfLife/MainForm.resx b/GameOfLife/MainForm.resx new file mode 100644 index 0000000..b5ae26c --- /dev/null +++ b/GameOfLife/MainForm.resx @@ -0,0 +1,60 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/GameOfLife/Program.cs b/GameOfLife/Program.cs new file mode 100644 index 0000000..ed16915 --- /dev/null +++ b/GameOfLife/Program.cs @@ -0,0 +1,70 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace GameOfLife +{ + static class Program + { + /// + /// The main entry point for the application. + /// + [STAThread] + static void Main(string[] args) + { + Application.SetHighDpiMode(HighDpiMode.SystemAware); + Application.EnableVisualStyles(); + Application.SetCompatibleTextRenderingDefault(false); + + if (args.Length > 0) + { + string firstArgument = args[0].ToLower().Trim(); + string secondArgument = null; + + // Handle cases where arguments are separated by colon. + // Examples: /c:1234567 or /P:1234567 + if (firstArgument.Length > 2) + { + secondArgument = firstArgument.Substring(3).Trim(); + firstArgument = firstArgument.Substring(0, 2); + } + else if (args.Length > 1) + secondArgument = args[1]; + + if (firstArgument == "/c") // Configuration mode + { + // TODO + } + else if (firstArgument == "/p") // Preview mode + { + // TODO + } + else if (firstArgument == "/s") // Full-screen mode + { + ShowScreenSaver(); + Application.Run(); + } + else // Undefined argument + { + MessageBox.Show("Sorry, but the command line argument \"" + firstArgument + + "\" is not valid.", "ScreenSaver", + MessageBoxButtons.OK, MessageBoxIcon.Exclamation); + } + } + else // No arguments - treat like /c + { + // TODO + } + } + + static void ShowScreenSaver() + { + foreach (Screen screen in Screen.AllScreens) { + MainForm form = new MainForm(screen.Bounds); + form.Show(); + } + } + } +} diff --git a/GameOfLife/Properties/launchSettings.json b/GameOfLife/Properties/launchSettings.json new file mode 100644 index 0000000..6a365cb --- /dev/null +++ b/GameOfLife/Properties/launchSettings.json @@ -0,0 +1,8 @@ +{ + "profiles": { + "GameOfLife": { + "commandName": "Project", + "commandLineArgs": "/s" + } + } +} \ No newline at end of file diff --git a/WindowsScreensavers.sln b/WindowsScreensavers.sln new file mode 100644 index 0000000..5932cf8 --- /dev/null +++ b/WindowsScreensavers.sln @@ -0,0 +1,25 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 16 +VisualStudioVersion = 16.0.31005.135 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "GameOfLife", "GameOfLife\GameOfLife.csproj", "{AED00861-CA7B-4A9E-AD2B-A4232834FC3F}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {AED00861-CA7B-4A9E-AD2B-A4232834FC3F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {AED00861-CA7B-4A9E-AD2B-A4232834FC3F}.Debug|Any CPU.Build.0 = Debug|Any CPU + {AED00861-CA7B-4A9E-AD2B-A4232834FC3F}.Release|Any CPU.ActiveCfg = Release|Any CPU + {AED00861-CA7B-4A9E-AD2B-A4232834FC3F}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {AF4042B1-D47C-4BDE-9E40-C25006615D66} + EndGlobalSection +EndGlobal