shape.cs

来自「Beginning C# Game Programming 的源代码」· CS 代码 · 共 50 行

CS
50
字号
using System;
using System.Drawing;
using System.Collections;
using Microsoft.DirectX;
using Microsoft.DirectX.DirectDraw;

namespace SpaceWar {
	/// <summary>
	///Shape drawing class
	/// </summary>
	public class Shape {
		Point center;
		ArrayList lines = new ArrayList();

		public Shape() {
		}

		public Point Center {
			get {
				return center;
			}
			set {
				center = value;
			}
		}

		public Line this[int index] {
			get {
				return (Line) lines[index];
			}
		}

		public void AddLine(PointF end1, PointF end2, float scale) {
			Point e1 = new Point((int) (end1.X * scale), (int) (end1.Y * scale));
			Point e2 = new Point((int) (end2.X * scale), (int) (end2.Y * scale));

			lines.Add(new Line(e1, e2));
		}

		public void Draw(Surface surface, int startIndex, int endIndex) {
			for (int index = startIndex; index <= endIndex; index++) {
				Line line = (Line) lines[index];

				line.Offset = center;
				line.Draw(surface);
			}
		}
	}
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?