Skip to content

Commit 85d3d9f

Browse files
committed
Hang Man (Forca):
-Deleted useless header file and integrated its contents into the main source file Genius (Simon): -Changed name to Simon (original name of the game) -Created (still blank)
1 parent 3db4e47 commit 85d3d9f

File tree

11 files changed

+256
-60
lines changed

11 files changed

+256
-60
lines changed

Atividades de Aula.sln

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Jogo da Velha", "Jogo da Ve
77
EndProject
88
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Lig 4", "Lig 4\Lig 4.vcxproj", "{0644F248-5E49-477A-BAD7-7FCA86DA135A}"
99
EndProject
10-
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Genius", "Genius\Genius.vcxproj", "{97AD3B54-D0D8-45CD-ABAC-D591E179E54A}"
11-
EndProject
1210
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Forca", "Forca\Forca.vcxproj", "{E42D6209-08C2-41E3-A600-C199645ADC2C}"
1311
EndProject
1412
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Batalha Naval", "Batalha Naval\Batalha Naval.vcxproj", "{EE58612E-920A-4BC3-8567-0AEB20070867}"
1513
EndProject
14+
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Simon", "Simon\Simon.vcxproj", "{108814A1-98EE-47AA-8749-2BFDAFC780E0}"
15+
EndProject
1616
Global
1717
GlobalSection(SolutionConfigurationPlatforms) = preSolution
1818
Debug|x64 = Debug|x64
@@ -37,14 +37,6 @@ Global
3737
{0644F248-5E49-477A-BAD7-7FCA86DA135A}.Release|x64.Build.0 = Release|x64
3838
{0644F248-5E49-477A-BAD7-7FCA86DA135A}.Release|x86.ActiveCfg = Release|Win32
3939
{0644F248-5E49-477A-BAD7-7FCA86DA135A}.Release|x86.Build.0 = Release|Win32
40-
{97AD3B54-D0D8-45CD-ABAC-D591E179E54A}.Debug|x64.ActiveCfg = Debug|x64
41-
{97AD3B54-D0D8-45CD-ABAC-D591E179E54A}.Debug|x64.Build.0 = Debug|x64
42-
{97AD3B54-D0D8-45CD-ABAC-D591E179E54A}.Debug|x86.ActiveCfg = Debug|Win32
43-
{97AD3B54-D0D8-45CD-ABAC-D591E179E54A}.Debug|x86.Build.0 = Debug|Win32
44-
{97AD3B54-D0D8-45CD-ABAC-D591E179E54A}.Release|x64.ActiveCfg = Release|x64
45-
{97AD3B54-D0D8-45CD-ABAC-D591E179E54A}.Release|x64.Build.0 = Release|x64
46-
{97AD3B54-D0D8-45CD-ABAC-D591E179E54A}.Release|x86.ActiveCfg = Release|Win32
47-
{97AD3B54-D0D8-45CD-ABAC-D591E179E54A}.Release|x86.Build.0 = Release|Win32
4840
{E42D6209-08C2-41E3-A600-C199645ADC2C}.Debug|x64.ActiveCfg = Debug|x64
4941
{E42D6209-08C2-41E3-A600-C199645ADC2C}.Debug|x64.Build.0 = Debug|x64
5042
{E42D6209-08C2-41E3-A600-C199645ADC2C}.Debug|x86.ActiveCfg = Debug|Win32
@@ -61,6 +53,14 @@ Global
6153
{EE58612E-920A-4BC3-8567-0AEB20070867}.Release|x64.Build.0 = Release|x64
6254
{EE58612E-920A-4BC3-8567-0AEB20070867}.Release|x86.ActiveCfg = Release|Win32
6355
{EE58612E-920A-4BC3-8567-0AEB20070867}.Release|x86.Build.0 = Release|Win32
56+
{108814A1-98EE-47AA-8749-2BFDAFC780E0}.Debug|x64.ActiveCfg = Debug|x64
57+
{108814A1-98EE-47AA-8749-2BFDAFC780E0}.Debug|x64.Build.0 = Debug|x64
58+
{108814A1-98EE-47AA-8749-2BFDAFC780E0}.Debug|x86.ActiveCfg = Debug|Win32
59+
{108814A1-98EE-47AA-8749-2BFDAFC780E0}.Debug|x86.Build.0 = Debug|Win32
60+
{108814A1-98EE-47AA-8749-2BFDAFC780E0}.Release|x64.ActiveCfg = Release|x64
61+
{108814A1-98EE-47AA-8749-2BFDAFC780E0}.Release|x64.Build.0 = Release|x64
62+
{108814A1-98EE-47AA-8749-2BFDAFC780E0}.Release|x86.ActiveCfg = Release|Win32
63+
{108814A1-98EE-47AA-8749-2BFDAFC780E0}.Release|x86.Build.0 = Release|Win32
6464
EndGlobalSection
6565
GlobalSection(SolutionProperties) = preSolution
6666
HideSolutionNode = FALSE

Forca/Forca.vcxproj

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
</ItemGroup>
2525
<ItemGroup>
2626
<ClInclude Include="ansi_escapes.h" />
27-
<ClInclude Include="forca.h" />
2827
</ItemGroup>
2928
<PropertyGroup Label="Globals">
3029
<VCProjectVersion>16.0</VCProjectVersion>

Forca/Forca.vcxproj.filters

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,6 @@
2323
</ClCompile>
2424
</ItemGroup>
2525
<ItemGroup>
26-
<ClInclude Include="forca.h">
27-
<Filter>Arquivos de Cabeçalho</Filter>
28-
</ClInclude>
2926
<ClInclude Include="ansi_escapes.h">
3027
<Filter>Arquivos de Cabeçalho</Filter>
3128
</ClInclude>

Forca/forca.c

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,30 @@
11
#define _CRT_SECURE_NO_WARNINGS
2-
#include "forca.h"
32
#include "ansi_escapes.h"
43
#include <stdio.h>
54
#include <string.h>
65
#include <stdbool.h>
76

7+
typedef struct WordInfo {
8+
char word[30];
9+
int numberOfLetters;
10+
char tip[40];
11+
}Word;
12+
13+
typedef struct Coordinates {
14+
int row, col;
15+
}Coordinate;
16+
17+
typedef enum BodyParts {
18+
HANG,
19+
HEAD,
20+
UPPER_BODY,
21+
LEFT_ARM,
22+
RIGHT_ARM,
23+
LOWER_BODY,
24+
LEFT_LEG,
25+
RIGHT_LEG
26+
}Body;
27+
828
void letterArrayCreator(char letters[28][3][5])
929
{
1030
char a[3][5] = { {'_', '_', '_', '_', ' '},
@@ -314,14 +334,13 @@ void screenPrinter(char hangMan[8][11], char* tip, Word word, char* alreadyChoos
314334

315335
moveUp(7);
316336
int alreadyChoosenLettersCounter = 0;
317-
for (int count1 = 0; count1 < 7; count1++)
337+
for (int count1 = 0; count1 < 6; count1++)
318338
{
319339
for (int count2 = 0; count2 < 6; count2++)
320340
{
321341
if (alreadyChoosenLetters[alreadyChoosenLettersCounter] == '\0' || alreadyChoosenLetters[alreadyChoosenLettersCounter] == ' ')
322342
{
323343
printf("%c", alreadyChoosenLetters[alreadyChoosenLettersCounter]);
324-
break;
325344
}
326345
else
327346
printf("%c", alreadyChoosenLetters[alreadyChoosenLettersCounter] - 32);

Forca/forca.h

Lines changed: 0 additions & 26 deletions
This file was deleted.

Genius/genius.h

Lines changed: 0 additions & 5 deletions
This file was deleted.

Genius/Genius.vcxproj renamed to Simon/Simon.vcxproj

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,18 +19,17 @@
1919
</ProjectConfiguration>
2020
</ItemGroup>
2121
<ItemGroup>
22-
<ClCompile Include="..\Lig 4\ansi_escapes.c" />
23-
<ClCompile Include="genius.c" />
22+
<ClCompile Include="ansi_escapes.c" />
23+
<ClCompile Include="simon.c" />
2424
</ItemGroup>
2525
<ItemGroup>
26-
<ClInclude Include="..\Lig 4\ansi_escapes.h" />
27-
<ClInclude Include="genius.h" />
26+
<ClInclude Include="ansi_escapes.h" />
2827
</ItemGroup>
2928
<PropertyGroup Label="Globals">
3029
<VCProjectVersion>16.0</VCProjectVersion>
31-
<ProjectGuid>{97AD3B54-D0D8-45CD-ABAC-D591E179E54A}</ProjectGuid>
30+
<ProjectGuid>{108814A1-98EE-47AA-8749-2BFDAFC780E0}</ProjectGuid>
3231
<Keyword>Win32Proj</Keyword>
33-
<RootNamespace>Genius</RootNamespace>
32+
<RootNamespace>Simon</RootNamespace>
3433
<WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion>
3534
</PropertyGroup>
3635
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />

Genius/Genius.vcxproj.filters renamed to Simon/Simon.vcxproj.filters

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,18 +15,15 @@
1515
</Filter>
1616
</ItemGroup>
1717
<ItemGroup>
18-
<ClCompile Include="..\Lig 4\ansi_escapes.c">
18+
<ClCompile Include="simon.c">
1919
<Filter>Arquivos de Origem</Filter>
2020
</ClCompile>
21-
<ClCompile Include="genius.c">
21+
<ClCompile Include="ansi_escapes.c">
2222
<Filter>Arquivos de Origem</Filter>
2323
</ClCompile>
2424
</ItemGroup>
2525
<ItemGroup>
26-
<ClInclude Include="..\Lig 4\ansi_escapes.h">
27-
<Filter>Arquivos de Cabeçalho</Filter>
28-
</ClInclude>
29-
<ClInclude Include="genius.h">
26+
<ClInclude Include="ansi_escapes.h">
3027
<Filter>Arquivos de Cabeçalho</Filter>
3128
</ClInclude>
3229
</ItemGroup>

Simon/ansi_escapes.c

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
#ifdef _WIN32
2+
#define _CRT_SECURE_NO_WARNINGS 1
3+
#include <windows.h>
4+
#else
5+
#include <termios.h>
6+
#include <unistd.h>
7+
#endif
8+
9+
#include <stdio.h>
10+
#include <stdlib.h>
11+
12+
#ifdef _WIN32
13+
// Some old MinGW/CYGWIN distributions don't define this:
14+
#ifndef ENABLE_VIRTUAL_TERMINAL_PROCESSING
15+
#define ENABLE_VIRTUAL_TERMINAL_PROCESSING 0x0004
16+
#endif
17+
18+
static HANDLE stdoutHandle, stdinHandle;
19+
static DWORD outModeInit, inModeInit;
20+
21+
void setupConsole(void) {
22+
DWORD outMode = 0, inMode = 0;
23+
stdoutHandle = GetStdHandle(STD_OUTPUT_HANDLE);
24+
stdinHandle = GetStdHandle(STD_INPUT_HANDLE);
25+
26+
if (stdoutHandle == INVALID_HANDLE_VALUE || stdinHandle == INVALID_HANDLE_VALUE) {
27+
exit(GetLastError());
28+
}
29+
30+
if (!GetConsoleMode(stdoutHandle, &outMode) || !GetConsoleMode(stdinHandle, &inMode)) {
31+
exit(GetLastError());
32+
}
33+
34+
outModeInit = outMode;
35+
inModeInit = inMode;
36+
37+
// Enable ANSI escape codes
38+
outMode |= ENABLE_VIRTUAL_TERMINAL_PROCESSING;
39+
40+
// Set stdin as no echo and unbuffered
41+
inMode &= ~(ENABLE_ECHO_INPUT | ENABLE_LINE_INPUT);
42+
43+
if (!SetConsoleMode(stdoutHandle, outMode) || !SetConsoleMode(stdinHandle, inMode)) {
44+
exit(GetLastError());
45+
}
46+
}
47+
48+
void restoreConsoleMode(void) {
49+
if (!SetConsoleMode(stdoutHandle, outModeInit) || !SetConsoleMode(stdinHandle, inModeInit)) {
50+
exit(GetLastError());
51+
}
52+
}
53+
54+
void restoreConsole(void) {
55+
// Reset colors
56+
printf("\x1b[0m");
57+
58+
// Reset console mode
59+
if (!SetConsoleMode(stdoutHandle, outModeInit) || !SetConsoleMode(stdinHandle, inModeInit)) {
60+
exit(GetLastError());
61+
}
62+
}
63+
#else
64+
65+
static struct termios orig_term;
66+
static struct termios new_term;
67+
68+
void setupConsole(void) {
69+
tcgetattr(STDIN_FILENO, &orig_term);
70+
new_term = orig_term;
71+
72+
new_term.c_lflag &= ~(ICANON | ECHO);
73+
74+
tcsetattr(STDIN_FILENO, TCSANOW, &new_term);
75+
}
76+
77+
void restoreConsole(void) {
78+
// Reset colors
79+
printf("\x1b[0m");
80+
81+
// Reset console mode
82+
tcsetattr(STDIN_FILENO, TCSANOW, &orig_term);
83+
}
84+
#endif
85+
86+
void getCursorPosition(int* row, int* col) {
87+
printf("\x1b[6n");
88+
char buff[128];
89+
int indx = 0;
90+
for (;;) {
91+
int cc = getchar();
92+
buff[indx] = (char)cc;
93+
indx++;
94+
if (cc == 'R') {
95+
buff[indx + 1] = '\0';
96+
break;
97+
}
98+
}
99+
sscanf(buff, "\x1b[%d;%dR", row, col);
100+
fseek(stdin, 0, SEEK_END);
101+
}

0 commit comments

Comments
 (0)