This repository has been archived by the owner on May 13, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Functions.cpp
86 lines (69 loc) · 1.73 KB
/
Functions.cpp
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
//CFunction
//Contains various functions, that might come in handy
#include "CFunctions.h"
//Funktion: allocate
//Aufgabe: T1 mit T2 füllen
void CFunctions::allocate(char* chT1, char* chT2)
{
for (unsigned int i = 0; i<strlen(chT2) + 1; i++)
chT1[i] = chT2[i];
}
//Funktion: Fehler
//Aufgabe: Einen variablen Fehler ausgeben
void CFunctions::error(const char chText[])
{
CColor C;
cout << C.red() << "\a" << chText << C.resetAll();
}
//Funktion: Compare
//Aufgabe: Zwei Strings vergleichen
bool CFunctions::compare(char* chT1, char* chT2)
{
if (strlen(chT1) != strlen(chT2))
return false;
for (unsigned int i = 0; i<strlen(chT1); i++)
{
if (chT1[i] != chT2[i])
return false;
}
return true;
}
//contains:
//Functions: checks, whether string1 conains sring two
bool CFunctions::contains(char* chText, char* chContains)
{
for(unsigned int i=0; i<strlen(chText); i++)
{
unsigned int counter = 0;
for(unsigned int j=0; j<strlen(chContains); j++)
{
if(chText[i+j] == chContains[j])
{
counter++;
if(counter == strlen(chContains)-1)
return true;
}
else
break;
}
}
return false;
}
//Funktion: ClearMemory
//Aufgabe: Einen String leeren
void CFunctions::clearMemory(char* chT)
{
for (unsigned int i = 0; i<sizeof(chT); i++)
chT[i] = '\0';
}
//Functions: checkField
//Check if the outlines of the Field are reached
bool CFunctions::checkField(int ymax, int xmax, int y, int x)
{
if (y > ymax || y < 0)
return false;
else if (x > xmax || x < 0)
return false;
else
return true;
}