using System;
namespace Shapes
{
///
/// Класс Square — потомок класса Rect.
///
public class Square: Rect
{
public Square(int side, int x, int y): base(side,side,x,у)
{
//квадрат — это прямоугольник с равными сторонами
}
}
}
Класс
Этот класс является прямым потомком класса
namespace Shapes
{
///
/// Класс Person — потомок класса Figure,
/// клиент классов Circle, Rect, LittleCircle.
///
public class Person: Figure
{
int head_h;
Circle head;
Rect body;
LittleCircle nose;
public Person (int head_h, int x, int y): base(x,y)
{
// head_h — радиус головы, x,y — ее центр.
// остальные размеры исчисляются относительно
// размера головы.
this.head_h = head_h;
head = new Circle(head_h,x,у);
int body_x = x;
int body_y = у + 3*head_h;
int body_w =2*head_h;
int body_h = 4*head_h;
body = new Rect(body_w, body_h, body_x,body_y);
nose = new LittleCircle (x+head_h +2, y);
}
public override void Show(System.Drawing.Graphics g,
System.Drawing.Pen pen, System.Drawing.Brush brush)
{
int h = Convert.ToInt32(head_h*scale);
//head
int top_x = center.X — h;
int top_y = center.Y — h;
g. DrawEllipse(pen, top_x,top_y, 2*h,2*h);
g. FillEllipse(brush, top_x,top_y, 2*h,2*h);
//body
top_y += 2*h;
g. DrawRectangle(pen, top_x,top_y, 2*h,4*h);
g. FillRectangle(brush, top_x,top_y, 2*h,4*h);
//nose
top_y — =h; top_x += 2*h;
g. DrawEllipse(pen, top_x,top_y, 8,8);
g. FillEllipse(brush, top_x,top_y, 8,8);
}
public override System.Drawing.Rectangle
Region_Capture()
{
int h = Convert.ToInt32(head_h*scale);
int top_x = center.X — h;
int top_y = center.Y — h;
return new
System.Drawing.Rectangle(top_x,top_y,2*h,2*h);
}
}
}
Список с курсором. Динамические структуры данных
Добавим в проект классы, задающие динамические структуры данных. Конечно, можно было бы воспользоваться стандартными… Но для обучения крайне полезно уметь создавать собственные задающие такие структуры данных. Список с курсором — один из важнейших образцов подобных классов: