Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
1
142GameCenter
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Incidents
Environments
Packages & Registries
Packages & Registries
Package Registry
Container Registry
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Nelson Phillips
142GameCenter
Commits
ac635381
Commit
ac635381
authored
Mar 12, 2019
by
Nelson Phillips
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
autosave
parent
962b4c8a
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
30 additions
and
24 deletions
+30
-24
Testings/Snake/Snake.cpp
Testings/Snake/Snake.cpp
+24
-22
Testings/Snake/Snake.h
Testings/Snake/Snake.h
+4
-0
Testings/Snake/SnakeTest.cpp
Testings/Snake/SnakeTest.cpp
+2
-2
No files found.
Testings/Snake/Snake.cpp
View file @
ac635381
...
...
@@ -8,7 +8,6 @@ using namespace std;
Snake
bdy
;
vector
<
Body
>
parts
;
void
Snake
::
movement
(
char
input
){
if
((
input
==
'w'
||
input
==
'W'
)
&&
direction
!=
3
)
direction
=
1
;
...
...
@@ -48,8 +47,8 @@ vector <Body> parts;
parts
[
0
].
changeY
(
0
);
}
for
(
int
count
=
0
;
count
<
parts
.
size
()
-
1
;
count
++
){
if
(
count
!=
0
)
for
(
int
count
=
0
;
count
<
parts
.
size
();
count
++
){
if
(
count
!=
0
)
parts
[
count
].
follow
(
count
);
}
}
...
...
@@ -58,29 +57,26 @@ vector <Body> parts;
void
Snake
::
draw
(){
for
(
int
i
=
0
;
i
<
14
;
i
++
){
for
(
int
q
=
0
;
q
<
30
;
q
++
){
if
(
x
<
1
)
x
++
;
if
(
y
<
1
)
y
++
;
if
(
x
>
11
)
x
--
;
if
(
y
>
28
)
y
--
;
if
(
x
<
1
)
bdy
.
over
();
if
(
y
<
1
)
bdy
.
over
();
if
(
x
>
11
)
bdy
.
over
();
if
(
y
>
28
)
bdy
.
over
();
grid
[
i
][
q
]
=
whtSpace
;
if
(
h
==
i
||
o
==
q
)
grid
[
h
][
o
]
=
'*'
;
if
(
i
==
x
&&
q
==
y
)
grid
[
x
][
y
]
=
'S'
;
if
((
i
!=
h
||
o
!=
q
)
&&
(
i
!=
x
||
q
!=
y
))
grid
[
i
][
q
]
=
whtSpace
;
if
(
i
==
12
||
i
==
0
||
q
==
0
||
q
==
29
){
grid
[
i
][
q
]
=
'O'
;
}
for
(
int
count
=
0
;
count
<
parts
.
size
();
count
++
){
grid
[
parts
[
count
].
getX
()][
parts
[
count
].
getY
()]
=
'B'
;
}
}
for
(
int
count
=
0
;
count
<
parts
.
size
();
count
++
){
grid
[
parts
[
count
].
getX
()][
parts
[
count
].
getY
()]
=
'B'
;
}
if
(
i
==
x
&&
q
==
y
)
grid
[
x
][
y
]
=
'S'
;
}
}
...
...
@@ -100,7 +96,6 @@ if (grid [x][y] == grid[h][o] ){
bdy
.
lengthed
();
bdy
.
newBody
();
}
}
int
Snake
::
snekoScore
(){
return
score
;
...
...
@@ -129,7 +124,14 @@ if (grid [x][y] == grid[h][o] ){
Body
segment
(
x
,
y
);
parts
.
push_back
(
segment
);
}
void
Snake
::
over
(){
quitbool
=
true
;
}
bool
Snake
::
quit
(){
return
quitbool
;
}
...
...
Testings/Snake/Snake.h
View file @
ac635381
...
...
@@ -18,6 +18,9 @@ class Snake {
void
newBody
();
void
lengthed
();
int
getLeng
();
void
over
();
bool
quit
();
private:
int
x
=
5
,
y
=
5
,
i
=
0
,
q
=
0
,
score
=
0
,
h
=
(
rand
()
%
14
),
o
=
(
rand
()
%
14
);
...
...
@@ -26,6 +29,7 @@ class Snake {
char
whtSpace
=
' '
;
int
direction
=
5
;
int
length
=
-
1
;
bool
quitbool
=
false
;
};
...
...
Testings/Snake/SnakeTest.cpp
View file @
ac635381
...
...
@@ -13,7 +13,7 @@ Thread Sneko;
ReadInput
inputRead
;
void
charCall
()
{
while
(
1
){
while
(
!
BrdSet
.
quit
()
){
BrdSet
.
input
=
inputRead
.
collectInput
();
if
(
BrdSet
.
input
==
'q'
||
BrdSet
.
input
==
'Q'
)
break
;
...
...
@@ -22,7 +22,7 @@ void charCall() {
}
void
snakePrint
(){
while
(
1
){
while
(
!
BrdSet
.
quit
()
){
Sneko
.
Sleep
(
1
);
system
(
"stty cooked"
);
...
...
Write
Preview
Markdown
is supported
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