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
dde00b28
Commit
dde00b28
authored
Mar 11, 2019
by
Nelson Phillips
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
autosave
parent
4c19275a
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
70 additions
and
31 deletions
+70
-31
Testings/Snake/Snake.cpp
Testings/Snake/Snake.cpp
+64
-29
Testings/Snake/Snake.h
Testings/Snake/Snake.h
+6
-2
No files found.
Testings/Snake/Snake.cpp
View file @
dde00b28
...
@@ -6,8 +6,8 @@
...
@@ -6,8 +6,8 @@
using
namespace
std
;
using
namespace
std
;
bool
hi
=
0
;
Snake
bdy
;
vector
<
Body
>
parts
;
vector
<
Body
>
parts
;
void
Snake
::
movement
(
char
input
){
void
Snake
::
movement
(
char
input
){
...
@@ -26,58 +26,77 @@ vector <Body> parts;
...
@@ -26,58 +26,77 @@ vector <Body> parts;
if
((
input
==
'd'
||
input
==
'D'
)
&&
direction
!=
4
)
if
((
input
==
'd'
||
input
==
'D'
)
&&
direction
!=
4
)
direction
=
2
;
direction
=
2
;
if
(
direction
==
1
)
if
(
direction
==
1
)
{
x
--
;
x
--
;
for
(
int
count
=
0
;
count
<
parts
.
size
();
count
++
){
parts
[
count
].
changeX
(
1
);
}
}
else
else
if
(
direction
==
4
)
if
(
direction
==
4
)
{
y
--
;
y
--
;
for
(
int
count
=
0
;
count
<
parts
.
size
();
count
++
){
parts
[
count
].
changeY
(
1
);
}
}
else
else
if
(
direction
==
3
)
if
(
direction
==
3
)
{
x
++
;
x
++
;
for
(
int
count
=
0
;
count
<
parts
.
size
();
count
++
){
parts
[
count
].
changeX
(
0
);
}
}
else
else
if
(
direction
==
2
)
if
(
direction
==
2
)
{
y
++
;
y
++
;
for
(
int
count
=
0
;
count
<
parts
.
size
();
count
++
){
parts
[
count
].
changeY
(
0
);
}
}
}
}
void
Snake
::
draw
(){
void
Snake
::
draw
(){
for
(
int
i
=
0
;
i
<
14
;
i
++
){
for
(
int
i
=
0
;
i
<
14
;
i
++
){
cout
<<
endl
;
for
(
int
q
=
0
;
q
<
30
;
q
++
){
for
(
int
q
=
0
;
q
<
30
;
q
++
){
if
(
x
<
0
)
x
++
;
if
(
x
<
0
)
x
++
;
if
(
y
<
0
)
y
++
;
if
(
y
<
0
)
y
++
;
if
(
x
>
12
)
x
--
;
if
(
x
>
12
)
x
--
;
if
(
y
>
29
)
y
--
;
if
(
y
>
29
)
y
--
;
for
(
int
count
=
0
;
count
<
parts
.
size
();
count
++
){
if
((
parts
[
count
].
getX
()
==
x
-
1
)
&&
(
parts
[
count
].
getY
()
==
y
-
1
))
grid
[
i
-
1
][
q
-
1
]
=
'B'
;
}
if
(
i
==
x
&&
q
==
y
)
grid
[
x
][
y
]
=
'S'
;
else
if
(
h
==
i
||
o
==
q
)
if
(
h
==
i
||
o
==
q
)
grid
[
h
][
o
]
=
'*'
;
grid
[
h
][
o
]
=
'*'
;
else
if
(
i
!=
h
||
o
!=
q
)
if
(
i
==
x
&&
q
==
y
)
grid
[
x
][
y
]
=
'S'
;
if
((
i
!=
h
||
o
!=
q
)
&&
(
i
!=
x
||
q
!=
y
))
grid
[
i
][
q
]
=
whtSpace
;
grid
[
i
][
q
]
=
whtSpace
;
for
(
int
count
=
0
;
count
<
parts
.
size
();
count
++
){
grid
[
parts
[
count
].
getX
()][
parts
[
count
].
getY
()]
=
'B'
;
}
}
}
for
(
int
i
=
0
;
i
<
14
;
i
++
){
cout
<<
endl
;
for
(
int
q
=
0
;
q
<
30
;
q
++
){
cout
<<
grid
[
i
][
q
]
<<
" "
;
cout
<<
grid
[
i
][
q
]
<<
" "
;
}
grid
[
i
][
q
]
==
' '
;
}
}
}
if
(
grid
[
x
][
y
]
==
grid
[
h
][
o
]
){
if
(
grid
[
x
][
y
]
==
grid
[
h
][
o
]
){
h
=
(
rand
()
%
13
);
h
=
(
rand
()
%
13
);
o
=
(
rand
()
%
30
);
o
=
(
rand
()
%
30
);
score
++
;
score
++
;
bdy
.
lengthed
();
bdy
.
newBody
();
}
}
}
}
...
@@ -100,13 +119,24 @@ if (grid [x][y] == grid[h][o] ){
...
@@ -100,13 +119,24 @@ if (grid [x][y] == grid[h][o] ){
void
Snake
::
newBody
(){
void
Snake
::
newBody
(){
Body
segment
(
x
,
y
);
Body
segment
(
x
-
length
,
y
);
cout
<<
x
<<
endl
<<
x
<<
endl
<<
x
<<
endl
<<
x
<<
endl
<<
x
<<
endl
<<
x
<<
endl
<<
x
<<
endl
<<
x
<<
endl
<<
x
<<
endl
<<
x
<<
endl
<<
x
<<
endl
;
parts
.
push_back
(
segment
);
parts
.
push_back
(
segment
);
}
}
void
Body
::
changeX
(
bool
updown
){
if
(
updown
)
x
--
;
else
x
++
;
}
void
Body
::
changeY
(
bool
updown
){
if
(
updown
)
y
--
;
else
y
++
;
}
Body
::
Body
(
int
xCord
,
int
yCord
){
Body
::
Body
(
int
xCord
,
int
yCord
){
...
@@ -119,4 +149,9 @@ if (grid [x][y] == grid[h][o] ){
...
@@ -119,4 +149,9 @@ if (grid [x][y] == grid[h][o] ){
}
}
int
Body
::
getY
(){
int
Body
::
getY
(){
return
y
;
return
y
;
}
}
\ No newline at end of file
void
Snake
::
lengthed
(){
length
++
;
}
\ No newline at end of file
Testings/Snake/Snake.h
View file @
dde00b28
...
@@ -16,13 +16,15 @@ class Snake {
...
@@ -16,13 +16,15 @@ class Snake {
int
getX
();
int
getX
();
int
getY
();
int
getY
();
void
newBody
();
void
newBody
();
void
lengthed
();
private:
private:
int
x
=
0
,
y
=
0
,
i
=
0
,
q
=
0
,
score
=
0
,
int
x
=
5
,
y
=
5
,
i
=
0
,
q
=
0
,
score
=
0
,
h
=
(
rand
()
%
14
),
o
=
(
rand
()
%
14
);
h
=
(
rand
()
%
14
),
o
=
(
rand
()
%
14
);
char
grid
[
15
][
30
];
char
grid
[
15
][
30
];
int
randChar
=
(
rand
()
%
5
);
int
randChar
=
(
rand
()
%
5
);
char
whtSpace
=
' '
;
char
whtSpace
=
' '
;
int
direction
=
5
;
int
direction
=
5
;
int
length
=
0
;
};
};
...
@@ -33,8 +35,10 @@ class Body {
...
@@ -33,8 +35,10 @@ class Body {
Body
(
int
xCord
,
int
yCord
);
Body
(
int
xCord
,
int
yCord
);
int
getX
();
int
getX
();
int
getY
();
int
getY
();
void
changeX
(
bool
updown
);
void
changeY
(
bool
updown
);
private:
private:
int
x
,
y
,
length
;
int
x
,
y
;
char
piece
;
char
piece
;
};
};
#endif
#endif
\ No newline at end of file
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