Source

FallingSand / FallingSand / SaltP.cs

Full commit
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace FallingSand
{
    class SaltP : Particle
    {
        public SaltP(GameGrid grid, int x, int y)
            : base(grid, x, y)
        {
            this.type = ParticleType.Salt;
            this.density = 4;
        }
        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].type == ParticleType.Ice && GameGrid.TestOdds(1,60))
                    {
                        this[x, y] = new WaterP(grid, xLoc + x, yLoc + y);
                    }
                    if (this[x, y].type == ParticleType.Plant)
                    {
                        this[x, y] = new SoilP(grid, xLoc + x, yLoc + y);
                    }
                }
            }
            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)
                {
                    if (this[1, -1].type == ParticleType.Ice)
                    {
                        this[1, -1] = new WaterP(grid, xLoc + 1, yLoc - 1);
                    }
                    Swap(this[1, -1]);
                }
                else if (this[-1, -1].density < this.density)
                {
                    if (this[-1, -1].type == ParticleType.Ice)
                    {
                        this[-1, -1] = new WaterP(grid, xLoc - 1, yLoc - 1);
                    }
                    Swap(this[-1, -1]);
                }
            }
            else
            {
                if (this[-1, -1].density < this.density)
                {
                    if (this[-1, -1].type == ParticleType.Ice)
                    {
                        this[-1, -1] = new WaterP(grid, xLoc - 1, yLoc - 1);
                    }
                    Swap(this[-1, -1]);
                }
                else if (this[1, -1].density < this.density)
                {
                    if (this[1, -1].type == ParticleType.Ice)
                    {
                        this[1, -1] = new WaterP(grid, xLoc + 1, yLoc - 1);
                    }
                    Swap(this[1, -1]);
                }
            }
        }
    }
}