Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
G
GBS
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
CS375
GBS
Commits
b8239737
Commit
b8239737
authored
Sep 4, 2024
by
Jake Dreher
Browse files
Options
Downloads
Patches
Plain Diff
Implement zoomed view
parent
36a43ce3
Branches
Branches containing commit
No related tags found
1 merge request
!13
8 deadplayers
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/game/game.js
+37
-2
37 additions, 2 deletions
src/game/game.js
src/models/WebSocketModel.js
+13
-11
13 additions, 11 deletions
src/models/WebSocketModel.js
with
50 additions
and
13 deletions
src/game/game.js
+
37
−
2
View file @
b8239737
...
@@ -302,7 +302,42 @@ module.exports = {
...
@@ -302,7 +302,42 @@ module.exports = {
getPlayerView
:
(
gameBoard
,
pid
)
=>
{
getPlayerView
:
(
gameBoard
,
pid
)
=>
{
let
updatedBoard
=
gameBoard
.
map
((
row
)
=>
row
.
map
((
cell
)
=>
({
...
cell
})));
let
updatedBoard
=
gameBoard
.
map
((
row
)
=>
row
.
map
((
cell
)
=>
({
...
cell
})));
// YANG: Find head with pid = pid
// return [x][y] around head
let
width
=
5
;
let
height
=
5
;
let
head
=
null
;
for
(
var
i
=
0
;
i
<
updatedBoard
.
length
;
i
++
)
{
for
(
var
j
=
0
;
j
<
updatedBoard
[
i
].
length
;
j
++
)
{
let
cell
=
updatedBoard
[
i
][
j
];
if
(
cell
.
type
===
cellTypes
.
PLAYERHEAD
&&
cell
.
pid
===
pid
)
{
console
.
log
(
"
MY Player head found at:
"
,
cell
.
x
,
cell
.
y
);
head
=
cell
;
}
}
}
if
(
head
===
null
)
{
return
[];
}
let
playerView
=
[];
for
(
var
i
=
0
;
i
<=
height
;
i
++
)
{
let
row
=
[];
for
(
var
j
=
0
;
j
<=
width
;
j
++
)
{
let
x
=
head
.
x
+
j
-
Math
.
floor
(
width
/
2
);
let
y
=
head
.
y
+
i
-
Math
.
floor
(
height
/
2
);
if
(
x
<
0
||
x
>=
updatedBoard
[
0
].
length
||
y
<
0
||
y
>=
updatedBoard
.
length
)
{
row
.
push
(
cellTypes
.
BORDER
);
}
else
{
row
.
push
(
updatedBoard
[
y
][
x
]);
}
}
playerView
.
push
(
row
);
}
return
playerView
;
},
},
};
};
This diff is collapsed.
Click to expand it.
src/models/WebSocketModel.js
+
13
−
11
View file @
b8239737
...
@@ -27,7 +27,7 @@ class WebSocketModel {
...
@@ -27,7 +27,7 @@ class WebSocketModel {
if
(
deadPlayers
.
length
>
0
)
{
if
(
deadPlayers
.
length
>
0
)
{
for
(
let
conn
of
this
.
games
[
game
].
players
)
{
for
(
let
conn
of
this
.
games
[
game
].
players
)
{
conn
.
send
(
conn
.
connection
.
send
(
JSON
.
stringify
({
JSON
.
stringify
({
type
:
"
deadPlayers
"
,
type
:
"
deadPlayers
"
,
data
:
deadPlayers
,
data
:
deadPlayers
,
...
@@ -37,14 +37,15 @@ class WebSocketModel {
...
@@ -37,14 +37,15 @@ class WebSocketModel {
}
}
for
(
let
conn
of
this
.
games
[
game
].
players
)
{
for
(
let
conn
of
this
.
games
[
game
].
players
)
{
conn
.
send
(
let
playerView
=
gameModule
.
getPlayerView
(
this
.
games
[
game
].
gameBoard
,
conn
.
pid
);
conn
.
connection
.
send
(
JSON
.
stringify
({
JSON
.
stringify
({
type
:
"
gameBoard
"
,
type
:
"
gameBoard
"
,
data
:
this
.
games
[
game
].
gameBoard
,
// YANG: gameModule.getPlayerView()...
data
:
playerView
,
// YANG: gameModule.getPlayerView()...
}),
}),
);
);
}
}
},
10
00
);
},
5
00
);
}
}
constructor
()
{
constructor
()
{
this
.
connections
=
[];
this
.
connections
=
[];
...
@@ -148,13 +149,13 @@ class WebSocketModel {
...
@@ -148,13 +149,13 @@ class WebSocketModel {
let
roomId
=
connection
.
protocol
;
let
roomId
=
connection
.
protocol
;
if
(
!
this
.
games
[
roomId
].
started
)
{
if
(
!
this
.
games
[
roomId
].
started
)
{
this
.
games
[
roomId
].
players
.
push
(
connection
);
this
.
games
[
roomId
].
players
.
push
(
{
connection
,
pid
:
this
.
games
[
roomId
].
players
.
length
+
1
}
);
this
.
games
[
roomId
].
gameBoard
=
gameModule
.
addPlayer
(
this
.
games
[
roomId
].
gameBoard
=
gameModule
.
addPlayer
(
this
.
games
[
roomId
].
gameBoard
,
this
.
games
[
roomId
].
gameBoard
,
this
.
games
[
roomId
].
players
.
length
,
this
.
games
[
roomId
].
players
.
length
,
);
);
}
else
{
}
else
{
this
.
games
[
roomId
].
players
.
push
(
connection
);
this
.
games
[
roomId
].
players
.
push
(
{
connection
,
pid
:
this
.
games
[
roomId
].
players
.
length
+
1
}
);
}
}
connection
.
send
(
connection
.
send
(
...
@@ -165,6 +166,7 @@ class WebSocketModel {
...
@@ -165,6 +166,7 @@ class WebSocketModel {
);
);
connection
.
on
(
"
close
"
,
()
=>
{
connection
.
on
(
"
close
"
,
()
=>
{
// Need to fix this
this
.
games
[
roomId
].
players
=
this
.
games
[
roomId
].
players
.
filter
(
this
.
games
[
roomId
].
players
=
this
.
games
[
roomId
].
players
.
filter
(
(
curr
)
=>
curr
!==
this
.
games
[
roomId
].
players
,
(
curr
)
=>
curr
!==
this
.
games
[
roomId
].
players
,
);
);
...
@@ -182,7 +184,7 @@ class WebSocketModel {
...
@@ -182,7 +184,7 @@ class WebSocketModel {
}
else
if
(
message
.
type
===
"
chat
"
)
{
}
else
if
(
message
.
type
===
"
chat
"
)
{
console
.
log
(
"
Received chat:
"
+
message
.
data
);
console
.
log
(
"
Received chat:
"
+
message
.
data
);
for
(
let
conn
of
this
.
games
[
roomId
].
players
)
{
for
(
let
conn
of
this
.
games
[
roomId
].
players
)
{
conn
.
send
(
conn
.
connection
.
send
(
JSON
.
stringify
({
JSON
.
stringify
({
type
:
"
chat
"
,
type
:
"
chat
"
,
data
:
message
.
data
,
data
:
message
.
data
,
...
@@ -193,7 +195,7 @@ class WebSocketModel {
...
@@ -193,7 +195,7 @@ class WebSocketModel {
}
else
if
(
message
.
type
===
"
join
"
)
{
}
else
if
(
message
.
type
===
"
join
"
)
{
console
.
log
(
"
Received join:
"
+
message
.
data
);
console
.
log
(
"
Received join:
"
+
message
.
data
);
for
(
let
conn
of
this
.
games
[
roomId
].
players
)
{
for
(
let
conn
of
this
.
games
[
roomId
].
players
)
{
conn
.
send
(
conn
.
connection
.
send
(
JSON
.
stringify
({
JSON
.
stringify
({
type
:
"
playerJoined
"
,
type
:
"
playerJoined
"
,
data
:
message
.
data
,
data
:
message
.
data
,
...
@@ -207,8 +209,8 @@ class WebSocketModel {
...
@@ -207,8 +209,8 @@ class WebSocketModel {
}
else
if
(
message
.
type
===
"
start
"
)
{
}
else
if
(
message
.
type
===
"
start
"
)
{
console
.
log
(
"
Received start:
"
+
message
.
data
);
console
.
log
(
"
Received start:
"
+
message
.
data
);
for
(
let
conn
of
this
.
games
[
roomId
].
players
)
{
for
(
let
conn
of
this
.
games
[
roomId
].
players
)
{
if
(
conn
!==
connection
)
if
(
conn
.
connection
!==
connection
)
conn
.
send
(
conn
.
connection
.
send
(
JSON
.
stringify
({
type
:
"
playerReady
"
,
data
:
message
.
data
}),
JSON
.
stringify
({
type
:
"
playerReady
"
,
data
:
message
.
data
}),
);
);
}
}
...
@@ -218,7 +220,7 @@ class WebSocketModel {
...
@@ -218,7 +220,7 @@ class WebSocketModel {
this
.
games
[
roomId
].
readyPlayers
this
.
games
[
roomId
].
readyPlayers
)
{
)
{
for
(
let
conn
of
this
.
games
[
roomId
].
players
)
{
for
(
let
conn
of
this
.
games
[
roomId
].
players
)
{
conn
.
send
(
conn
.
connection
.
send
(
JSON
.
stringify
({
type
:
"
start
"
,
data
:
message
.
data
}),
JSON
.
stringify
({
type
:
"
start
"
,
data
:
message
.
data
}),
);
);
}
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
sign in
to comment