Simplified drawNet() and created putElement()
This commit is contained in:
parent
f6d50cae54
commit
fc61facbb1
@ -154,8 +154,8 @@ int map[M][N] = {
|
|||||||
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
|
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
|
||||||
};
|
};
|
||||||
|
|
||||||
enum enum_moves { left, right, up, down };
|
enum enum_ways { left, right, up, down };
|
||||||
void movePlayer(enum_moves move) {
|
void movePlayer(enum_ways move) {
|
||||||
switch (move) {
|
switch (move) {
|
||||||
case left:
|
case left:
|
||||||
if ((player_x > 0) and map[player_y][player_x - 1] != 2) player_x -= 1;
|
if ((player_x > 0) and map[player_y][player_x - 1] != 2) player_x -= 1;
|
||||||
@ -176,15 +176,32 @@ void movePlayer(enum_moves move) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void drawNet(HDC hdc, int width, int height, int step) {
|
void putElement(enum_ways way, int element) {
|
||||||
for (int i = 0; i <= width; i = i + step) {
|
switch (way) {
|
||||||
MoveToEx(hdc, i, 0, NULL);
|
case left:
|
||||||
LineTo(hdc, i, height);
|
if ((player_x > 0) and map[player_y][player_x - 1] == 0) map[player_y][player_x - 1] = element;
|
||||||
|
break;
|
||||||
|
case right:
|
||||||
|
if ((player_x < N - 1) and map[player_y][player_x + 1] == 0) map[player_y][player_x + 1] = element;
|
||||||
|
break;
|
||||||
|
case up:
|
||||||
|
if ((player_y > 0) and map[player_y - 1][player_x] == 0) map[player_y - 1][player_x] = element;
|
||||||
|
break;
|
||||||
|
case down:
|
||||||
|
if ((player_y < M - 1) and map[player_y + 1][player_x] == 0) map[player_y + 1][player_x] = element;
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int i = 0; i <= height; i = i + step) {
|
void drawNet(HDC hdc) {
|
||||||
|
for (int i = 0; i <= N * WIDTH; i = i + WIDTH) {
|
||||||
|
MoveToEx(hdc, i, 0, NULL);
|
||||||
|
LineTo(hdc, i, M*HEIGHT);
|
||||||
|
}
|
||||||
|
|
||||||
|
for (int i = 0; i <= M * HEIGHT; i = i + HEIGHT) {
|
||||||
MoveToEx(hdc, 0, i, NULL);
|
MoveToEx(hdc, 0, i, NULL);
|
||||||
LineTo(hdc, width, i);
|
LineTo(hdc, N * WIDTH, i);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -321,12 +338,9 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
|
|||||||
HDC hdc = BeginPaint(hWnd, &ps);
|
HDC hdc = BeginPaint(hWnd, &ps);
|
||||||
// TODO: Добавьте сюда любой код прорисовки, использующий HDC...
|
// TODO: Добавьте сюда любой код прорисовки, использующий HDC...
|
||||||
|
|
||||||
RECT rect;
|
|
||||||
GetClientRect(hWnd, &rect);
|
|
||||||
|
|
||||||
drawMap(hdc);
|
drawMap(hdc);
|
||||||
drawPlayer(hdc);
|
drawPlayer(hdc);
|
||||||
if (netToggle) drawNet(hdc, rect.right, rect.bottom, 40);
|
if (netToggle) drawNet(hdc);
|
||||||
|
|
||||||
EndPaint(hWnd, &ps);
|
EndPaint(hWnd, &ps);
|
||||||
}
|
}
|
||||||
@ -355,6 +369,8 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
|
|||||||
case VK_A:
|
case VK_A:
|
||||||
movePlayer(left);
|
movePlayer(left);
|
||||||
break;
|
break;
|
||||||
|
case VK_L:
|
||||||
|
putElement(right, 2);
|
||||||
}
|
}
|
||||||
InvalidateRect(hWnd, NULL, FALSE);
|
InvalidateRect(hWnd, NULL, FALSE);
|
||||||
break;
|
break;
|
||||||
|
@ -142,6 +142,9 @@
|
|||||||
<Image Include="lab16.ico" />
|
<Image Include="lab16.ico" />
|
||||||
<Image Include="small.ico" />
|
<Image Include="small.ico" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<Text Include="savefile.txt" />
|
||||||
|
</ItemGroup>
|
||||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
||||||
<ImportGroup Label="ExtensionTargets">
|
<ImportGroup Label="ExtensionTargets">
|
||||||
</ImportGroup>
|
</ImportGroup>
|
||||||
|
@ -46,4 +46,9 @@
|
|||||||
<Filter>Файлы ресурсов</Filter>
|
<Filter>Файлы ресурсов</Filter>
|
||||||
</Image>
|
</Image>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<Text Include="savefile.txt">
|
||||||
|
<Filter>Файлы ресурсов</Filter>
|
||||||
|
</Text>
|
||||||
|
</ItemGroup>
|
||||||
</Project>
|
</Project>
|
Loading…
Reference in New Issue
Block a user