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
2aad108b
Commit
2aad108b
authored
Mar 12, 2019
by
Nelson Phillips
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
autosave
parent
6ba21b5f
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
70 additions
and
55 deletions
+70
-55
Testings/Snake/CLICK TO PLAY.sh
Testings/Snake/CLICK TO PLAY.sh
+1
-0
Testings/Snake/Snake.cpp
Testings/Snake/Snake.cpp
+53
-38
Testings/Snake/Snake.h
Testings/Snake/Snake.h
+7
-11
Testings/Snake/SnakeTest.cpp
Testings/Snake/SnakeTest.cpp
+8
-4
Testings/Snake/Threads.cpp
Testings/Snake/Threads.cpp
+1
-1
Testings/Snake/compile.sh
Testings/Snake/compile.sh
+0
-1
No files found.
Testings/Snake/CLICK TO PLAY.sh
0 → 100644
View file @
2aad108b
g++
*
.cpp
-o
main.out
-pthread
-std
=
c++11
&&
./main.outf
\ No newline at end of file
Testings/Snake/Snake.cpp
View file @
2aad108b
...
...
@@ -5,7 +5,7 @@
#include "Snake.h"
using
namespace
std
;
bool
hi
=
true
;
Snake
bdy
;
vector
<
Body
>
parts
;
void
Snake
::
movement
(
char
input
){
...
...
@@ -54,48 +54,66 @@ vector <Body> parts;
}
void
Snake
::
draw
(){
for
(
int
i
=
0
;
i
<
14
;
i
++
){
for
(
int
q
=
0
;
q
<
30
;
q
++
){
if
(
x
<
1
)
bdy
.
over
();
if
(
y
<
1
)
bdy
.
over
();
if
(
x
>
11
)
bdy
.
over
();
if
(
y
>
28
)
bdy
.
over
();
bool
Snake
::
draw
(){
for
(
int
i
=
0
;
i
<
29
;
i
++
){
for
(
int
q
=
0
;
q
<
60
;
q
++
){
if
(
x
<
1
)
return
false
;
if
(
y
<
1
)
return
false
;
if
(
x
>
26
)
return
false
;
if
(
y
>
57
)
return
false
;
grid
[
i
][
q
]
=
whtSpace
;
if
(
h
==
i
||
o
==
q
)
grid
[
h
][
o
]
=
'*'
;
if
(
i
==
12
||
i
==
0
||
q
==
0
||
q
==
29
){
grid
[
i
][
q
]
=
'O'
;
}
if
(
i
==
27
||
i
==
0
)
grid
[
i
][
q
]
=
'|'
;
if
(
q
==
0
||
q
==
59
)
grid
[
i
][
q
]
=
'_'
;
for
(
int
count
=
0
;
count
<
parts
.
size
();
count
++
){
grid
[
parts
[
count
].
getX
()][
parts
[
count
].
getY
()]
=
'B'
;
if
(
grid
[
parts
[
0
].
getX
()][
parts
[
0
].
getY
()]
==
'-'
)
return
false
;
if
(
count
==
0
){
if
(
direction
==
2
)
grid
[
parts
[
count
].
getX
()][
parts
[
count
].
getY
()]
=
'>'
;
else
if
(
direction
==
3
)
grid
[
parts
[
count
].
getX
()][
parts
[
count
].
getY
()]
=
'v'
;
else
if
(
direction
==
4
)
grid
[
parts
[
count
].
getX
()][
parts
[
count
].
getY
()]
=
'<'
;
else
if
(
direction
==
1
)
grid
[
parts
[
count
].
getX
()][
parts
[
count
].
getY
()]
=
'^'
;
else
grid
[
parts
[
count
].
getX
()][
parts
[
count
].
getY
()]
=
'O'
;
}
else
grid
[
parts
[
count
].
getX
()][
parts
[
count
].
getY
()]
=
'-'
;
}
if
(
i
==
x
&&
q
==
y
)
grid
[
x
][
y
]
=
'S'
;
}
}
for
(
int
i
=
0
;
i
<
14
;
i
++
){
for
(
int
i
=
0
;
i
<
29
;
i
++
){
cout
<<
endl
;
for
(
int
q
=
0
;
q
<
3
0
;
q
++
){
for
(
int
q
=
0
;
q
<
6
0
;
q
++
){
cout
<<
grid
[
i
][
q
]
<<
" "
;
grid
[
i
][
q
]
==
' '
;
}
}
if
(
grid
[
x
][
y
]
==
grid
[
h
][
o
]
){
h
=
(
rand
()
%
11
)
+
1
;
o
=
(
rand
()
%
21
)
+
1
;
h
=
(
rand
()
%
26
)
+
1
;
o
=
(
rand
()
%
57
)
+
1
;
score
++
;
bdy
.
lengthed
();
bdy
.
newBody
();
bonusBody
=
bonusBody
+
2
;
}
else
if
(
bonusBody
>
0
){
bdy
.
newBody
();
bonusBody
--
;
}
return
true
;
}
int
Snake
::
snekoScore
(){
return
score
;
...
...
@@ -113,25 +131,22 @@ if (grid [x][y] == grid[h][o] ){
int
Snake
::
getY
(){
return
y
;
}
int
Snake
::
getLeng
(){
return
length
;
}
void
Snake
::
lengthed
(){
length
++
;
}
void
Snake
::
newBody
(){
void
Snake
::
newBody
(){
Body
segment
(
x
,
y
);
parts
.
push_back
(
segment
);
}
void
Snake
::
over
(){
quitbool
=
true
;
void
Snake
::
GameOver
(){
for
(
int
p
=
0
;
p
<
40
;
p
++
){
cout
<<
endl
;
}
bool
Snake
::
quit
(){
return
quitbool
;
}
cout
<<
" _____ ____"
<<
endl
<<
" / ____| / __ | "
<<
endl
<<
" | | __ __ _ _ __ ___ ___ | | | |_ _____ _ __"
<<
endl
<<
" | | |_ |/ _` | '_ ` _ | / _ | | | | || | / / _ | '__|"
<<
endl
<<
" | |__| | (_| | | | | | | __/ | |__| || V / __/ |"
<<
endl
<<
" |_____||__,_|_| |_| |_||___| |____/ |_/ |___|_|"
<<
endl
;
}
...
...
Testings/Snake/Snake.h
View file @
2aad108b
...
...
@@ -8,7 +8,7 @@
class
Snake
{
public:
void
movement
(
char
input
);
void
draw
();
bool
draw
();
int
snekoScore
();
void
clrScreen
();
void
bodied
();
...
...
@@ -16,20 +16,16 @@ class Snake {
int
getX
();
int
getY
();
void
newBody
();
void
lengthed
();
int
getLeng
();
void
over
();
bool
quit
();
void
GameOver
();
private:
int
x
=
5
,
y
=
5
,
i
=
0
,
q
=
0
,
score
=
0
,
h
=
(
rand
()
%
14
),
o
=
(
rand
()
%
14
);
char
grid
[
15
][
30
]
;
int
randChar
=
(
rand
()
%
5
)
;
int
x
=
13
,
y
=
13
,
i
=
0
,
q
=
0
,
score
=
0
,
h
=
13
,
o
=
23
;
char
grid
[
30
][
60
]
;
char
whtSpace
=
' '
;
int
direction
=
5
;
int
length
=
-
1
;
bool
quitbool
=
false
;
int
bonusBody
=
0
;
};
...
...
Testings/Snake/SnakeTest.cpp
View file @
2aad108b
...
...
@@ -4,16 +4,17 @@
#include "Snake.h"
#include <thread>
#include <vector>
#include <time.h>
using
namespace
std
;
bool
hello
=
true
;
Snake
BrdSet
;
Thread
Sneko
;
ReadInput
inputRead
;
void
charCall
()
{
while
(
!
BrdSet
.
quit
()
){
while
(
hello
){
BrdSet
.
input
=
inputRead
.
collectInput
();
if
(
BrdSet
.
input
==
'q'
||
BrdSet
.
input
==
'Q'
)
break
;
...
...
@@ -22,7 +23,7 @@ void charCall() {
}
void
snakePrint
(){
while
(
!
BrdSet
.
quit
()
){
while
(
hello
){
Sneko
.
Sleep
(
1
);
system
(
"stty cooked"
);
...
...
@@ -36,13 +37,16 @@ void charCall() {
cout
<<
"Your score is : "
<<
BrdSet
.
snekoScore
()
<<
endl
;
BrdSet
.
draw
();
hello
=
BrdSet
.
draw
();
if
(
hello
==
false
)
BrdSet
.
GameOver
();
system
(
"stty raw"
);
}
}
int
main
()
{
srand
(
time
(
NULL
));
BrdSet
.
newBody
();
thread
first
(
charCall
);
// spawn new thread that calls input()
...
...
Testings/Snake/Threads.cpp
View file @
2aad108b
...
...
@@ -4,6 +4,6 @@
#include "Threads.h"
void
Thread
::
Sleep
(
float
s
){
int
sec
=
int
(
s
*
25
0000
);
int
sec
=
int
(
s
*
13
0000
);
usleep
(
sec
);
}
\ No newline at end of file
Testings/Snake/compile.sh
deleted
100644 → 0
View file @
6ba21b5f
g++
*
.cpp
-o
main.out
-pthread
-std
=
c++11
&&
./main.out
\ 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