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
1291831e
Commit
1291831e
authored
Feb 27, 2019
by
Nelson Phillips
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
autosave
parent
c3fed2f8
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
41 additions
and
109 deletions
+41
-109
Testings/Game.cpp
Testings/Game.cpp
+0
-89
Testings/Nelson's YEET/thread.cpp
Testings/Nelson's YEET/thread.cpp
+17
-20
Testings/Nelson's YEET/threadClass.h
Testings/Nelson's YEET/threadClass.h
+13
-0
Testings/Nelson's YEET/threadFunc.cpp
Testings/Nelson's YEET/threadFunc.cpp
+11
-0
No files found.
Testings/Game.cpp
deleted
100644 → 0
View file @
c3fed2f8
#include <iostream>
#include <vector>
#include <stdio.h>
#include <unistd.h>
using
namespace
std
;
void
Sleep
(
float
s
)
{
int
sec
=
int
(
s
*
100000
);
usleep
(
sec
);
}
main
(){
char
grid
[
15
][
15
];
int
x
=
0
;
int
y
=
0
;
int
score
=
0
;
int
h
=
(
rand
()
%
14
);
int
o
=
(
rand
()
%
14
);
char
letter
=
' '
;
while
(
1
){
system
(
"stty raw"
);
// Wait for single character
char
input
=
getchar
();
// THIS IS JUST SOMETHING I THREW TOGETHER IF YOU WANT TO TRY TO UNDERSTAND HOW TO CREATE A WINDOW FOR A GAME OR SCREEN
// Reset terminal to normal "cooked" mode
if
(
input
==
'w'
||
input
==
'W'
)
x
--
;
else
if
(
input
==
'a'
||
input
==
'A'
)
y
--
;
else
if
(
input
==
's'
||
input
==
'S'
)
x
++
;
else
if
(
input
==
'd'
||
input
==
'D'
)
y
++
;
else
x
++
;
system
(
"stty cooked"
);
for
(
int
p
=
0
;
p
<
40
;
p
++
){
cout
<<
endl
;
}
for
(
int
p
=
0
;
p
<
40
;
p
++
){
cout
<<
endl
;
}
cout
<<
"Your score is : "
<<
score
<<
endl
;
for
(
int
i
=
0
;
i
<
14
;
i
++
){
cout
<<
endl
;
for
(
int
q
=
0
;
q
<
14
;
q
++
){
if
(
x
<
0
)
x
++
;
if
(
y
<
0
)
y
++
;
if
(
x
>
13
)
x
--
;
if
(
y
>
13
)
y
--
;
if
(
h
==
i
||
o
==
q
)
grid
[
h
][
o
]
=
'*'
;
if
(
i
==
x
&&
q
==
y
)
grid
[
x
][
y
]
=
'H'
;
else
if
(
i
!=
h
||
o
!=
q
)
grid
[
i
][
q
]
=
letter
;
cout
<<
grid
[
i
][
q
]
<<
" "
;
}
}
if
(
grid
[
x
][
y
]
==
grid
[
h
][
o
]
){
h
=
(
rand
()
%
14
);
o
=
(
rand
()
%
14
);
score
++
;
}
}
}
Testings/thread.cpp
→
Testings/
Nelson's YEET/
thread.cpp
View file @
1291831e
...
...
@@ -3,36 +3,35 @@
#include <thread> // std::thread
#include <unistd.h>
#include <stdio.h>
#include "threadFunc.cpp"
using
namespace
std
;
char
grid
[
15
][
15
];
char
grid
[
15
][
30
];
int
x
=
0
;
int
y
=
0
;
int
score
=
0
;
int
h
=
(
rand
()
%
14
);
int
o
=
(
rand
()
%
14
);
int
o
=
(
rand
()
%
30
);
char
letter
=
' '
;
ReadInput
inputRead
;
char
input
;
void
Sleep
(
float
s
)
{
int
sec
=
int
(
s
*
50
0000
);
int
sec
=
int
(
s
*
25
0000
);
usleep
(
sec
);
}
void
foo
()
{
void
charCall
()
{
for
(
int
i
=
0
;
i
<
5000
;
i
++
){
system
(
"stty raw"
);
input
=
getchar
();
system
(
"stty cooked"
);
input
=
inputRead
.
collectInput
();
}
}
void
bar
(){
void
snakePrint
(){
for
(
int
i
=
0
;
i
<
5000
;
i
++
){
Sleep
(
1
);
system
(
"stty cooked"
);
...
...
@@ -59,11 +58,11 @@ void foo() {
for
(
int
i
=
0
;
i
<
14
;
i
++
){
cout
<<
endl
;
for
(
int
q
=
0
;
q
<
14
;
q
++
){
for
(
int
q
=
0
;
q
<
30
;
q
++
){
if
(
x
<
0
)
x
++
;
if
(
y
<
0
)
y
++
;
if
(
x
>
1
3
)
x
--
;
if
(
y
>
13
)
y
--
;
if
(
x
>
1
2
)
x
--
;
if
(
y
>
29
)
y
--
;
if
(
h
==
i
||
o
==
q
)
grid
[
h
][
o
]
=
'*'
;
if
(
i
==
x
&&
q
==
y
)
...
...
@@ -76,21 +75,19 @@ void foo() {
}
}
if
(
grid
[
x
][
y
]
==
grid
[
h
][
o
]
){
h
=
(
rand
()
%
1
4
);
o
=
(
rand
()
%
14
);
h
=
(
rand
()
%
1
3
);
o
=
(
rand
()
%
30
);
score
++
;
}
system
(
"stty raw"
);
system
(
"stty raw"
);
}
}
int
main
()
{
thread
first
(
foo
);
// spawn new thread that calls foo
()
thread
second
(
bar
);
// spawn new thread that calls bar
(0)
cout
<<
"main,
foo and bar
now execute concurrently...
\n
"
;
thread
first
(
charCall
);
// spawn new thread that calls input
()
thread
second
(
snakePrint
);
// spawn new thread that calls snakePrint
(0)
cout
<<
"main,
input and snakePrint
now execute concurrently...
\n
"
;
// synchronize threads:
first
.
join
();
// pauses until first finishes
...
...
Testings/Nelson's YEET/threadClass.h
0 → 100644
View file @
1291831e
#ifndef THREADCLASS_H
#define THREADCLASS_H
#include <iostream>
class
ReadInput
{
public
:
char
collectInput
();
private:
char
inputCh
;
};
#endif
Testings/Nelson's YEET/threadFunc.cpp
0 → 100644
View file @
1291831e
#include <iostream>
#include <stdio.h>
#include "threadClass.h"
char
ReadInput
::
collectInput
(){
system
(
"stty raw"
);
inputCh
=
getchar
();
system
(
"stty cooked"
);
return
inputCh
;
}
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