add lab17

This commit is contained in:
Kaehvaman 2024-10-28 19:22:02 +04:00
parent b3b9149592
commit 78eda1475f
8 changed files with 411 additions and 7 deletions

View File

@ -154,7 +154,7 @@ int map[M][N] = {
int player_x = 1; int player_x = 1;
int player_y = 1; int player_y = 1;
enum obj_enum {empty = 0, wall = 2, gold = 3}; enum obj_enum { empty = 0, wall = 2, gold = 3 };
// TODO: do something with "empty" object // TODO: do something with "empty" object
#define INVENTORY_SIZE 4 #define INVENTORY_SIZE 4
int inventory[INVENTORY_SIZE] = { 0, 0, 15, 0 }; int inventory[INVENTORY_SIZE] = { 0, 0, 15, 0 };
@ -164,16 +164,16 @@ enum enum_ways { left, right, up, down };
void movePlayer(enum_ways 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] != wall) player_x -= 1;
break; break;
case right: case right:
if ((player_x < N - 1) and map[player_y][player_x + 1] != 2) player_x += 1; if ((player_x < N - 1) and map[player_y][player_x + 1] != wall) player_x += 1;
break; break;
case up: case up:
if ((player_y > 0) and map[player_y - 1][player_x] != 2) player_y -= 1; if ((player_y > 0) and map[player_y - 1][player_x] != wall) player_y -= 1;
break; break;
case down: case down:
if ((player_y < M - 1) and map[player_y + 1][player_x] != 2) player_y += 1; if ((player_y < M - 1) and map[player_y + 1][player_x] != wall) player_y += 1;
break; break;
} }
if (map[player_y][player_x] == gold) { if (map[player_y][player_x] == gold) {
@ -397,8 +397,6 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
(player_x + 2) * WIDTH, (player_y + 2) * HEIGHT (player_x + 2) * WIDTH, (player_y + 2) * HEIGHT
};*/ };*/
RECT textrect = { 0, 0, 100, 50 };
drawMap(hdc); drawMap(hdc);
drawPlayer(hdc); drawPlayer(hdc);
if (netToggle) drawNet(hdc); if (netToggle) drawNet(hdc);
@ -407,10 +405,17 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
else if (selected_element == wall) sprintf(count_string, "wall = %d", inventory[wall]); else if (selected_element == wall) sprintf(count_string, "wall = %d", inventory[wall]);
else sprintf(count_string, "not selected"); else sprintf(count_string, "not selected");
RECT textrect = { 0, 0, 150, 50 };
HFONT hFont = CreateFontW(23, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, DEFAULT_CHARSET, OUT_OUTLINE_PRECIS,
CLIP_DEFAULT_PRECIS, PROOF_QUALITY, VARIABLE_PITCH, TEXT("SegoeUI"));
SelectObject(hdc, hFont);
//SetBkColor(hdc, RGB(255, 0, 0)); //SetBkColor(hdc, RGB(255, 0, 0));
//SetBkMode(hdc, TRANSPARENT); //SetBkMode(hdc, TRANSPARENT);
DrawTextA(hdc, count_string, -1, &textrect, (DT_SINGLELINE | DT_TOP | DT_CENTER)); DrawTextA(hdc, count_string, -1, &textrect, (DT_SINGLELINE | DT_TOP | DT_CENTER));
DeleteObject(hFont);
EndPaint(hWnd, &ps); EndPaint(hWnd, &ps);
} }
break; break;

31
lab17/lab17.sln Normal file
View File

@ -0,0 +1,31 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.11.35222.181
MinimumVisualStudioVersion = 10.0.40219.1
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "lab17", "lab17\lab17.vcxproj", "{2B99CB20-E56D-415E-A18B-BC59994DE409}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|x64 = Debug|x64
Debug|x86 = Debug|x86
Release|x64 = Release|x64
Release|x86 = Release|x86
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{2B99CB20-E56D-415E-A18B-BC59994DE409}.Debug|x64.ActiveCfg = Debug|x64
{2B99CB20-E56D-415E-A18B-BC59994DE409}.Debug|x64.Build.0 = Debug|x64
{2B99CB20-E56D-415E-A18B-BC59994DE409}.Debug|x86.ActiveCfg = Debug|Win32
{2B99CB20-E56D-415E-A18B-BC59994DE409}.Debug|x86.Build.0 = Debug|Win32
{2B99CB20-E56D-415E-A18B-BC59994DE409}.Release|x64.ActiveCfg = Release|x64
{2B99CB20-E56D-415E-A18B-BC59994DE409}.Release|x64.Build.0 = Release|x64
{2B99CB20-E56D-415E-A18B-BC59994DE409}.Release|x86.ActiveCfg = Release|Win32
{2B99CB20-E56D-415E-A18B-BC59994DE409}.Release|x86.Build.0 = Release|Win32
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {10542F7B-5667-42D1-99B8-B3B0186CF58D}
EndGlobalSection
EndGlobal

138
lab17/lab17/lab17.vcxproj Normal file
View File

@ -0,0 +1,138 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="Debug|Win32">
<Configuration>Debug</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|Win32">
<Configuration>Release</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Debug|x64">
<Configuration>Debug</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|x64">
<Configuration>Release</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
</ItemGroup>
<PropertyGroup Label="Globals">
<VCProjectVersion>17.0</VCProjectVersion>
<Keyword>Win32Proj</Keyword>
<ProjectGuid>{2b99cb20-e56d-415e-a18b-bc59994de409}</ProjectGuid>
<RootNamespace>lab17</RootNamespace>
<WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v143</PlatformToolset>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v143</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v143</PlatformToolset>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v143</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings">
</ImportGroup>
<ImportGroup Label="Shared">
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<PropertyGroup Label="UserMacros" />
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
<GenerateDebugInformation>true</GenerateDebugInformation>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
<GenerateDebugInformation>true</GenerateDebugInformation>
</Link>
</ItemDefinitionGroup>
<ItemGroup>
<ClCompile Include="main.c" />
</ItemGroup>
<ItemGroup>
<Text Include="trace.txt" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
</Project>

View File

@ -0,0 +1,27 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<Filter Include="Исходные файлы">
<UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>
<Extensions>cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx</Extensions>
</Filter>
<Filter Include="Файлы заголовков">
<UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>
<Extensions>h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd</Extensions>
</Filter>
<Filter Include="Файлы ресурсов">
<UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier>
<Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms</Extensions>
</Filter>
</ItemGroup>
<ItemGroup>
<ClCompile Include="main.c">
<Filter>Исходные файлы</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<Text Include="trace.txt">
<Filter>Файлы ресурсов</Filter>
</Text>
</ItemGroup>
</Project>

107
lab17/lab17/main.c Normal file
View File

@ -0,0 +1,107 @@
#include <stdio.h>
long long fact(int n) {
if (n == 0) {
return 1;
}
printf_s("n=%d\n", n);
long long res = fact(n - 1) * n;
printf_s("n=%d fact(%d)=%lld res=%lld\n", n, n - 1, res / n, res);
return res;
}
void f1(int n, FILE* f) {
printf_s("%d ", n);
fprintf(f, "f1(%d) -> print(%d) \n", n, n);
if (n > 1) {
f1(n - 2, f);
fprintf(f, "f1(%d) returned \n", n - 2);
}
}
void f2(int n, FILE* f) {
if (n > 1) {
f2(n - 2, f);
fprintf(f, "f2(%d) returned \n", n - 2);
}
printf_s("%d ", n);
fprintf(f, "f2(%d) -> print(%d) \n", n, n);
}
void f3(int n, FILE* f) {
printf_s("%d ", n);
fprintf(f, "f3(%d) -> print(%d) \n", n, n);
if (n > 3) {
f3(n - 2, f);
fprintf(f, "f3(%d) returned \n", n - 2);
}
if (n == 3) {
printf_s("1 ");
fprintf(f, "f3(%d) && n == 3 -> print(%d) \n", n, 1);
}
printf_s("%d ", n);
fprintf(f, "f3(%d) -> print(%d) \n", n, n);
}
void recEGE1(int n, FILE* f) {
if (n >= 1) {
printf(" %d", n);
fprintf(f, "recEGE1(%d) && (n >= 1) == true -> print( %d) \n", n, n);
recEGE1(n - 1, f);
fprintf(f, "1)recEGE1(%d) returned\n", n - 1);
recEGE1(n - 1, f);
fprintf(f, "2)recEGE1(%d) returned \n", n - 1);
}
}
void F1(int n, FILE* f) {
if (n > 2) {
printf_s("%d\n", n);
fprintf(f, "F1(%d) -> print(%d) \n", n, n);
F1(n - 3, f);
fprintf(f, "1)F1(%d) returned\n", n - 3);
F1(n - 4, f);
fprintf(f, "2)F1(%d) returned\n", n - 4);
}
}
void F2(int n, FILE* f) {
if (n < 5) {
printf_s("%d\n", n);
fprintf(f, "F2(%d) -> print(%d) \n", n, n);
F2(n + 1, f);
fprintf(f, "1)F2(%d) returned\n", n + 1);
F2(n + 3, f);
fprintf(f, "2)F2(%d) returned\n", n + 3);
}
}
int main() {
FILE* fout = fopen("trace.txt", "w");
if (fout == NULL) {
puts("Íåâîçìîæíî ñîçäàòü ôàéë");
return;
}
//printf("%lld", fact(5)); // 1
f1(11, fout);
fprintf(fout, "\n");
printf_s("\n\n");
f2(11, fout);
fprintf(fout, "\n");
printf_s("\n\n");
f3(11, fout);
fprintf(fout, "\n");
printf_s("\n\n");
recEGE1(3, fout);
fprintf(fout, "\n");
printf_s("\n\n");
F1(10, fout);
fprintf(fout, "\n");
printf_s("\n\n");
F2(1, fout);
fclose(fout);
return 0;
}

96
lab17/lab17/trace.txt Normal file
View File

@ -0,0 +1,96 @@
f1(11) -> print(11)
f1(9) -> print(9)
f1(7) -> print(7)
f1(5) -> print(5)
f1(3) -> print(3)
f1(1) -> print(1)
f1(1) returned
f1(3) returned
f1(5) returned
f1(7) returned
f1(9) returned
f2(1) -> print(1)
f2(1) returned
f2(3) -> print(3)
f2(3) returned
f2(5) -> print(5)
f2(5) returned
f2(7) -> print(7)
f2(7) returned
f2(9) -> print(9)
f2(9) returned
f2(11) -> print(11)
f3(11) -> print(11)
f3(9) -> print(9)
f3(7) -> print(7)
f3(5) -> print(5)
f3(3) -> print(3)
f3(3) && n == 3 -> print(1)
f3(3) -> print(3)
f3(3) returned
f3(5) -> print(5)
f3(5) returned
f3(7) -> print(7)
f3(7) returned
f3(9) -> print(9)
f3(9) returned
f3(11) -> print(11)
recEGE1(3) && (n >= 1) == true -> print( 3)
recEGE1(2) && (n >= 1) == true -> print( 2)
recEGE1(1) && (n >= 1) == true -> print( 1)
1)recEGE1(0) returned
2)recEGE1(0) returned
1)recEGE1(1) returned
recEGE1(1) && (n >= 1) == true -> print( 1)
1)recEGE1(0) returned
2)recEGE1(0) returned
2)recEGE1(1) returned
1)recEGE1(2) returned
recEGE1(2) && (n >= 1) == true -> print( 2)
recEGE1(1) && (n >= 1) == true -> print( 1)
1)recEGE1(0) returned
2)recEGE1(0) returned
1)recEGE1(1) returned
recEGE1(1) && (n >= 1) == true -> print( 1)
1)recEGE1(0) returned
2)recEGE1(0) returned
2)recEGE1(1) returned
2)recEGE1(2) returned
F1(10) -> print(10)
F1(7) -> print(7)
F1(4) -> print(4)
1)F1(1) returned
2)F1(0) returned
1)F1(4) returned
F1(3) -> print(3)
1)F1(0) returned
2)F1(-1) returned
2)F1(3) returned
1)F1(7) returned
F1(6) -> print(6)
F1(3) -> print(3)
1)F1(0) returned
2)F1(-1) returned
1)F1(3) returned
2)F1(2) returned
2)F1(6) returned
F2(1) -> print(1)
F2(2) -> print(2)
F2(3) -> print(3)
F2(4) -> print(4)
1)F2(5) returned
2)F2(7) returned
1)F2(4) returned
2)F2(6) returned
1)F2(3) returned
2)F2(5) returned
1)F2(2) returned
F2(4) -> print(4)
1)F2(5) returned
2)F2(7) returned
2)F2(4) returned

Binary file not shown.