Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
S
Snake
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
KosmX
Snake
Commits
5f71bc21
Commit
5f71bc21
authored
Nov 4, 2020
by
KosmX
Browse files
Options
Downloads
Patches
Plain Diff
sssssssssssss
parent
776a4420
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
config.cfg
+1
-1
1 addition, 1 deletion
config.cfg
snake.c
+44
-4
44 additions, 4 deletions
snake.c
xperiments.c
+2
-0
2 additions, 0 deletions
xperiments.c
with
47 additions
and
5 deletions
config.cfg
+
1
−
1
View file @
5f71bc21
use_utf8
=
1
tickspeed
=
120
repeatMap
=
1
This diff is collapsed.
Click to expand it.
snake.c
+
44
−
4
View file @
5f71bc21
...
...
@@ -90,6 +90,9 @@ typedef struct food{
typedef
struct
screenData
{
Pos
pos
;
Pos
size
;
int
repeatMap
;
int
isXRepeat
;
int
isYRepeat
;
}
screenData
;
//-----------methods--------------
...
...
@@ -258,7 +261,9 @@ void rmMatrix(Matrix *map){
free
(
map
->
matrix
);
}
//Use printChar
//Use what chunk,
//witch screen coordinates?
//just the screen data
void
printChunk
(
chunk
ch
,
Pos
pos
,
screenData
*
scrDat
){
pos
.
x
-=
scrDat
->
pos
.
x
;
pos
.
y
-=
scrDat
->
pos
.
y
;
...
...
@@ -268,10 +273,42 @@ void printChunk(chunk ch, Pos pos, screenData *scrDat){
}
int
updateScreenSize
(
Matrix
*
map
,
screenData
*
scrDat
){
struct
Vec2i
size
=
getWindowSize
();
if
(
size
.
x
==
scrDat
->
size
.
x
&&
size
.
y
==
scrDat
->
size
.
y
){
return
0
;
//no change happened
}
scrDat
->
size
.
x
=
size
.
x
;
scrDat
->
size
.
y
=
size
.
y
;
if
(
scrDat
->
repeatMap
){
scrDat
->
isXRepeat
=
size
.
x
<
map
->
width
;
scrDat
->
isYRepeat
=
size
.
y
<
map
->
height
;
}
return
1
;
}
//Update screen if required
void
updateScreen
(
Matrix
*
map
,
screenData
*
scrDat
,
snakeChain
*
head
){
int
do_update
;
do_update
=
updateScreenSize
(
map
,
scrDat
);
if
(
scrDat
->
isXRepeat
){
if
(
head
->
pos
.
x
<
scrDat
->
pos
.
x
-
6
){
}
}
else
{
scrDat
->
pos
.
x
=
0
;
}
}
//Tick the game, step the snake, collect and place food.
void
tick
(
Matrix
*
map
,
screenData
*
scrDat
,
snakeChain
*
snake
){
}
//------------config loader------------
int
loadConfig
(
int
*
tickSpeed
){
int
loadConfig
(
int
*
tickSpeed
,
int
*
repeatMap
){
FILE
*
config
;
config
=
fopen
(
"config.cfg"
,
"r"
);
//int stillFile = 1; //boolean to show file is ended...
...
...
@@ -304,6 +341,9 @@ int loadConfig(int *tickSpeed){
else
if
(
strncmp
(
name
,
"tickspeed"
,
10
)
==
0
){
fscanf
(
config
,
" %d"
,
tickSpeed
);
}
else
if
(
strncmp
(
name
,
"repeatMap"
,
10
)
==
0
){
fscanf
(
config
,
" %d"
,
repeatMap
);
}
else
{
printf
(
"Unknown keyword: %s"
,
name
);
}
...
...
@@ -361,11 +401,11 @@ int core(int argc, char const *argv[])
FILE
*
f
;
Matrix
map
;
int
tickspeed
=
100
;
// if no config, default value
int
tickspeed
=
100
,
repeatMap
=
0
;
// if no config, default value
//----load config----
if
(
loadConfig
(
&
tickspeed
)){
if
(
loadConfig
(
&
tickspeed
,
&
repeatMap
)){
printf
(
"Error while loading config..."
);
}
...
...
This diff is collapsed.
Click to expand it.
xperiments.c
+
2
−
0
View file @
5f71bc21
...
...
@@ -42,8 +42,10 @@ void xp3(){
printf
(
"%c"
,
0x00
);
}
int
main
(
int
argc
,
char
const
*
argv
[])
{
12
%
5
;
xp3
();
return
0
;
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
sign in
to comment