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
34ac98cf
Commit
34ac98cf
authored
Mar 11, 2019
by
Nelson Phillips
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
autosave
parent
541cb824
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
78 additions
and
38 deletions
+78
-38
Testings/Snake/Snake.cpp
Testings/Snake/Snake.cpp
+57
-26
Testings/Snake/Snake.h
Testings/Snake/Snake.h
+10
-3
Testings/Snake/SnakeTest.cpp
Testings/Snake/SnakeTest.cpp
+11
-9
No files found.
Testings/Snake/Snake.cpp
View file @
34ac98cf
...
...
@@ -6,6 +6,10 @@
using
namespace
std
;
vector
<
Body
>
parts
;
void
Snake
::
movement
(
char
input
){
if
((
input
==
'w'
||
input
==
'W'
)
&&
direction
!=
3
)
direction
=
1
;
...
...
@@ -41,31 +45,39 @@ using namespace std;
void
Snake
::
draw
(){
for
(
int
i
=
0
;
i
<
14
;
i
++
){
cout
<<
endl
;
for
(
int
q
=
0
;
q
<
30
;
q
++
){
if
(
x
<
0
)
x
++
;
if
(
y
<
0
)
y
++
;
if
(
x
>
12
)
x
--
;
if
(
y
>
29
)
y
--
;
if
(
h
==
i
||
o
==
q
)
grid
[
h
][
o
]
=
'*'
;
if
(
i
==
x
&&
q
==
y
)
grid
[
x
][
y
]
=
'S'
;
else
if
(
i
!=
h
||
o
!=
q
)
grid
[
i
][
q
]
=
whtSpace
;
for
(
int
i
=
0
;
i
<
14
;
i
++
){
cout
<<
endl
;
for
(
int
q
=
0
;
q
<
30
;
q
++
){
if
(
x
<
0
)
x
++
;
if
(
y
<
0
)
y
++
;
if
(
x
>
12
)
x
--
;
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
cout
<<
grid
[
i
][
q
]
<<
" "
;
}
}
if
(
h
==
i
||
o
==
q
)
grid
[
h
][
o
]
=
'*'
;
else
if
(
i
!=
h
||
o
!=
q
)
grid
[
i
][
q
]
=
whtSpace
;
cout
<<
grid
[
i
][
q
]
<<
" "
;
}
}
if
(
grid
[
x
][
y
]
==
grid
[
h
][
o
]
){
h
=
(
rand
()
%
13
);
o
=
(
rand
()
%
30
);
score
++
;
h
=
(
rand
()
%
13
);
o
=
(
rand
()
%
30
);
score
++
;
}
}
...
...
@@ -79,13 +91,32 @@ score++;
}
}
int
Snake
::
getX
(){
return
x
;
}
int
Snake
::
getY
(){
return
y
;
}
void
Snake
::
bodied
(){
void
Snake
::
newBody
(){
Body
segment
(
x
,
y
);
parts
.
push_back
(
segment
);
}
\ No newline at end of file
Body
::
Body
(
int
xCord
,
int
yCord
){
x
=
xCord
;
y
=
yCord
;
}
int
Body
::
getX
(){
return
x
;
}
int
Body
::
getY
(){
return
y
;
}
\ No newline at end of file
Testings/Snake/Snake.h
View file @
34ac98cf
...
...
@@ -13,6 +13,9 @@ class Snake {
void
clrScreen
();
void
bodied
();
char
input
;
int
getX
();
int
getY
();
void
newBody
();
private:
int
x
=
0
,
y
=
0
,
i
=
0
,
q
=
0
,
score
=
0
,
h
=
(
rand
()
%
14
),
o
=
(
rand
()
%
14
);
...
...
@@ -20,14 +23,18 @@ class Snake {
int
randChar
=
(
rand
()
%
5
);
char
whtSpace
=
' '
;
int
direction
=
5
;
//vector<Body>parts();
};
class
Body
{
public:
Body
(
int
xCord
,
int
yCord
);
int
getX
();
int
getY
();
private:
int
x
,
y
;
int
x
,
y
,
length
;
char
piece
;
};
#endif
\ No newline at end of file
Testings/Snake/SnakeTest.cpp
View file @
34ac98cf
...
...
@@ -3,6 +3,8 @@
#include "Threads.h"
#include "Snake.h"
#include <thread>
#include <vector>
using
namespace
std
;
...
...
@@ -35,22 +37,22 @@ void charCall() {
cout
<<
"Your score is : "
<<
BrdSet
.
snekoScore
()
<<
endl
;
BrdSet
.
draw
();
system
(
"stty raw"
);
}
}
int
main
()
{
BrdSet
.
newBody
();
thread
first
(
charCall
);
// spawn new thread that calls input()
thread
second
(
snakePrint
);
// spawn new thread that calls snakePrint(0)
cout
<<
"Press w,a,s,d to begin."
;
// synchronize threads:
first
.
join
();
// pauses until first finishes
second
.
join
();
return
0
;
thread
first
(
charCall
);
// spawn new thread that calls input()
thread
second
(
snakePrint
);
// spawn new thread that calls snakePrint(0)
cout
<<
"Press w,a,s,d to begin."
;
// synchronize threads:
first
.
join
();
// pauses until first finishes
second
.
join
();
return
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