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
bb95deef
Commit
bb95deef
authored
Mar 11, 2019
by
Nelson Phillips
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
autosave
parent
c9918a08
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
32 additions
and
23 deletions
+32
-23
Testings/Snake/Snake.cpp
Testings/Snake/Snake.cpp
+26
-21
Testings/Snake/Snake.h
Testings/Snake/Snake.h
+5
-1
Testings/Snake/SnakeTest.cpp
Testings/Snake/SnakeTest.cpp
+1
-1
No files found.
Testings/Snake/Snake.cpp
View file @
bb95deef
...
...
@@ -47,19 +47,21 @@ vector <Body> parts;
y
++
;
parts
[
0
].
changeY
(
0
);
}
for
(
int
count
=
0
;
count
<
parts
.
size
()
-
1
;
count
++
){
parts
[
count
+
1
].
follow
(
count
);
}
if
(
count
!=
0
)
parts
[
count
].
follow
(
count
);
}
}
void
Snake
::
draw
(){
for
(
int
i
=
0
;
i
<
14
;
i
++
){
for
(
int
q
=
0
;
q
<
30
;
q
++
){
if
(
x
<
0
)
x
++
;
if
(
y
<
0
)
y
++
;
if
(
x
>
1
2
)
x
--
;
if
(
y
>
2
9
)
y
--
;
if
(
x
<
1
)
x
++
;
if
(
y
<
1
)
y
++
;
if
(
x
>
1
1
)
x
--
;
if
(
y
>
2
8
)
y
--
;
if
(
h
==
i
||
o
==
q
)
...
...
@@ -67,9 +69,13 @@ vector <Body> parts;
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'
;
...
...
@@ -88,8 +94,8 @@ vector <Body> parts;
}
}
if
(
grid
[
x
][
y
]
==
grid
[
h
][
o
]
){
h
=
(
rand
()
%
1
3
)
;
o
=
(
rand
()
%
30
)
;
h
=
(
rand
()
%
1
1
)
+
1
;
o
=
(
rand
()
%
21
)
+
1
;
score
++
;
bdy
.
lengthed
();
bdy
.
newBody
();
...
...
@@ -120,14 +126,11 @@ if (grid [x][y] == grid[h][o] ){
}
void
Snake
::
newBody
(){
Body
segment
(
parts
[
bdy
.
getLeng
()].
getX
(),
parts
[
bdy
.
getLeng
()].
getY
()
);
Body
segment
(
x
,
y
);
parts
.
push_back
(
segment
);
}
}
void
Snake
::
firstbody
(){
Body
segment
(
x
,
y
);
parts
.
push_back
(
segment
);
}
...
...
@@ -135,8 +138,8 @@ if (grid [x][y] == grid[h][o] ){
void
Body
::
changeX
(
bool
updown
){
lastX
=
x
;
lastX
=
x
;
lastY
=
y
;
if
(
updown
)
x
--
;
else
...
...
@@ -144,12 +147,14 @@ if (grid [x][y] == grid[h][o] ){
}
void
Body
::
changeY
(
bool
updown
){
lastX
=
x
;
lastY
=
y
;
if
(
updown
)
y
--
;
else
y
++
;
}
}
Body
::
Body
(
int
xCord
,
int
yCord
){
...
...
@@ -170,9 +175,9 @@ if (grid [x][y] == grid[h][o] ){
return
lastY
;
}
void
Body
::
follow
(
int
count
){
x
=
parts
[
count
].
getlastX
();
y
=
parts
[
count
].
getlastY
();
lastX
=
x
;
lastY
=
y
;
x
=
parts
[
count
-
1
].
getlastX
();
y
=
parts
[
count
-
1
].
getlastY
();
}
\ No newline at end of file
Testings/Snake/Snake.h
View file @
bb95deef
...
...
@@ -16,7 +16,6 @@ class Snake {
int
getX
();
int
getY
();
void
newBody
();
void
firstbody
();
void
lengthed
();
int
getLeng
();
private:
...
...
@@ -34,6 +33,7 @@ class Snake {
class
Body
{
public:
Body
(
int
xCord
,
int
yCord
);
int
getX
();
int
getY
();
...
...
@@ -42,7 +42,11 @@ class Body {
void
follow
(
int
count
);
int
getlastX
();
int
getlastY
();
void
setLast
(
int
count
);
private:
int
x
,
y
;
int
lastX
,
lastY
;
char
piece
;
...
...
Testings/Snake/SnakeTest.cpp
View file @
bb95deef
...
...
@@ -43,7 +43,7 @@ void charCall() {
}
int
main
()
{
BrdSet
.
firstb
ody
();
BrdSet
.
newB
ody
();
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