1. Nick Massey
  2. FallingSand

Commits

Nick Massey  committed 64b51ad

Initial commit

  • Participants
  • Branches default

Comments (0)

Files changed (28)

File .hgignore

View file
+glob:FallingSand/bin/
+glob:FallingSand/obj/
+glob:*.suo
+glob:*~
+glob:FallingSand/FallingSand.csproj.user
+glob:_ReSharper.FallingSand/

File FallingSand.sln

View file
+
+Microsoft Visual Studio Solution File, Format Version 11.00
+# Visual Studio 2010
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FallingSand", "FallingSand\FallingSand.csproj", "{9189301F-9501-4122-A76F-807243496DC8}"
+EndProject
+Global
+	GlobalSection(SolutionConfigurationPlatforms) = preSolution
+		Debug|x86 = Debug|x86
+		Release|x86 = Release|x86
+	EndGlobalSection
+	GlobalSection(ProjectConfigurationPlatforms) = postSolution
+		{9189301F-9501-4122-A76F-807243496DC8}.Debug|x86.ActiveCfg = Debug|x86
+		{9189301F-9501-4122-A76F-807243496DC8}.Debug|x86.Build.0 = Debug|x86
+		{9189301F-9501-4122-A76F-807243496DC8}.Release|x86.ActiveCfg = Release|x86
+		{9189301F-9501-4122-A76F-807243496DC8}.Release|x86.Build.0 = Release|x86
+	EndGlobalSection
+	GlobalSection(SolutionProperties) = preSolution
+		HideSolutionNode = FALSE
+	EndGlobalSection
+EndGlobal

File FallingSand/EmptyP.cs

View file
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+
+namespace FallingSand
+{
+    class EmptyP : Particle
+    {
+        public EmptyP(GameGrid grid, int x, int y)
+            : base(grid, x, y)
+        {
+            this.type = ParticleType.Empty;
+            this.density = 0;
+        }
+    }
+}

File FallingSand/FallingSand.csproj

View file
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+  <PropertyGroup>
+    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+    <Platform Condition=" '$(Platform)' == '' ">x86</Platform>
+    <ProductVersion>8.0.30703</ProductVersion>
+    <SchemaVersion>2.0</SchemaVersion>
+    <ProjectGuid>{9189301F-9501-4122-A76F-807243496DC8}</ProjectGuid>
+    <OutputType>WinExe</OutputType>
+    <AppDesignerFolder>Properties</AppDesignerFolder>
+    <RootNamespace>FallingSand</RootNamespace>
+    <AssemblyName>FallingSand</AssemblyName>
+    <TargetFrameworkVersion>v3.5</TargetFrameworkVersion>
+    <FileAlignment>512</FileAlignment>
+  </PropertyGroup>
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x86' ">
+    <PlatformTarget>x86</PlatformTarget>
+    <DebugSymbols>true</DebugSymbols>
+    <DebugType>full</DebugType>
+    <Optimize>true</Optimize>
+    <OutputPath>bin\Debug\</OutputPath>
+    <DefineConstants>DEBUG;TRACE</DefineConstants>
+    <ErrorReport>prompt</ErrorReport>
+    <WarningLevel>4</WarningLevel>
+    <AllowUnsafeBlocks>true</AllowUnsafeBlocks>
+  </PropertyGroup>
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|x86' ">
+    <PlatformTarget>x86</PlatformTarget>
+    <DebugType>pdbonly</DebugType>
+    <Optimize>true</Optimize>
+    <OutputPath>bin\Release\</OutputPath>
+    <DefineConstants>TRACE</DefineConstants>
+    <ErrorReport>prompt</ErrorReport>
+    <WarningLevel>4</WarningLevel>
+  </PropertyGroup>
+  <ItemGroup>
+    <Reference Include="System" />
+    <Reference Include="System.Core" />
+    <Reference Include="System.Xml.Linq" />
+    <Reference Include="System.Data.DataSetExtensions" />
+    <Reference Include="System.Data" />
+    <Reference Include="System.Deployment" />
+    <Reference Include="System.Drawing" />
+    <Reference Include="System.Windows.Forms" />
+    <Reference Include="System.Xml" />
+  </ItemGroup>
+  <ItemGroup>
+    <Compile Include="PipeP.cs" />
+    <Compile Include="LavaP.cs" />
+    <Compile Include="WaxP.cs" />
+    <Compile Include="GasolineP.cs" />
+    <Compile Include="EmptyP.cs" />
+    <Compile Include="SprinklerP.cs" />
+    <Compile Include="OilP.cs" />
+    <Compile Include="SparkP.cs" />
+    <Compile Include="FireP.cs" />
+    <Compile Include="PlantP.cs" />
+    <Compile Include="WeirdP.cs" />
+    <Compile Include="WaterP.cs" />
+    <Compile Include="Form1.cs">
+      <SubType>Form</SubType>
+    </Compile>
+    <Compile Include="Form1.Designer.cs">
+      <DependentUpon>Form1.cs</DependentUpon>
+    </Compile>
+    <Compile Include="GameGrid.cs" />
+    <Compile Include="Particle.cs" />
+    <Compile Include="Program.cs" />
+    <Compile Include="Properties\AssemblyInfo.cs" />
+    <Compile Include="SandP.cs" />
+    <Compile Include="WallP.cs" />
+    <EmbeddedResource Include="Form1.resx">
+      <DependentUpon>Form1.cs</DependentUpon>
+    </EmbeddedResource>
+    <EmbeddedResource Include="Properties\Resources.resx">
+      <Generator>ResXFileCodeGenerator</Generator>
+      <LastGenOutput>Resources.Designer.cs</LastGenOutput>
+      <SubType>Designer</SubType>
+    </EmbeddedResource>
+    <Compile Include="Properties\Resources.Designer.cs">
+      <AutoGen>True</AutoGen>
+      <DependentUpon>Resources.resx</DependentUpon>
+    </Compile>
+    <None Include="Properties\Settings.settings">
+      <Generator>SettingsSingleFileGenerator</Generator>
+      <LastGenOutput>Settings.Designer.cs</LastGenOutput>
+    </None>
+    <Compile Include="Properties\Settings.Designer.cs">
+      <AutoGen>True</AutoGen>
+      <DependentUpon>Settings.settings</DependentUpon>
+      <DesignTimeSharedInput>True</DesignTimeSharedInput>
+    </Compile>
+  </ItemGroup>
+  <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
+  <!-- To modify your build process, add your task inside one of the targets below and uncomment it. 
+       Other similar extension points exist, see Microsoft.Common.targets.
+  <Target Name="BeforeBuild">
+  </Target>
+  <Target Name="AfterBuild">
+  </Target>
+  -->
+</Project>

File FallingSand/FireP.cs

View file
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+
+namespace FallingSand
+{
+    class FireP : Particle
+    {
+        int age = 0;
+        ParticleType oldType;
+        public FireP(GameGrid grid, int x, int y, int burntime = 0, ParticleType oldType = ParticleType.Empty)
+            : base(grid, x, y)
+        {
+            this.type = ParticleType.Fire;
+            this.density = 499;
+            this.age -= burntime;
+            this.oldType = oldType;
+        }
+
+        public override void Tick()
+        {
+            int fireCount = 0;
+            for(int x = -1; x < 2; x++)
+            {
+                for(int y = -1; y < 2; y++)
+                {
+                    if(x == 0 && y == 0)
+                        continue;
+                    if (this[x, y] == ParticleType.Empty || this[x, y] == ParticleType.Fire || this[x,y] == ParticleType.Lava)
+                    {
+                        fireCount++;
+                    }
+                    if (GameGrid.TestOdds(this[x, y].flammability, 1000))
+                    {
+                        this[x, y] = new FireP(grid, xLoc + x, yLoc + y, this[x,y].burntime, this[x,y].type);
+                    }
+                }
+            }
+
+
+            age += fireCount;
+            if (fireCount >= 8)
+                age = 100;
+
+            if (this[0, 1] == ParticleType.Empty)
+            {
+                if (GameGrid.TestOdds(1, 15))
+                    this[0, 1] = new SparkP(grid, xLoc, yLoc + 1);
+            }
+
+            if (age > 30)
+            {
+                if (oldType == ParticleType.Wax && GameGrid.TestOdds(1,3))
+                    this[0, 0] = new LiquidWaxP(grid, xLoc, yLoc);
+                else
+                    this[0, 0] = new EmptyP(grid, xLoc, yLoc);
+            }
+            age++;
+        }
+    }
+}

File FallingSand/Form1.Designer.cs

View file
+namespace FallingSand
+{
+    partial class Form1
+    {
+        /// <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.panel1 = new System.Windows.Forms.Panel();
+            this.button1 = new System.Windows.Forms.Button();
+            this.comboBox1 = new System.Windows.Forms.ComboBox();
+            this.trackBar1 = new System.Windows.Forms.TrackBar();
+            ((System.ComponentModel.ISupportInitialize)(this.trackBar1)).BeginInit();
+            this.SuspendLayout();
+            // 
+            // panel1
+            // 
+            this.panel1.Location = new System.Drawing.Point(12, 12);
+            this.panel1.Name = "panel1";
+            this.panel1.Size = new System.Drawing.Size(350, 350);
+            this.panel1.TabIndex = 0;
+            this.panel1.MouseDown += new System.Windows.Forms.MouseEventHandler(this.Panel1MouseDown);
+            this.panel1.MouseUp += new System.Windows.Forms.MouseEventHandler(this.Panel1MouseUp);
+            // 
+            // button1
+            // 
+            this.button1.Location = new System.Drawing.Point(12, 441);
+            this.button1.Name = "button1";
+            this.button1.Size = new System.Drawing.Size(75, 23);
+            this.button1.TabIndex = 1;
+            this.button1.Text = "button1";
+            this.button1.UseVisualStyleBackColor = true;
+            this.button1.Click += new System.EventHandler(this.Button1Click);
+            // 
+            // comboBox1
+            // 
+            this.comboBox1.FormattingEnabled = true;
+            this.comboBox1.Location = new System.Drawing.Point(93, 441);
+            this.comboBox1.Name = "comboBox1";
+            this.comboBox1.Size = new System.Drawing.Size(121, 21);
+            this.comboBox1.TabIndex = 0;
+            // 
+            // trackBar1
+            // 
+            this.trackBar1.Location = new System.Drawing.Point(220, 428);
+            this.trackBar1.Maximum = 100;
+            this.trackBar1.Minimum = 1;
+            this.trackBar1.Name = "trackBar1";
+            this.trackBar1.Size = new System.Drawing.Size(192, 45);
+            this.trackBar1.TabIndex = 2;
+            this.trackBar1.Value = 1;
+            // 
+            // Form1
+            // 
+            this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
+            this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
+            this.ClientSize = new System.Drawing.Size(438, 476);
+            this.Controls.Add(this.trackBar1);
+            this.Controls.Add(this.comboBox1);
+            this.Controls.Add(this.button1);
+            this.Controls.Add(this.panel1);
+            this.Name = "Form1";
+            this.Text = "Form1";
+            this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.Form1FormClosing);
+            this.Load += new System.EventHandler(this.Form1Load);
+            ((System.ComponentModel.ISupportInitialize)(this.trackBar1)).EndInit();
+            this.ResumeLayout(false);
+            this.PerformLayout();
+
+        }
+
+        #endregion
+
+        private System.Windows.Forms.Panel panel1;
+        private System.Windows.Forms.Button button1;
+        private System.Windows.Forms.ComboBox comboBox1;
+        private System.Windows.Forms.TrackBar trackBar1;
+    }
+}
+

File FallingSand/Form1.cs

View file
+using System;
+using System.Drawing;
+using System.Linq;
+using System.Windows.Forms;
+using System.Threading;
+using System.Collections;
+
+
+
+namespace FallingSand
+{
+    public partial class Form1 : Form
+    {
+        BufferedGraphics _buff;
+        BufferedGraphicsContext _buffC;
+        public Form1()
+        {
+            InitializeComponent();
+        }
+
+        private  void Form1Load(object sender, EventArgs e)
+        {
+            comboBox1.DataSource = Enum.GetNames(typeof(ParticleType)).OrderBy(x => x).ToList();
+        }
+
+        private static IEnumerable DrawLine(int x0, int y0, int x1, int y1)
+        {
+            var dx = Math.Abs(x1-x0);
+            var dy = Math.Abs(y1-y0);
+            
+            int sx;
+            int sy;
+
+            if (x0 < x1)
+                sx = 1;
+            else
+                sx = -1;
+            if (y0 < y1)
+                sy = 1;
+            else
+                sy = -1;
+
+            var err = dx - dy;
+
+            while (true)
+            {
+                yield return new Point(x0, y0);
+                if (x0 == x1 && y0 == y1)
+                    break;
+                var e2 = err * 2;
+                if (e2 > dy * -1)
+                {
+                    err = err - dy;
+                    x0 += sx;
+                }
+                if (e2 >= dx) continue;
+                err = err + dx;
+                y0 += sy;
+            }
+        }
+        Point _p1;
+        private unsafe void Button1Click(object sender, EventArgs e)
+        {
+            var grid = new GameGrid(panel1.Width, panel1.Height);
+            var screen = new Bitmap(panel1.Width, panel1.Height);
+            var pGfx = panel1.CreateGraphics();
+            _buffC = new BufferedGraphicsContext();
+            _buff = _buffC.Allocate(pGfx, new Rectangle(0,0,panel1.Width, panel1.Height));
+            while (!_closing)
+            {
+                Application.DoEvents();
+                if (!_mouseDown)
+                {
+                    _p1 = new Point(-1, -1);
+                }
+                else
+                {
+                    ParticleType a;
+                    try
+                    {
+                         a = (ParticleType)Enum.Parse(typeof(ParticleType), comboBox1.Items[comboBox1.SelectedIndex].ToString());
+                    }
+                    catch
+                    {
+                        a = ParticleType.Empty;
+                    }
+                    Point p0 = panel1.PointToClient(Cursor.Position);
+                    if (_p1.X == -1)
+                        _p1 = p0;
+                    var radius = trackBar1.Value;
+                    foreach (Point p in DrawLine(p0.X, p0.Y, _p1.X, _p1.Y))
+                    {
+                        for (var x = -radius; x < radius; x++)
+                        {
+                            var height = (int) Math.Sqrt(radius*radius - x*x);
+                            for (var y = -height; y < height; y++)
+                            {
+
+                                var xPos = p.X + x;
+                                var yPos = panel1.Height - (p.Y + y);
+                                Particle par;
+                                switch (a)
+                                {
+                                    default:
+                                        par = new EmptyP(grid, xPos, yPos);
+                                        break;
+                                    case ParticleType.Wax:
+                                        par = new WaxP(grid, xPos, yPos);
+                                        break;
+                                    case ParticleType.Fire:
+                                        par = new FireP(grid, xPos, yPos);
+                                        break;
+                                    case ParticleType.Gasoline:
+                                        par = new GasolineP(grid, xPos, yPos);
+                                        break;
+                                    case ParticleType.Oil:
+                                        par = new OilP(grid, xPos, yPos);
+                                        break;
+                                    case ParticleType.Plant:
+                                        par = new PlantP(grid, xPos, yPos);
+                                        break;
+                                    case ParticleType.Sand:
+                                        par = new SandP(grid, xPos, yPos);
+                                        break;
+                                    case ParticleType.Spark:
+                                        par = new SparkP(grid, xPos, yPos);
+                                        break;
+                                    case ParticleType.Sprinkler:
+                                        par = new SprinklerP(grid, xPos, yPos, ParticleType.Water);
+                                        break;
+                                    case ParticleType.Torch:
+                                        par = new SprinklerP(grid, xPos, yPos, ParticleType.Spark);
+                                        break;
+                                    case ParticleType.OilSprinkler:
+                                        par = new SprinklerP(grid, xPos, yPos, ParticleType.Oil);
+                                        break;
+                                    case ParticleType.Wall:
+                                        par = new WallP(grid, xPos, yPos);
+                                        break;
+                                    case ParticleType.Water:
+                                        par = new WaterP(grid, xPos, yPos);
+                                        break;
+                                    case ParticleType.Weird:
+                                        par = new WeirdP(grid, xPos, yPos);
+                                        break;
+                                    case ParticleType.Lava:
+                                        par = new LavaP(grid, xPos, yPos);
+                                        break;
+                                    case ParticleType.Pipe:
+                                        par = new PipeP(grid, xPos, yPos);
+                                        break;
+                                }
+                                grid[xPos, yPos] = par;
+                            }
+                        }
+                    }
+                    _p1 = p0;
+                }
+                var bmd = screen.LockBits(new Rectangle(0, 0, grid.sizeX, grid.sizeY), System.Drawing.Imaging.ImageLockMode.WriteOnly, System.Drawing.Imaging.PixelFormat.Format32bppArgb);
+                var ptr = (uint*)bmd.Scan0;
+
+                for (var x = 0; x < grid.sizeX; x++)
+                {
+                    for (int y = 0; y < grid.sizeY; y++)
+                        ptr[(((grid.sizeY - 1) - y)*grid.sizeX) + x] = (uint) grid[x, y].type | 0xFF000000;
+                }
+
+                screen.UnlockBits(bmd);
+                if(!_closing)
+                _buff.Graphics.DrawImageUnscaled(screen, Point.Empty);
+
+                if (!_closing)
+                grid.RandTick();
+
+                if (!_closing)
+                _buff.Render();
+            }
+
+        }
+        bool _closing;
+        private void Form1FormClosing(object sender, FormClosingEventArgs e)
+        {
+
+            _closing = true;
+            Thread.Sleep(200);
+        }
+
+        bool _mouseDown;
+
+        private void Panel1MouseDown(object sender, MouseEventArgs e)
+        {
+            _mouseDown = true;
+        }
+
+        private void Panel1MouseUp(object sender, MouseEventArgs e)
+        {
+            _mouseDown = false;
+        }
+    }
+}

File FallingSand/Form1.resx

View file
+<?xml version="1.0" encoding="utf-8"?>
+<root>
+  <!-- 
+    Microsoft ResX Schema 
+    
+    Version 2.0
+    
+    The primary goals of this format is to allow a simple XML format 
+    that is mostly human readable. The generation and parsing of the 
+    various data types are done through the TypeConverter classes 
+    associated with the data types.
+    
+    Example:
+    
+    ... ado.net/XML headers & schema ...
+    <resheader name="resmimetype">text/microsoft-resx</resheader>
+    <resheader name="version">2.0</resheader>
+    <resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
+    <resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
+    <data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
+    <data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
+    <data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
+        <value>[base64 mime encoded serialized .NET Framework object]</value>
+    </data>
+    <data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
+        <value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
+        <comment>This is a comment</comment>
+    </data>
+                
+    There are any number of "resheader" rows that contain simple 
+    name/value pairs.
+    
+    Each data row contains a name, and value. The row also contains a 
+    type or mimetype. Type corresponds to a .NET class that support 
+    text/value conversion through the TypeConverter architecture. 
+    Classes that don't support this are serialized and stored with the 
+    mimetype set.
+    
+    The mimetype is used for serialized objects, and tells the 
+    ResXResourceReader how to depersist the object. This is currently not 
+    extensible. For a given mimetype the value must be set accordingly:
+    
+    Note - application/x-microsoft.net.object.binary.base64 is the format 
+    that the ResXResourceWriter will generate, however the reader can 
+    read any of the formats listed below.
+    
+    mimetype: application/x-microsoft.net.object.binary.base64
+    value   : The object must be serialized with 
+            : System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
+            : and then encoded with base64 encoding.
+    
+    mimetype: application/x-microsoft.net.object.soap.base64
+    value   : The object must be serialized with 
+            : System.Runtime.Serialization.Formatters.Soap.SoapFormatter
+            : and then encoded with base64 encoding.
+
+    mimetype: application/x-microsoft.net.object.bytearray.base64
+    value   : The object must be serialized into a byte array 
+            : using a System.ComponentModel.TypeConverter
+            : and then encoded with base64 encoding.
+    -->
+  <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=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
+  </resheader>
+  <resheader name="writer">
+    <value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
+  </resheader>
+</root>

File FallingSand/GameGrid.cs

View file
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Drawing;
+
+namespace FallingSand
+{
+    class GameGrid
+    {
+        public static Random randGen = new Random();
+        public static bool TestOdds(int numerator, int denominator)
+        {
+            return randGen.Next(denominator) < numerator;
+        }
+
+        public int sizeX;
+        public int sizeY;
+
+        Particle[,] grid;
+
+        Particle borderWall;
+
+        int[][] randTickOrder;
+        int tickOrderCount = 10;
+
+        public GameGrid(int x, int y)
+        {
+            this.sizeX = x;
+            this.sizeY = y;
+            this.grid = new Particle[sizeX, sizeY];
+            for (int xPos = 0; xPos < sizeX; xPos++)
+            {
+                for (int yPos = 0; yPos < sizeY; yPos++)
+                {
+                    this[xPos, yPos] = new EmptyP(this, xPos, yPos);
+                }
+            }
+            /*
+            for (int xPos = (int)(x * 0.3); xPos < (int)(x * 0.6); xPos++)
+            {
+                for (int yPos = (int)(y * 0.3); yPos < (int)(y * 0.6); yPos++)
+                {
+                    this[xPos, yPos] = new SandP(this, xPos, yPos);
+                }
+            }
+
+            for (int xPos = (int)(x * 0.3); xPos < (int)(x * 0.6); xPos++)
+            {
+                for (int yPos = (int)(y * 0.0); yPos < (int)(y * 0.3); yPos++)
+                {
+                    this[xPos, yPos] = new WaterP(this, xPos, yPos);
+                }
+            }
+
+            for (int xPos = (int)(x * 0.25); xPos < (int)(x * 0.4); xPos++)
+            {
+                for (int yPos = 55; yPos < 61; yPos++)
+                {
+                    this[xPos, yPos] = new WallP(this, xPos, yPos);
+                }
+            }
+
+            for (int xPos = (int)(x * 0.15); xPos < (int)(x * 0.2); xPos++)
+            {
+                for (int yPos = 8; yPos < 12; yPos++)
+                {
+                    this[xPos, yPos] = new PlantP(this, xPos, yPos);
+                }
+            }
+
+            for (int xPos = (int)(x * 0.425); xPos < (int)(x * 0.475); xPos++)
+            {
+                for (int yPos = (int)(y * 0.425); yPos < (int)(y * 0.475); yPos++)
+                {
+                    //this[xPos, yPos] = new FireP(this, xPos, yPos);
+                }
+            }
+
+            for (int xPos = x - 10; xPos < x; xPos++)
+            {
+                for (int yPos = 0; yPos < y - (int)(y * 0.2); yPos++)
+                {
+                    this[xPos, yPos] = new GasolineP(this, xPos, yPos);
+                }
+            }
+            for (int xPos = 0; xPos < x; xPos++)
+            {
+                for (int yPos = y - (int)(y * 0.32); yPos < y - (int)(y * 0.2); yPos++)
+                {
+                    this[xPos, yPos] = new PlantP(this, xPos, yPos);
+                }
+            }
+            for (int xPos = 0; xPos < 10; xPos++)
+            {
+                for (int yPos = 0; yPos < y; yPos++)
+                {
+                    this[xPos, yPos] = new PlantP(this, xPos, yPos);
+                }
+            }
+
+            for (int xPos = x -(int)(x * 0.2); xPos < x - (int)(x * 0.15); xPos++)
+            {
+                for (int yPos = y - (int)(y * 0.53); yPos < y - (int)(y*0.5); yPos++)
+                {
+                    this[xPos, yPos] = new SprinklerP(this, xPos, yPos, ParticleType.Oil);
+                }
+            }
+            for (int xPos = x - (int)(x * 0.18); xPos < x - (int)(x * 0.13); xPos++)
+            {
+                for (int yPos = y - (int)(y * 0.1); yPos < y - (int)(y * 0.08); yPos++)
+                {
+                    this[xPos, yPos] = new SprinklerP(this, xPos, yPos, ParticleType.Water);
+                }
+            }
+             * 
+             */
+            borderWall = new WallP(this, int.MinValue / 2, int.MinValue / 2);
+
+
+
+            List<int> hitPoints = new List<int>(sizeX * sizeY);
+
+            for (int xPos = 0; xPos < sizeX; xPos++)
+            {
+                for (int yPos = 0; yPos < sizeY; yPos++)
+                {
+                    hitPoints.Add(xPos | (yPos << 16));
+                }
+            }
+
+            randTickOrder = new int[tickOrderCount][];
+            for (int i = 0; i < tickOrderCount; i++)
+                randTickOrder[i] = hitPoints.OrderBy(hp => randGen.Next()).ToArray();
+        }
+
+        public void Tick()
+        {
+            for (int xPos = 0; xPos < sizeX; xPos++)
+            {
+                for (int yPos = 0; yPos < sizeY; yPos++)
+                {
+                    this[xPos, yPos].Tick();
+                }
+            }
+        }
+
+        public void RandTick()
+        {
+            int index = GameGrid.randGen.Next(tickOrderCount);
+            for(int i =0; i < randTickOrder[index].Length; i++)
+                this[randTickOrder[index][i] & 0xFFFF, randTickOrder[index][i] >> 16].Tick();
+        }
+
+        public Particle this[int x, int y]
+        {
+            get
+            {
+                if (x < 0 || y < 0 || x >= sizeX || y >= sizeY)
+                {
+                    return borderWall;
+                }
+                else
+                {
+                    return grid[x, y];
+                }
+            }
+            set
+            {
+                if (!(x < 0 || y < 0 || x >= sizeX || y >= sizeY))
+                {
+                    grid[x, y] = value;
+                }
+            }
+        }
+    }
+}

File FallingSand/GasolineP.cs

View file
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+
+namespace FallingSand
+{
+    class GasolineP : Particle
+    {
+        public GasolineP(GameGrid grid, int x, int y)
+            : base(grid, x, y)
+        {
+            this.type = ParticleType.Gasoline;
+            this.density = 0;
+            this.flammability = 2000;
+        }
+
+        public override void Tick()
+        {
+            List<int> gasSpotY = new List<int>(9);
+            List<int> gasSpotX = new List<int>(9);
+            for (int x = -1; x < 2; x++)
+            {
+                for (int y = -1; y < 2; y++)
+                {
+                    if (this[x, y] == ParticleType.Empty)
+                    {
+                        gasSpotY.Add(y);
+                        gasSpotX.Add(x);
+
+                    }
+                }
+            }
+            if (gasSpotX.Count != 0)
+            {
+                int randPoint = GameGrid.randGen.Next(gasSpotX.Count);
+
+                Swap(this[gasSpotX[randPoint], gasSpotY[randPoint]]);
+            }
+        }
+    }
+}

File FallingSand/LavaP.cs

View file
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+
+namespace FallingSand
+{
+    class LavaP : Particle
+    {
+        private int spread = 6;
+        public LavaP(GameGrid grid, int x, int y)
+            : base(grid, x, y)
+        {
+            this.type = ParticleType.Lava;
+            this.density = 3;
+            this.flammability = 0;
+        }
+        public override void Tick()
+        {
+            for (int x = -1; x < 2; x++)
+            {
+                for (int y = -1; y < 2; y++)
+                {
+                    if (x == 0 && y == 0)
+                        continue;
+                    if (this[x, y] == ParticleType.Water)
+                    {
+                        this[x, y] = new WallP(grid, xLoc + x, yLoc + y);
+                    }
+                    else if (GameGrid.TestOdds(this[x, y].flammability, 1000))
+                    {
+                        this[x, y] = new FireP(grid, xLoc + x, yLoc + y, this[x, y].burntime, this[x, y].type);
+                    }
+                }
+            }
+            
+            if (this[0, -1].density < this.density)
+            {
+               Swap(this[0, -1]);
+            }
+            else if (GameGrid.TestOdds(1, 2))
+            {
+                bool fallOrder = GameGrid.TestOdds(1, 2);
+                bool initOrder = fallOrder;
+                bool done = false;
+                while (!done)
+                {
+                    if (fallOrder)
+                    {
+                        for (int x = -1; x > (spread * -1); x--)
+                        {
+                            if (this[x, 0].density < this.density)
+                            {
+                                done = true;
+                                Swap(this[x, 0]);
+                                break;
+                            }
+                            else if (this[x, 0] != this.type)
+                            {
+                                break;
+                            }
+                        }
+                    }
+                    else
+                    {
+                        for (int x = 1; x < (spread); x++)
+                        {
+                            if (this[x, 0].density < this.density)
+                            {
+                                done = true;
+                                Swap(this[x, 0]);
+                                break;
+                            }
+                            else if (this[x, 0] != this.type)
+                            {
+                                break;
+                            }
+                        }
+                    }
+                    fallOrder = !fallOrder;
+                    if (fallOrder == initOrder)
+                            done = true;
+                }
+            }
+        }
+    }
+}

File FallingSand/OilP.cs

View file
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+
+namespace FallingSand
+{
+    class OilP : Particle
+    {
+        private int spread = 15;
+        public OilP(GameGrid grid, int x, int y)
+            : base(grid, x, y)
+        {
+            this.type = ParticleType.Oil;
+            this.density = 1;
+            this.flammability = 2000;
+        }
+        public override void Tick()
+        {
+
+            if (this[0, 1] == ParticleType.Empty)
+            {
+                if (GameGrid.TestOdds(1, 250))
+                {
+                    this[0, 1] = new GasolineP(grid, xLoc, yLoc + 1);
+                    this[0, 0] = new EmptyP(grid, xLoc, yLoc);
+                    return;
+                }
+            }
+            
+            if (this[0, -1].density < this.density)
+            {
+               Swap(this[0, -1]);
+            }
+            else if (GameGrid.TestOdds(1, 2))
+            {
+                bool fallOrder = GameGrid.TestOdds(1, 2);
+                bool initOrder = fallOrder;
+                bool done = false;
+                while (!done)
+                {
+                    if (fallOrder)
+                    {
+                        for (int x = -1; x > (spread * -1); x--)
+                        {
+                            if (this[x, 0].density < this.density)
+                            {
+                                done = true;
+                                Swap(this[x, 0]);
+                                break;
+                            }
+                            else if (this[x, 0] != this.type)
+                            {
+                                break;
+                            }
+                        }
+                    }
+                    else
+                    {
+                        for (int x = 1; x < (spread); x++)
+                        {
+                            if (this[x, 0].density < this.density)
+                            {
+                                done = true;
+                                Swap(this[x, 0]);
+                                break;
+                            }
+                            else if (this[x, 0] != this.type)
+                            {
+                                break;
+                            }
+                        }
+                    }
+                    fallOrder = !fallOrder;
+                    if (fallOrder == initOrder)
+                            done = true;
+                }
+            }
+        }
+    }
+}

File FallingSand/Particle.cs

View file
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+
+namespace FallingSand
+{
+    enum ParticleType
+    {
+        Empty = 0x000000,
+        Sand = 0xEFE4B0,
+        Wax = 0xFFF4C0,
+        LiquidWax = 0xFFF4C0,
+        Water = 0x0000FF,
+        Wall = 0xDDDDDD,
+        Plant = 0x00FF00,
+        Fire = 0xFFFF00,
+        Spark = 0xFF0000,
+        Oil = 0x660066,
+        Sprinkler = 0x333333,
+        Gasoline = 0x440044,
+        OilSprinkler,
+        Torch,
+        Lava = 0xAA0000,
+        Pipe = 0x222222,
+        Weird = 0xFFFFFF,
+        Weird2 = 0xFE0000,
+        Weird3 = 0xFF00FF
+    }
+
+    class Particle
+    {
+        protected GameGrid grid;
+        public int xLoc;
+        public int yLoc;
+        public int density;
+        public int flammability;
+        public int burntime;
+        public ParticleType type;
+
+        public Particle(GameGrid grid, int x, int y)
+        {
+            this.grid = grid;
+            this.xLoc = x;
+            this.yLoc = y;
+        }
+
+        public Particle this[int x, int y]
+        {
+            get
+            {
+                return grid[xLoc + x, yLoc + y];
+            }
+            set
+            {
+                grid[xLoc + x, yLoc + y] = value;
+            }
+        }
+
+        public void Swap(Particle p)
+        {
+            int x = p.xLoc;
+            int y = p.yLoc;
+            p.Move(xLoc, yLoc);
+            this.Move(x, y);
+        }
+
+        public void Move(int x, int y)
+        {
+            grid[x, y] = this;
+            xLoc = x;
+            yLoc = y;
+        }
+
+        public virtual void Tick()
+        {
+        }
+
+        public static bool operator ==(Particle p, Particle p2)
+        {
+            return p.type == p2.type;
+        }
+        public static bool operator ==(Particle p, ParticleType t)
+        {
+            return p.type == t;
+        }
+        public static bool operator ==(ParticleType t, Particle p)
+        {
+            return p.type == t;
+        }
+        public static bool operator !=(Particle p, Particle p2)
+        {
+            return !(p == p2);
+        }
+        public static bool operator !=(Particle p, ParticleType t)
+        {
+            return !(p == t);
+        }
+        public static bool operator !=(ParticleType t, Particle p)
+        {
+            return !(p == t);
+        }
+    }
+}

File FallingSand/PipeP.cs

View file
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+
+namespace FallingSand
+{
+    class PipeP : Particle
+    {
+        int age = 0;
+        public PipeP(GameGrid grid, int x, int y)
+            : base(grid, x, y)
+        {
+            this.type = ParticleType.Pipe;
+            this.density = 499;
+        }
+
+        public override void Tick()
+        {
+            if (age < 20)
+            {
+                for (int x = -1; x < 2; x++)
+                {
+                    for (int y = -1; y < 2; y++)
+                    {
+                        if (x == 0 && y == 0)
+                            continue;
+                        if (this[x, y] != ParticleType.Pipe)
+                        {
+                            this[x, y] = new WallP(grid, xLoc + x, yLoc + y);
+                        }
+                    }
+                }
+            }
+
+            if (age > 30)
+            {
+                this[0, 0] = new EmptyP(grid, xLoc, yLoc);
+            }
+            age++;
+        }
+    }
+}

File FallingSand/PlantP.cs

View file
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+
+namespace FallingSand
+{
+    class PlantP : Particle
+    {
+        List<Particle> candidates = new List<Particle>(9);
+        public PlantP(GameGrid grid, int x, int y)
+            : base(grid, x, y)
+        {
+            this.type = ParticleType.Plant;
+            this.density = 500;
+            this.flammability = 100;
+            
+        }
+        public override void Tick()
+        {
+            int minCount = 100;
+
+            for (int x = -1; x < 2; x++)
+            {
+                for (int y = -1; y < 2; y++)
+                {
+                    if (x == 0 && y == 0)
+                        continue;
+                    if (this[x, y] == ParticleType.Water)
+                    {
+                        int count = 0;
+                        for (int x2 = -1; x2 < 2; x2++)
+                        {
+                            for (int y2 = -1; y2 < 2; y2++)
+                            {
+                                if (x2 == 0 && y2 == 0)
+                                    continue;
+                                if (this[x, y][x2, y2] == ParticleType.Plant)
+                                    count++;
+                            }
+                        }
+                        if (count < minCount)
+                        {
+                            candidates.Clear();
+                            candidates.Add(this[x, y]);
+                            minCount = count;
+                        }
+                        else if (count == minCount)
+                            candidates.Add(this[x, y]);
+                    }
+                }
+            }
+            if (candidates.Count == 0)
+                return;
+            if (minCount > 2 && minCount < 5)
+                return;
+            if ((minCount == 5) && GameGrid.TestOdds(99, 100))
+                return;
+            int index = GameGrid.randGen.Next(candidates.Count);
+
+
+            grid[candidates[index].xLoc, candidates[index].yLoc] = new PlantP(grid, candidates[index].xLoc, candidates[index].yLoc);
+        }
+    }
+}

File FallingSand/Program.cs

View file
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Windows.Forms;
+
+namespace FallingSand
+{
+    static class Program
+    {
+        /// <summary>
+        /// The main entry point for the application.
+        /// </summary>
+        [STAThread]
+        static void Main()
+        {
+            Application.EnableVisualStyles();
+            Application.SetCompatibleTextRenderingDefault(false);
+            Application.Run(new Form1());
+        }
+    }
+}

File FallingSand/Properties/AssemblyInfo.cs

View file
+using System.Reflection;
+using System.Runtime.CompilerServices;
+using System.Runtime.InteropServices;
+
+// General Information about an assembly is controlled through the following 
+// set of attributes. Change these attribute values to modify the information
+// associated with an assembly.
+[assembly: AssemblyTitle("FallingSand")]
+[assembly: AssemblyDescription("")]
+[assembly: AssemblyConfiguration("")]
+[assembly: AssemblyCompany("Microsoft")]
+[assembly: AssemblyProduct("FallingSand")]
+[assembly: AssemblyCopyright("Copyright © Microsoft 2011")]
+[assembly: AssemblyTrademark("")]
+[assembly: AssemblyCulture("")]
+
+// Setting ComVisible to false makes the types in this assembly not visible 
+// to COM components.  If you need to access a type in this assembly from 
+// COM, set the ComVisible attribute to true on that type.
+[assembly: ComVisible(false)]
+
+// The following GUID is for the ID of the typelib if this project is exposed to COM
+[assembly: Guid("61d0bdf1-f61e-4b1e-814a-3fdbad3d5ad6")]
+
+// Version information for an assembly consists of the following four values:
+//
+//      Major Version
+//      Minor Version 
+//      Build Number
+//      Revision
+//
+// You can specify all the values or you can default the Build and Revision Numbers 
+// by using the '*' as shown below:
+// [assembly: AssemblyVersion("1.0.*")]
+[assembly: AssemblyVersion("1.0.0.0")]
+[assembly: AssemblyFileVersion("1.0.0.0")]

File FallingSand/Properties/Resources.Designer.cs

View file
+//------------------------------------------------------------------------------
+// <auto-generated>
+//     This code was generated by a tool.
+//     Runtime Version:4.0.30319.239
+//
+//     Changes to this file may cause incorrect behavior and will be lost if
+//     the code is regenerated.
+// </auto-generated>
+//------------------------------------------------------------------------------
+
+namespace FallingSand.Properties
+{
+
+
+    /// <summary>
+    ///   A strongly-typed resource class, for looking up localized strings, etc.
+    /// </summary>
+    // This class was auto-generated by the StronglyTypedResourceBuilder
+    // class via a tool like ResGen or Visual Studio.
+    // To add or remove a member, edit your .ResX file then rerun ResGen
+    // with the /str option, or rebuild your VS project.
+    [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")]
+    [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
+    [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
+    internal class Resources
+    {
+
+        private static global::System.Resources.ResourceManager resourceMan;
+
+        private static global::System.Globalization.CultureInfo resourceCulture;
+
+        [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
+        internal Resources()
+        {
+        }
+
+        /// <summary>
+        ///   Returns the cached ResourceManager instance used by this class.
+        /// </summary>
+        [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
+        internal static global::System.Resources.ResourceManager ResourceManager
+        {
+            get
+            {
+                if ((resourceMan == null))
+                {
+                    global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("FallingSand.Properties.Resources", typeof(Resources).Assembly);
+                    resourceMan = temp;
+                }
+                return resourceMan;
+            }
+        }
+
+        /// <summary>
+        ///   Overrides the current thread's CurrentUICulture property for all
+        ///   resource lookups using this strongly typed resource class.
+        /// </summary>
+        [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
+        internal static global::System.Globalization.CultureInfo Culture
+        {
+            get
+            {
+                return resourceCulture;
+            }
+            set
+            {
+                resourceCulture = value;
+            }
+        }
+    }
+}

File FallingSand/Properties/Resources.resx

View file
+<?xml version="1.0" encoding="utf-8"?>
+<root>
+  <!-- 
+    Microsoft ResX Schema 
+    
+    Version 2.0
+    
+    The primary goals of this format is to allow a simple XML format 
+    that is mostly human readable. The generation and parsing of the 
+    various data types are done through the TypeConverter classes 
+    associated with the data types.
+    
+    Example:
+    
+    ... ado.net/XML headers & schema ...
+    <resheader name="resmimetype">text/microsoft-resx</resheader>
+    <resheader name="version">2.0</resheader>
+    <resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
+    <resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
+    <data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
+    <data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
+    <data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
+        <value>[base64 mime encoded serialized .NET Framework object]</value>
+    </data>
+    <data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
+        <value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
+        <comment>This is a comment</comment>
+    </data>
+                
+    There are any number of "resheader" rows that contain simple 
+    name/value pairs.
+    
+    Each data row contains a name, and value. The row also contains a 
+    type or mimetype. Type corresponds to a .NET class that support 
+    text/value conversion through the TypeConverter architecture. 
+    Classes that don't support this are serialized and stored with the 
+    mimetype set.
+    
+    The mimetype is used for serialized objects, and tells the 
+    ResXResourceReader how to depersist the object. This is currently not 
+    extensible. For a given mimetype the value must be set accordingly:
+    
+    Note - application/x-microsoft.net.object.binary.base64 is the format 
+    that the ResXResourceWriter will generate, however the reader can 
+    read any of the formats listed below.
+    
+    mimetype: application/x-microsoft.net.object.binary.base64
+    value   : The object must be serialized with 
+            : System.Serialization.Formatters.Binary.BinaryFormatter
+            : and then encoded with base64 encoding.
+    
+    mimetype: application/x-microsoft.net.object.soap.base64
+    value   : The object must be serialized with 
+            : System.Runtime.Serialization.Formatters.Soap.SoapFormatter
+            : and then encoded with base64 encoding.
+
+    mimetype: application/x-microsoft.net.object.bytearray.base64
+    value   : The object must be serialized into a byte array 
+            : using a System.ComponentModel.TypeConverter
+            : and then encoded with base64 encoding.
+    -->
+  <xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
+    <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" type="xsd:string" />
+              <xsd:attribute name="type" type="xsd:string" />
+              <xsd:attribute name="mimetype" type="xsd:string" />
+            </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" msdata:Ordinal="1" />
+              <xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
+              <xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
+            </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=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
+  </resheader>
+  <resheader name="writer">
+    <value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
+  </resheader>
+</root>

File FallingSand/Properties/Settings.Designer.cs

View file
+//------------------------------------------------------------------------------
+// <auto-generated>
+//     This code was generated by a tool.
+//     Runtime Version:4.0.30319.239
+//
+//     Changes to this file may cause incorrect behavior and will be lost if
+//     the code is regenerated.
+// </auto-generated>
+//------------------------------------------------------------------------------
+
+namespace FallingSand.Properties
+{
+
+
+    [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
+    [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "10.0.0.0")]
+    internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase
+    {
+
+        private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings())));
+
+        public static Settings Default
+        {
+            get
+            {
+                return defaultInstance;
+            }
+        }
+    }
+}

File FallingSand/Properties/Settings.settings

View file
+<?xml version='1.0' encoding='utf-8'?>
+<SettingsFile xmlns="http://schemas.microsoft.com/VisualStudio/2004/01/settings" CurrentProfile="(Default)">
+  <Profiles>
+    <Profile Name="(Default)" />
+  </Profiles>
+  <Settings />
+</SettingsFile>

File FallingSand/SandP.cs

View file
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+
+namespace FallingSand
+{
+    class SandP : Particle
+    {
+        public SandP(GameGrid grid, int x, int y)
+            : base(grid, x, y)
+        {
+            this.type = ParticleType.Sand;
+            this.density = 3;
+        }
+        public override void Tick()
+        {
+            if (this[0, -1].density < this.density)
+            {
+                Swap(this[0, -1]);
+            }
+            else if (GameGrid.TestOdds(2, 3))
+            {
+
+            }
+            else if (GameGrid.TestOdds(1, 2))
+            {
+                if (this[1, -1].density < this.density)
+                    Swap(this[1, -1]);
+                else if (this[-1, -1].density < this.density)
+                    Swap(this[-1, -1]);
+            }
+            else
+            {
+                if (this[-1, -1].density < this.density)
+                    Swap(this[-1, -1]);
+                else if (this[1, -1].density < this.density)
+                    Swap(this[1, -1]);
+            }
+        }
+    }
+}

File FallingSand/SparkP.cs

View file
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+
+namespace FallingSand
+{
+    class SparkP : Particle
+    {
+        int age = 16;
+        public SparkP(GameGrid grid, int x, int y)
+            : base(grid, x, y)
+        {
+            this.type = ParticleType.Spark;
+            this.density = 499;
+            age += GameGrid.randGen.Next(20);
+        }
+
+        public override void Tick()
+        {
+            for(int x = -1; x < 2; x++)
+            {
+                for(int y = -1; y < 2; y++)
+                {
+                    if(x == 0 && y == 0)
+                        continue;
+                    if (GameGrid.TestOdds(this[x, y].flammability, 2000))
+                    {
+                        this[x, y] = new FireP(grid, xLoc + x, yLoc + y);
+                    }
+                }
+            }
+
+            if (this[0, 1] == ParticleType.Empty)
+            {
+                Swap(this[0, 1]);
+            }
+            else if (GameGrid.TestOdds(this[0, 1].flammability, 200))
+            {
+                this[0, 1] = new FireP(grid, xLoc, yLoc + 1);
+                this[0, 0] = new EmptyP(grid, xLoc, yLoc);
+            }
+            else
+            {
+                this[0, 0] = new EmptyP(grid, xLoc, yLoc);
+            }
+
+
+            if (age <= 0)
+            {
+                this[0, 0] = new EmptyP(grid, xLoc, yLoc);
+            }
+            age--;
+        }
+    }
+}

File FallingSand/SprinklerP.cs

View file
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+
+namespace FallingSand
+{
+    class SprinklerP : Particle
+    {
+        ParticleType childType;
+        public SprinklerP(GameGrid grid, int x, int y, ParticleType childType)
+            : base(grid, x, y)
+        {
+            this.childType = childType;
+            this.type = ParticleType.Sprinkler;
+            this.density = 500;
+        }
+
+        public override void Tick()
+        {
+            for(int x = -1; x < 2; x++)
+            {
+                for(int y = -1; y < 2; y++)
+                {
+                    if(x == 0 && y == 0)
+                        continue;
+                    if ((this[x,y] == ParticleType.Empty) && GameGrid.TestOdds(1,2))
+                    {
+                        switch (childType)
+                        {
+                            case ParticleType.Oil:
+                                this[x, y] = new OilP(grid, xLoc + x, yLoc + y);
+                                break;
+                            case ParticleType.Water:
+                                this[x, y] = new WaterP(grid, xLoc + x, yLoc + y);
+                                break;
+                            case ParticleType.Fire:
+                                this[x, y] = new FireP(grid, xLoc + x, yLoc + y);
+                                break;
+                            case ParticleType.Spark:
+                                this[x, y] = new SparkP(grid, xLoc + x, yLoc + y);
+                                break;
+                        }
+                    }
+                }
+            }
+        }
+    }
+}

File FallingSand/WallP.cs

View file
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+
+namespace FallingSand
+{
+    class WallP : Particle
+    {
+        public WallP(GameGrid grid, int x, int y)
+            : base(grid, x, y)
+        {
+            this.type = ParticleType.Wall;
+            this.density = 500;
+        }
+    }
+}

File FallingSand/WaterP.cs

View file
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+
+namespace FallingSand
+{
+    class WaterP : Particle
+    {
+        private int spread = 10;
+        bool fallOrder;
+        public WaterP(GameGrid grid, int x, int y)
+            : base(grid, x, y)
+        {
+            this.type = ParticleType.Water;
+            this.density = 2;
+
+            
+        }
+        public override void Tick()
+        {
+            if (this[0, -1].density < this.density)
+            {
+               Swap(this[0, -1]);
+            }
+            else if (GameGrid.TestOdds(1, 2))
+            {
+                bool fallOrder = GameGrid.TestOdds(1, 2);
+                bool initOrder = fallOrder;
+                bool done = false;
+                while (!done)
+                {
+                    if (fallOrder)
+                    {
+                        for (int x = -1; x > (spread * -1); x--)
+                        {
+                            if (this[x, 0].density < this.density)
+                            {
+                                done = true;
+                                Swap(this[x, 0]);
+                                break;
+                            }
+                            else if (this[x, 0] != this.type)
+                            {
+                                break;
+                            }
+                        }
+                    }
+                    else
+                    {
+                        for (int x = 1; x < (spread); x++)
+                        {
+                            if (this[x, 0].density < this.density)
+                            {
+                                done = true;
+                                Swap(this[x, 0]);
+                                break;
+                            }
+                            else if (this[x, 0] != this.type)
+                            {
+                                break;
+                            }
+                        }
+                    }
+                    fallOrder = !fallOrder;
+                    if (fallOrder == initOrder)
+                            done = true;
+                }
+            }
+        }
+    }
+}

File FallingSand/WaxP.cs

View file
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+
+namespace FallingSand
+{
+    class LiquidWaxP : Particle
+    {
+        int setTime = 0;
+        public LiquidWaxP(GameGrid grid, int x, int y)
+            : base(grid, x, y)
+        {
+            this.type = ParticleType.LiquidWax;
+            this.density = 3;
+            this.flammability = 5;
+            this.burntime = 3000;
+        }
+        public override void Tick()
+        {
+            if (this[0, -1].density < this.density)
+            {
+                Swap(this[0, -1]);
+                setTime = 0;
+            }
+            else
+            {
+                setTime++;
+                if (setTime > 30)
+                    this[0, 0] = new WaxP(grid, xLoc, yLoc);
+            }
+        }
+    }
+
+    class WaxP : Particle
+    {
+        public WaxP(GameGrid grid, int x, int y)
+            : base(grid, x, y)
+        {
+            this.type = ParticleType.Wax;
+            this.density = 3;
+            this.flammability = 5;
+            this.burntime = 3000;
+        }
+    }
+}

File FallingSand/WeirdP.cs

View file
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+
+namespace FallingSand
+{
+    class WeirdP : Particle
+    {
+        int age = 3;
+        public WeirdP(GameGrid grid, int x, int y)
+            : base(grid, x, y)
+        {
+            this.type = ParticleType.Weird;
+            this.density = 500;
+        }
+        public override void Tick()
+        {
+            for (int x = -1; x < 2; x++)
+            {
+                for (int y = -1; y < 2; y++)
+                {
+                    if (this[x, y] != ParticleType.Empty && this[x, y] != ParticleType.Weird && this[x, y] != ParticleType.Weird2)
+                        this[x, y] = new WeirdP(grid, xLoc + x, yLoc + y);
+                }
+            }
+            age--;
+            if (age == 0)
+                this[0, 0] = new WeirdP2(grid, xLoc, yLoc);
+        }
+    }
+    class WeirdP2 : Particle
+    {
+        int age = 3;
+        public WeirdP2(GameGrid grid, int x, int y)
+            : base(grid, x, y)
+        {
+            this.type = ParticleType.Weird2;
+            this.density = 500;
+        }
+        public override void Tick()
+        {
+            for (int x = -1; x < 2; x++)
+            {
+                for (int y = -1; y < 2; y++)
+                {
+                    if (this[x, y] != ParticleType.Empty && this[x, y] != ParticleType.Weird2 && this[x, y] != ParticleType.Weird3)
+                        this[x, y] = new WeirdP2(grid, xLoc + x, yLoc + y);
+                }
+            }
+            age--;
+            if (age == 0)
+                this[0, 0] = new WeirdP3(grid, xLoc, yLoc);
+        }
+    }
+    class WeirdP3 : Particle
+    {
+        int age = 3;
+        public WeirdP3(GameGrid grid, int x, int y)
+            : base(grid, x, y)
+        {
+            this.type = ParticleType.Weird3;
+            this.density = 500;
+        }
+        public override void Tick()
+        {
+            for (int x = -1; x < 2; x++)
+            {
+                for (int y = -1; y < 2; y++)
+                {
+                    if (this[x, y] != ParticleType.Empty && this[x, y] != ParticleType.Weird3 && this[x,y] != ParticleType.Weird)
+                        this[x, y] = new WeirdP3(grid, xLoc + x, yLoc + y);
+                }
+            }
+            age--;
+            if (age == 0)
+                this[0, 0] = new WeirdP(grid, xLoc, yLoc);
+        }
+    }
+}