Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Gabriela Tričáková
zsi
Commits
a824a1d3
Commit
a824a1d3
authored
Feb 22, 2018
by
Gabriela Tričáková
Browse files
prva verzia
parents
Changes
3
Hide whitespace changes
Inline
Side-by-side
README.md
0 → 100644
View file @
a824a1d3
# Piskvorky
Jednoducha implementacia hry piskvorky v C
Obsah:
*
piskvorky.h - hlavickovy subor
*
piskvorky.c - samotna implementacia hry
*
README.md - tento readme subor
## Preklad
```
bash
gcc
-std
=
c11
-Wall
-Werror
piskvorky.c
-o
piskvorky
```
piskvorky.c
0 → 100644
View file @
a824a1d3
#include
<stdio.h>
#include
<stdlib.h>
int
main
()
{
printf
(
"Enter the size of field: "
);
int
size
;
scanf
(
"%d"
,
&
size
);
char
field
[
size
];
for
(
int
i
=
0
;
i
<
size
;
i
++
)
{
field
[
i
]
=
' '
;
}
draw
(
field
,
size
);
char
player
=
'B'
;
while
(
!
isSolved
(
field
,
size
))
{
player
=
(
player
==
'A'
)
?
'B'
:
'A'
;
printf
(
"Player %c: "
,
player
);
int
position
;
scanf
(
"%d"
,
&
position
);
int
cross
=
addCross
(
field
,
size
,
position
);
if
(
cross
==
-
1
)
{
printf
(
"Wrong position!
\n
"
);
continue
;
}
else
if
(
cross
==
0
)
{
printf
(
"X is already there!
\n
"
);
continue
;
}
draw
(
field
,
size
);
}
printf
(
"Player %c wins!
\n
"
,
player
);
return
EXIT_SUCCESS
;
}
void
draw
(
char
field
[],
int
size
)
{
printf
(
"
\n
"
);
for
(
int
i
=
0
;
i
<
size
;
i
++
)
{
printf
(
" %d"
,
i
+
1
);
}
printf
(
"
\n
"
);
printf
(
"+"
);
for
(
int
i
=
0
;
i
<
size
;
i
++
)
{
printf
(
"-+"
);
}
printf
(
"
\n
"
);
printf
(
"|"
);
for
(
int
i
=
0
;
i
<
size
;
i
++
)
{
printf
(
"%c|"
,
field
[
i
]);
}
printf
(
"
\n
"
);
printf
(
"+"
);
for
(
int
i
=
0
;
i
<
size
;
i
++
)
{
printf
(
"-+"
);
}
printf
(
"
\n
"
);
}
int
addCross
(
char
field
[],
int
size
,
int
position
)
{
if
(
position
<
0
||
position
>
size
){
return
-
1
;
}
if
(
field
[
position
-
1
]
==
'X'
){
return
0
;
}
field
[
position
-
1
]
=
'X'
;
return
1
;
}
int
isSolved
(
char
field
[],
int
size
)
{
for
(
int
i
=
0
;
i
<
size
-
2
;
i
++
){
if
(
field
[
i
]
==
'X'
&&
field
[
i
+
1
]
==
'X'
&&
field
[
i
+
2
]
==
'X'
){
return
1
;
}
}
return
0
;
}
piskvorky.h
0 → 100644
View file @
a824a1d3
int
isSolved
(
char
field
[],
int
size
);
int
addCross
(
char
field
[],
int
size
,
int
position
);
void
draw
(
char
field
[],
int
size
);
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment