1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
| class kvadrat:public TImage
{
protected:
int a,x,y;
public:
kvadrat(int na=15): TImage(this)
{a=na;
}
void Show();
};
class Kletka:public kvadrat
{
protected:
bool l,r,d,u;
public:
Kletka(int nl,int nr,int nd,int nu)
{
l=nl;
r=nr;
d=nd;
u=nu;
}
};
class field:public kvadrat
{
protected:
int CellSize;//размер клетки в пикселях
Kletka KL[10][10];
public:
field();
void Show();
};
class Player:public TImage
{
private:
int R;
TColor c;
public:
Player(int l,int t,TColor nc,int nR) ;
void Move();
void Draw();
};
Файл myClass.cpp
Player::Player(int l,int t,TColor nc,int nR)
{
Left=l;
Top=t;
c=nc;
R=nR;
}
void field::Show()
{
int Mas[11][22]={
{1,0,1,1,0,1,1,1,0,1,1,1,1,1,0,1,1,1,1,1,1,0},
{1,0,0,0,1,0,0,1,1,0,0,1,0,0,1,1,1,0,0,1,1,0},
{1,1,0,0,1,0,0,1,0,0,1,0,0,1,0,0,0,0,1,0,1,0},
{1,1,1,1,0,0,1,0,0,0,0,1,1,0,1,0,0,1,0,0,1,0},
{1,0,1,0,0,1,1,1,1,0,1,0,0,1,0,1,0,0,1,1,1,0},
{1,0,1,0,0,0,0,0,0,1,1,0,1,1,0,0,0,0,1,0,1,0},
{1,0,0,1,0,0,1,0,1,0,1,0,0,1,0,0,1,1,1,0,1,0},
{1,0,1,0,0,0,1,0,1,0,0,0,1,0,1,1,0,0,0,0,1,0},
{1,1,0,1,0,0,1,1,1,1,0,0,1,0,1,0,1,1,1,0,1,0},
{1,1,1,0,1,1,0,0,0,0,0,0,0,1,0,0,0,0,1,0,0,0},
{0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,0},
};
int x,y;
int Cellsize=30;
x=0;
y=0;
for(int i=1;i<=11;i++)
{
Form1->Image2->Canvas->MoveTo(x,y);
for(int j=1;j<=11;j++)
{
if(Mas[i-1][2*(j-1)]==1)
{
Form1->Image2->Canvas->LineTo(x,y+Cellsize);
Form1->Image2->Canvas->MoveTo(x,y);
}
if(Mas[i-1][2*(j-1)+1]==1)
Form1->Image2->Canvas->LineTo(x+Cellsize,y);
x=x+Cellsize;
Form1->Image2->Canvas->MoveTo(x,y);
}
x=0;
y=y+Cellsize;
}
}
void Player::Draw()
{
c=6;
Canvas->Brush->Color=c;
Canvas->Ellipse(0,0,R,R);
}
void Player::Move(int n)
{
switch( n)
{
case 0:if ((x>0)&& Mas[x-1][y] !=1) x--;break;
case 1:if (y>0 && Mas[x][y-1] !=1) y--;break;
case 2: if (x<11 && Mas[x+1][y] !=1) x++;break;
case 3: if (y<22 && Mas[x][y+1] !=1) y++;break;
}
Draw();
} |