Browse Source

Initial commit

Add files from Visual Studio.
master
TheoryOfNekomata 3 years ago
commit
9bf43c3b8f
8 changed files with 776 additions and 0 deletions
  1. +361
    -0
      .gitignore
  2. +9
    -0
      GameOfLife/GameOfLife.csproj
  3. +60
    -0
      GameOfLife/MainForm.Designer.cs
  4. +183
    -0
      GameOfLife/MainForm.cs
  5. +60
    -0
      GameOfLife/MainForm.resx
  6. +70
    -0
      GameOfLife/Program.cs
  7. +8
    -0
      GameOfLife/Properties/launchSettings.json
  8. +25
    -0
      WindowsScreensavers.sln

+ 361
- 0
.gitignore View File

@@ -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

+ 9
- 0
GameOfLife/GameOfLife.csproj View File

@@ -0,0 +1,9 @@
<Project Sdk="Microsoft.NET.Sdk.WindowsDesktop">
<PropertyGroup>
<OutputType>WinExe</OutputType>
<TargetFramework>netcoreapp3.1</TargetFramework>
<UseWindowsForms>true</UseWindowsForms>
</PropertyGroup>
</Project>

+ 60
- 0
GameOfLife/MainForm.Designer.cs View File

@@ -0,0 +1,60 @@

namespace GameOfLife
{
partial class MainForm
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
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;
}
}

+ 183
- 0
GameOfLife/MainForm.cs View File

@@ -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);
}
}
}

+ 60
- 0
GameOfLife/MainForm.resx View File

@@ -0,0 +1,60 @@
<root>
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
</root>

+ 70
- 0
GameOfLife/Program.cs View File

@@ -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
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[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();
}
}
}
}

+ 8
- 0
GameOfLife/Properties/launchSettings.json View File

@@ -0,0 +1,8 @@
{
"profiles": {
"GameOfLife": {
"commandName": "Project",
"commandLineArgs": "/s"
}
}
}

+ 25
- 0
WindowsScreensavers.sln View File

@@ -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

Loading…
Cancel
Save