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
1e61c7ef
Commit
1e61c7ef
authored
Mar 11, 2019
by
Nelson Phillips
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
autosave
parent
6317fec5
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
36 additions
and
19 deletions
+36
-19
Testings/Snake/Snake.cpp
Testings/Snake/Snake.cpp
+28
-17
Testings/Snake/Snake.h
Testings/Snake/Snake.h
+7
-2
Testings/Snake/SnakeTest.cpp
Testings/Snake/SnakeTest.cpp
+1
-0
No files found.
Testings/Snake/Snake.cpp
View file @
1e61c7ef
...
...
@@ -30,32 +30,26 @@ vector <Body> parts;
if
(
direction
==
1
){
x
--
;
for
(
int
count
=
0
;
count
<
parts
.
size
();
count
++
){
parts
[
count
].
changeX
(
1
);
}
parts
[
0
].
changeX
(
1
);
}
else
if
(
direction
==
4
){
y
--
;
for
(
int
count
=
0
;
count
<
parts
.
size
();
count
++
){
parts
[
count
].
changeY
(
1
);
}
parts
[
0
].
changeY
(
1
);
}
else
if
(
direction
==
3
){
x
++
;
for
(
int
count
=
0
;
count
<
parts
.
size
();
count
++
){
parts
[
count
].
changeX
(
0
);
}
parts
[
0
].
changeX
(
0
);
}
else
if
(
direction
==
2
){
y
++
;
for
(
int
count
=
0
;
count
<
parts
.
size
();
count
++
){
parts
[
count
].
changeY
(
0
);
}
parts
[
0
].
changeY
(
0
);
}
for
(
int
count
=
0
;
count
<
parts
.
size
()
-
1
;
count
++
){
parts
[
count
+
1
].
follow
(
count
);
}
}
...
...
@@ -126,11 +120,14 @@ if (grid [x][y] == grid[h][o] ){
}
void
Snake
::
newBody
(){
Body
segment
(
x
,
y
);
//parts[bdy.getLeng()].getX(), parts[bdy.getLeng()].getY()
Body
segment
(
parts
[
bdy
.
getLeng
()].
getX
(),
parts
[
bdy
.
getLeng
()].
getY
());
parts
.
push_back
(
segment
);
}
void
Snake
::
firstbody
(){
Body
segment
(
x
,
y
);
parts
.
push_back
(
segment
);
}
...
...
@@ -138,6 +135,8 @@ if (grid [x][y] == grid[h][o] ){
void
Body
::
changeX
(
bool
updown
){
lastX
=
x
;
if
(
updown
)
x
--
;
else
...
...
@@ -145,6 +144,7 @@ if (grid [x][y] == grid[h][o] ){
}
void
Body
::
changeY
(
bool
updown
){
lastY
=
y
;
if
(
updown
)
y
--
;
else
...
...
@@ -152,7 +152,7 @@ if (grid [x][y] == grid[h][o] ){
}
Body
::
Body
(
int
&
xCord
,
int
&
yCord
){
Body
::
Body
(
int
xCord
,
int
yCord
){
x
=
xCord
;
y
=
yCord
;
}
...
...
@@ -163,5 +163,16 @@ if (grid [x][y] == grid[h][o] ){
int
Body
::
getY
(){
return
y
;
}
int
Body
::
getlastX
(){
return
lastX
;
}
int
Body
::
getlastY
(){
return
lastY
;
}
\ No newline at end of file
void
Body
::
follow
(
int
count
){
x
=
parts
[
count
].
getlastX
();
y
=
parts
[
count
].
getlastY
();
}
\ No newline at end of file
Testings/Snake/Snake.h
View file @
1e61c7ef
...
...
@@ -16,6 +16,7 @@ class Snake {
int
getX
();
int
getY
();
void
newBody
();
void
firstbody
();
void
lengthed
();
int
getLeng
();
private:
...
...
@@ -25,7 +26,7 @@ class Snake {
int
randChar
=
(
rand
()
%
5
);
char
whtSpace
=
' '
;
int
direction
=
5
;
int
length
=
0
;
int
length
=
-
1
;
};
...
...
@@ -33,13 +34,17 @@ class Snake {
class
Body
{
public:
Body
(
int
&
xCord
,
int
&
yCord
);
Body
(
int
xCord
,
int
yCord
);
int
getX
();
int
getY
();
void
changeX
(
bool
updown
);
void
changeY
(
bool
updown
);
void
follow
(
int
count
);
int
getlastX
();
int
getlastY
();
private:
int
x
,
y
;
int
lastX
,
lastY
;
char
piece
;
};
#endif
\ No newline at end of file
Testings/Snake/SnakeTest.cpp
View file @
1e61c7ef
...
...
@@ -43,6 +43,7 @@ void charCall() {
}
int
main
()
{
BrdSet
.
firstbody
();
thread
first
(
charCall
);
// spawn new thread that calls input()
thread
second
(
snakePrint
);
// spawn new thread that calls snakePrint(0)
...
...
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