Merge remote-tracking branch 'origin/master'
# Conflicts: # CMakeLists.txt # main.c
This commit is contained in:
commit
1422955906
96
hangman.c
Normal file
96
hangman.c
Normal file
@ -0,0 +1,96 @@
|
||||
#include <stdio.h>
|
||||
#include "hangman.h"
|
||||
#include "termstuff.h"
|
||||
|
||||
int printWord(char *word, char *tried){
|
||||
int unknownCharacterExists = 0;
|
||||
int characterFound;
|
||||
char *p = word;
|
||||
|
||||
while (*p != 0) {
|
||||
characterFound = 0;
|
||||
for (char *triedFindptr = tried; *triedFindptr != 0; triedFindptr++) {
|
||||
if (*p == *triedFindptr) {
|
||||
putchar(*p);
|
||||
characterFound = 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!characterFound) {
|
||||
putchar('_');
|
||||
unknownCharacterExists = 1;
|
||||
}
|
||||
p++;
|
||||
}
|
||||
putchar('\n');
|
||||
return unknownCharacterExists;
|
||||
}
|
||||
|
||||
int getInput(char znak, char *tried, char **triedptr, char *word, int *fails, int maxFails) {
|
||||
int validGuess = 0;
|
||||
int characterFound;
|
||||
char *p;
|
||||
clear();
|
||||
|
||||
if(!printWord(word, tried)){
|
||||
return 1;
|
||||
}
|
||||
|
||||
printf("Zadaj znak:");
|
||||
while (validGuess == 0){
|
||||
znak = getchar();
|
||||
if(znak != '\n') { // we got a non enter character
|
||||
validGuess = 1; //presume no duplicates
|
||||
for (char *triedFindptr = tried; *triedFindptr != 0; triedFindptr++) {
|
||||
if (znak == *triedFindptr) {
|
||||
validGuess = 0; //duplicate found
|
||||
printf("Znak už bol zadaný, zadajte znova:");
|
||||
}
|
||||
}
|
||||
if(validGuess) {
|
||||
*(*triedptr)++ = znak;
|
||||
p = word;
|
||||
characterFound = 0;
|
||||
while (*p != 0) {
|
||||
if (*p == znak) {
|
||||
characterFound = 1;
|
||||
break;
|
||||
}
|
||||
p++;
|
||||
}
|
||||
if (!characterFound) {
|
||||
(*fails)++;
|
||||
if (*fails > maxFails) {
|
||||
printf("Neuhádol si ani na tento počet pokusov: %d, slovo bolo %s\n", maxFails, word);
|
||||
return 1;
|
||||
} else {
|
||||
printf("Neuhádol si, pokusov, ktoré ešte ostávajú je %d.\n", maxFails - *fails + 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
while (getchar() != '\n'); // wait for enter to ensure only one character
|
||||
return 0;
|
||||
}
|
||||
|
||||
int hangman() {
|
||||
|
||||
char word[21];
|
||||
|
||||
char tried[100];
|
||||
*tried = 0;
|
||||
char *triedptr = tried;
|
||||
char znak;
|
||||
int fails = 0;
|
||||
int maxFails = 2;
|
||||
|
||||
printf("Zadaj slovo(max 20 znakov):");
|
||||
scanf("%20s", word);
|
||||
|
||||
while (1) {
|
||||
if(getInput(znak, tried, &triedptr, word, &fails, maxFails)){
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
1
hangman.h
Normal file
1
hangman.h
Normal file
@ -0,0 +1 @@
|
||||
int hangman();
|
35
hviezdicky.c
35
hviezdicky.c
@ -4,41 +4,8 @@
|
||||
|
||||
#include "hviezdicky.h"
|
||||
#include "stdio.h"
|
||||
#include "termstuff.h"
|
||||
|
||||
void escapeStart(){
|
||||
putchar('\033');
|
||||
putchar('[');
|
||||
}
|
||||
|
||||
void escapeEnd() {
|
||||
putchar('m');
|
||||
}
|
||||
|
||||
void white() {
|
||||
escapeStart();
|
||||
putchar('3');
|
||||
putchar('7');
|
||||
putchar(';');
|
||||
putchar('4');
|
||||
putchar('0');
|
||||
escapeEnd();
|
||||
}
|
||||
|
||||
void black() {
|
||||
escapeStart();
|
||||
putchar('3');
|
||||
putchar('0');
|
||||
putchar(';');
|
||||
putchar('4');
|
||||
putchar('7');
|
||||
escapeEnd();
|
||||
}
|
||||
|
||||
void original() {
|
||||
escapeStart();
|
||||
putchar('0');
|
||||
escapeEnd();
|
||||
}
|
||||
|
||||
int stars() {
|
||||
int j; //stĺpec
|
||||
|
40
stringy.c
40
stringy.c
@ -17,45 +17,5 @@ int meno() {
|
||||
int dlzka = strlen(str);
|
||||
printf("Kópia: %s, meno: %s ,dĺžka: %d, 'a' sa nachádza na: %d mieste v zadanom texte", strkopia, str, dlzka,
|
||||
polohaAcka);
|
||||
|
||||
}
|
||||
|
||||
int stringy() {
|
||||
char word[21];
|
||||
char *p;
|
||||
char tried[100];
|
||||
char *triedptr = tried;
|
||||
printf("Zadaj slovo(max 20 znakov):");
|
||||
fgets(word, 20, stdin);
|
||||
int unknownCharacterExists = 1;
|
||||
while (unknownCharacterExists) {
|
||||
printf("Zadaj znak:");
|
||||
char znak = '\n';
|
||||
while (znak == '\n'){
|
||||
znak = getchar();
|
||||
}
|
||||
*triedptr = znak;
|
||||
triedptr++;
|
||||
p = word;
|
||||
int characterFound;
|
||||
unknownCharacterExists = 0;
|
||||
while (*p != '\n') {
|
||||
characterFound = 0;
|
||||
for (char *triedFindptr = tried; *triedFindptr != 0; triedFindptr++) {
|
||||
if (*p == *triedFindptr) {
|
||||
putchar(*p);
|
||||
characterFound = 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!characterFound) {
|
||||
putchar('_');
|
||||
unknownCharacterExists = 1;
|
||||
}
|
||||
p++;
|
||||
}
|
||||
putchar('\n');
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
@ -1,2 +1,2 @@
|
||||
int stringy();
|
||||
int meno();
|
||||
|
||||
|
51
termstuff.c
Normal file
51
termstuff.c
Normal file
@ -0,0 +1,51 @@
|
||||
#include "termstuff.h"
|
||||
#include "stdio.h"
|
||||
|
||||
void clear(){
|
||||
putchar(0x1b);
|
||||
putchar(0x5b);
|
||||
putchar(0x48);
|
||||
putchar(0x1b);
|
||||
putchar(0x5b);
|
||||
putchar(0x32);
|
||||
putchar(0x4a);
|
||||
putchar(0x1b);
|
||||
putchar(0x5b);
|
||||
putchar(0x33);
|
||||
putchar(0x4a);
|
||||
}
|
||||
|
||||
void escapeStart(){
|
||||
putchar('\033');
|
||||
putchar('[');
|
||||
}
|
||||
|
||||
void escapeEnd() {
|
||||
putchar('m');
|
||||
}
|
||||
|
||||
void white() {
|
||||
escapeStart();
|
||||
putchar('3');
|
||||
putchar('7');
|
||||
putchar(';');
|
||||
putchar('4');
|
||||
putchar('0');
|
||||
escapeEnd();
|
||||
}
|
||||
|
||||
void black() {
|
||||
escapeStart();
|
||||
putchar('3');
|
||||
putchar('0');
|
||||
putchar(';');
|
||||
putchar('4');
|
||||
putchar('7');
|
||||
escapeEnd();
|
||||
}
|
||||
|
||||
void original() {
|
||||
escapeStart();
|
||||
putchar('0');
|
||||
escapeEnd();
|
||||
}
|
6
termstuff.h
Normal file
6
termstuff.h
Normal file
@ -0,0 +1,6 @@
|
||||
void clear();
|
||||
void escapeStart();
|
||||
void escapeEnd();
|
||||
void white();
|
||||
void black();
|
||||
void original();
|
Loading…
Reference in New Issue
Block a user