Form1.Designer.cs:
namespace NiklasUlvinge.ChipsEater
{
partial class Form1
{
private System.ComponentModel.IContainer components = null;
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
private void InitializeComponent()
{
System.Windows.Forms.TreeNode treeNode1 = new System.Windows.Forms.TreeNode("Cord");
System.Windows.Forms.TreeNode treeNode2 = new System.Windows.Forms.TreeNode("Transistor");
System.Windows.Forms.TreeNode treeNode3 = new System.Windows.Forms.TreeNode("Battery");
System.Windows.Forms.TreeNode treeNode4 = new System.Windows.Forms.TreeNode("lowest", new System.Windows.Forms.TreeNode[] {
treeNode1,
treeNode2,
treeNode3});
this.menuStrip1 = new System.Windows.Forms.MenuStrip();
this.toolStrip1 = new System.Windows.Forms.ToolStrip();
this.splitContainer1 = new System.Windows.Forms.SplitContainer();
this.treeItems = new System.Windows.Forms.TreeView();
this.PB = new System.Windows.Forms.PictureBox();
this.splitContainer1.Panel1.SuspendLayout();
this.splitContainer1.Panel2.SuspendLayout();
this.splitContainer1.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.PB)).BeginInit();
this.SuspendLayout();
this.menuStrip1.Location = new System.Drawing.Point(0, 0);
this.menuStrip1.Name = "menuStrip1";
this.menuStrip1.Size = new System.Drawing.Size(608, 24);
this.menuStrip1.TabIndex = 0;
this.menuStrip1.Text = "menuStrip1";
this.toolStrip1.Location = new System.Drawing.Point(0, 24);
this.toolStrip1.Name = "toolStrip1";
this.toolStrip1.Size = new System.Drawing.Size(608, 25);
this.toolStrip1.TabIndex = 1;
this.toolStrip1.Text = "toolStrip1";
this.splitContainer1.Dock = System.Windows.Forms.DockStyle.Fill;
this.splitContainer1.Location = new System.Drawing.Point(0, 49);
this.splitContainer1.Name = "splitContainer1";
this.splitContainer1.Panel1.Controls.Add(this.treeItems);
this.splitContainer1.Panel2.Controls.Add(this.PB);
this.splitContainer1.Size = new System.Drawing.Size(608, 376);
this.splitContainer1.SplitterDistance = 83;
this.splitContainer1.TabIndex = 3;
this.splitContainer1.Text = "splitContainer1";
this.treeItems.Dock = System.Windows.Forms.DockStyle.Fill;
this.treeItems.Location = new System.Drawing.Point(0, 0);
this.treeItems.Name = "treeItems";
treeNode1.Name = "NodeLst0";
treeNode1.Text = "Cord";
treeNode1.ToolTipText = "A simple current wire";
treeNode2.Name = "NodeLst1";
treeNode2.Text = "Transistor";
treeNode2.ToolTipText = "A transistor";
treeNode3.Name = "NodeLst2";
treeNode3.Text = "Battery";
treeNode3.ToolTipText = "A simple battery";
treeNode4.Name = "NodeLst";
treeNode4.Text = "lowest";
treeNode4.ToolTipText = "The lowest things of circuts";
this.treeItems.Nodes.AddRange(new System.Windows.Forms.TreeNode[] {
treeNode4});
this.treeItems.ShowRootLines = false;
this.treeItems.Size = new System.Drawing.Size(83, 376);
this.treeItems.TabIndex = 0;
this.PB.Dock = System.Windows.Forms.DockStyle.Fill;
this.PB.Location = new System.Drawing.Point(0, 0);
this.PB.Name = "PB";
this.PB.Size = new System.Drawing.Size(521, 376);
this.PB.TabIndex = 1;
this.PB.TabStop = false;
this.PB.MouseMove += new System.Windows.Forms.MouseEventHandler(this.PB_MouseMove);
this.PB.Paint += new System.Windows.Forms.PaintEventHandler(this.PB_Paint);
this.PB.MouseClick += new System.Windows.Forms.MouseEventHandler(this.PB_MouseClick);
this.PB.MouseUp += new System.Windows.Forms.MouseEventHandler(this.PB_MouseUp);
this.PB.MouseDown += new System.Windows.Forms.MouseEventHandler(this.PB_MouseDown);
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(608, 425);
this.Controls.Add(this.splitContainer1);
this.Controls.Add(this.toolStrip1);
this.Controls.Add(this.menuStrip1);
this.MainMenuStrip = this.menuStrip1;
this.Name = "Form1";
this.Text = "Form1";
this.splitContainer1.Panel1.ResumeLayout(false);
this.splitContainer1.Panel2.ResumeLayout(false);
this.splitContainer1.ResumeLayout(false);
((System.ComponentModel.ISupportInitialize)(this.PB)).EndInit();
this.ResumeLayout(false);
this.PerformLayout();
}
#endregion
private System.Windows.Forms.MenuStrip menuStrip1;
private System.Windows.Forms.ToolStrip toolStrip1;
private System.Windows.Forms.SplitContainer splitContainer1;
private System.Windows.Forms.PictureBox PB;
private System.Windows.Forms.TreeView treeItems;
}
}
Program.cs:
using System;
using System.Collections.Generic;
using System.Windows.Forms;
namespace NiklasUlvinge.ChipsEater
{
static class Program
{
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.Run(new Form1());
}
}
}
strom.cs
namespace NiklasUlvinge.ChipsEater
{
struct Strom
{
public float l, r;
public Strom(float left, float right)
{
l=left;
r = right;
}
public static Strom operator +(Strom a, Strom b)
{
return new Strom(a.l + b.l, a.r + b.r);
}
public static bool operator ==(Strom a, Strom b)
{
if (a.l == b.l && a.r == b.r)
return true;
else
return false;
}
public static bool operator !=(Strom a, Strom b)
{
return !(a == b);
}
}
}
the new item.cs file:
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Text;
namespace NiklasUlvinge.ChipsEater
{
abstract class Item
{
public Item[][] input;
public int x;
public int y;
public abstract Strom LeftOutput
{
get;
}
public abstract Strom RightOutput
{
get;
}
public abstract Point[] Snap
{
get;
}
protected Item(int X, int Y)
{
x = X;
y = Y;
input = new Item[1][];
}
public abstract void function();
public abstract void draw(Graphics g);
public void addBothInput(int index, Item Input)
{
Input.addInput(1 - index, this);
this.addInput(index, Input);
}
private void addInput(int index, Item Input)
{
index = input.Length & index;
Item[] inp = input[index];
Item[] titem;
if (inp == null)
{
titem = new Item[1];
}
else
titem = new Item[inp.Length];
for (int i = 0; i < titem.Length - 1; i++)
{
titem[i] = inp[i];
}
titem[titem.Length - 1] = Input;
input[index] = titem;
}
public Strom combinedInput(int index)
{
Strom r = new Strom(0, 0);
if (input[index] == null)
return new Strom(0, 0);
else
{
for (int i = 0; i < input[index].Length; i++)
{
if (index == 0)
r += input[index][i].LeftOutput;
else
r += input[index][i].RightOutput;
}
return r;
}
}
protected Brush surf = Brushes.LightGray;
protected Pen side = Pens.DarkGray;
protected Pen loff = Pens.Black;
protected Pen lon = Pens.Red;
}
class Null : Item
{
public override Strom LeftOutput
{
get
{
return new Strom(0, 0);
}
}
public override Strom RightOutput
{
get
{
return new Strom(0, 0);
}
}
public override Point[] Snap
{
get
{
return new Point[0];
}
}
public Null(int X, int Y)
: base(X, Y)
{
}
public override void function()
{
throw new Exception("The method or operation is not implemented.");
}
public override void draw(Graphics g)
{
throw new Exception("The method or operation is not implemented.");
}
}
class Transistor : Item
{
protected float[] output;
public Null theNull = new Null(-50, -50);
public override Strom LeftOutput
{
get
{
return new Strom(0, 0);
}
}
public override Strom RightOutput
{
get
{
return new Strom(0, 0);
}
}
public override Point[] Snap
{
get
{
return new Point[3] {
new Point(x - 16, y - 1),
new Point(x + 3, y - 16),
new Point(x + 3, y + 16)};
}
}
public Transistor(int X, int Y) : base(X, Y)
{
input = new Item[4][];
output = new float[1];
}
public override void function()
{
}
public override void draw(Graphics g)
{
IntPtr intp;
if (combinedInput(0) == new Strom(0, 0))
if (combinedInput(1) == new Strom(0, 0))
if (output[0] == 0)
intp = Properties.Resources.trans000.GetHbitmap();
else
intp = Properties.Resources.trans001.GetHbitmap();
else
if (output[0] == 0)
intp = Properties.Resources.trans010.GetHbitmap();
else
intp = Properties.Resources.trans011.GetHbitmap();
else
if (combinedInput(1) == new Strom(0, 0))
if (output[0] == 0)
intp = Properties.Resources.trans100.GetHbitmap();
else
intp = Properties.Resources.trans101.GetHbitmap();
else
if (output[0] == 0)
intp = Properties.Resources.trans110.GetHbitmap();
else
intp = Properties.Resources.trans111.GetHbitmap();
g.DrawImage(Image.FromHbitmap(intp), x - Image.FromHbitmap(intp).Size.Width / 2, y - Image.FromHbitmap(intp).Size.Height / 2);
}
}
class Cord : Item
{
public int x2, y2;
public Null theNull = new Null(-50, -50);
public override Strom LeftOutput
{
get
{
return combinedInput(1);
}
}
public override Strom RightOutput
{
get
{
return combinedInput(0);
}
}
public override Point[] Snap
{
get
{
return new Point[2] {
new Point(x, y),
new Point(x2, y2) };
}
}
public Cord(int X1, int Y1)
: base(X1, Y1)
{
input = new Item[2][];
}
public override void function()
{
}
public override void draw(Graphics g)
{
g.DrawLine(combinedInput(0) == new Strom(0,0) ? loff : lon,
x, y, x2, y2);
}
public override string ToString()
{
return "L: l" + combinedInput(1).l + " r" + combinedInput(1).l + "R: l" + combinedInput(0).l + " r" + combinedInput(0).l;
}
}
class Battery : Item
{
public Null theNull = new Null(-50, -50);
public override Strom LeftOutput
{
get
{
return new Strom(100,-100);
}
}
public override Strom RightOutput
{
get
{
return new Strom(-100, 100);
}
}
public override Point[] Snap
{
get
{
return new Point[2] {
new Point(x - 5, y),
new Point(x + 5, y) };
}
}
public Battery(int X, int Y)
: base(X, Y)
{
input = new Item[2][];
}
public override void function()
{
}
public override void draw(Graphics g)
{
g.DrawLine(lon, x - 2, y - 10, x - 2, y + 10);
g.DrawLine(lon, x + 2, y - 6, x + 2, y + 6);
g.DrawLine(lon, x - 2, y, x - 5, y);
g.DrawLine(lon, x + 2, y, x + 5, y);
}
public override string ToString()
{
return "L: l" + combinedInput(1).l + " r" + combinedInput(1).l + "R: l" + combinedInput(0).l + " r" + combinedInput(0).l;
}
}
}
Niklas Ulvinge aka IDK
|