Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
Chess Project
Manage
Activity
Members
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Package Registry
Model registry
Operate
Terraform modules
Analyze
Contributor analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Maiko Voigtländer
Chess Project
Commits
bb388948
Commit
bb388948
authored
1 year ago
by
MaikoVoigt
Browse files
Options
Downloads
Patches
Plain Diff
Tutorial - Task 5
parent
bf067112
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
public/javascripts/renderChessboard.js
+52
-9
52 additions, 9 deletions
public/javascripts/renderChessboard.js
routes/index.js
+2
-1
2 additions, 1 deletion
routes/index.js
views/index.hbs
+9
-2
9 additions, 2 deletions
views/index.hbs
with
63 additions
and
12 deletions
public/javascripts/renderChessboard.js
+
52
−
9
View file @
bb388948
// Tutorial 3
// Task 2
function
renderChessboard
(
pov
){
function
renderChessboard
_task2
(
pov
){
// Erstellung eines HTML-Strings
// POV Schwarz
...
...
@@ -13,18 +13,18 @@
col
.
reverse
();
}
let
result
=
''
;
result
+=
'
<table id="chessboard">
'
;
let
HTML
=
''
;
HTML
+=
'
<table id="chessboard">
'
;
for
(
let
i
of
row
)
{
result
+=
'
<tr id="row
'
+
i
+
'
">
'
;
HTML
+=
'
<tr id="row
'
+
i
+
'
">
'
;
for
(
let
j
of
col
)
{
result
+=
'
<td id="
'
+
j
+
i
+
'
">
'
+
j
+
i
+
'
</td>
'
;
HTML
+=
'
<td id="
'
+
j
+
i
+
'
">
'
+
j
+
i
+
'
</td>
'
;
}
result
+=
'
</tr>
'
;
HTML
+=
'
</tr>
'
;
}
result
+=
'
</table>
'
;
return
result
;
HTML
+=
'
</table>
'
;
return
HTML
;
}
// Task 4
...
...
@@ -100,7 +100,7 @@
return
FEN
;
}
function
renderC
ompleteC
hessboard
(
fen
,
pov
){
function
renderChessboard
_task4
(
fen
,
pov
){
// es wir von korrekten FEN ausgegangen
// POV Schwarz
...
...
@@ -146,4 +146,47 @@
table
.
appendChild
(
tr
);
}
document
.
getElementById
(
"
chessboardElement
"
).
appendChild
(
table
);
}
// Task 5
function
renderChessboard_task5
(
pov
){
// Erstellung eines HTML-Strings
// POV Schwarz
let
row
=
[
'
1
'
,
'
2
'
,
'
3
'
,
'
4
'
,
'
5
'
,
'
6
'
,
'
7
'
,
'
8
'
];
let
col
=
[
'
H
'
,
'
G
'
,
'
F
'
,
'
E
'
,
'
D
'
,
'
C
'
,
'
B
'
,
'
A
'
];
if
(
pov
==
'
w
'
)
{
// POV Weiß
row
.
reverse
();
col
.
reverse
();
}
let
HTML
=
''
;
HTML
+=
'
<table id="chessboard">
'
;
for
(
let
i
of
row
)
{
HTML
+=
'
<tr id="row
'
+
i
+
'
">
'
;
for
(
let
j
of
col
)
{
HTML
+=
'
<td id="
'
+
j
+
i
+
'
"><span class="boardPosition">
'
+
j
+
i
+
'
</span><span class="chessPiece"></span></td>
'
;
}
HTML
+=
'
</tr>
'
;
}
HTML
+=
'
</table>
'
;
//console.log(HTML);
return
HTML
;
}
function
placePieces
(
fen
){
// es wir von korrekten FEN ausgegangen
// Array aus Unicode für Schachfiguren
let
FEN
=
convertFEN
(
fen
);
// Schachbrett
let
squares
=
document
.
getElementsByClassName
(
"
chessPiece
"
);
for
(
let
i
of
squares
){
i
.
innerHTML
=
FEN
.
shift
();
// entfernt ersten Eintrag aus Array und gibt ihn zurück
}
}
\ No newline at end of file
This diff is collapsed.
Click to expand it.
routes/index.js
+
2
−
1
View file @
bb388948
...
...
@@ -3,7 +3,8 @@ var router = express.Router();
/* GET home page. */
router
.
get
(
'
/
'
,
function
(
req
,
res
,
next
)
{
res
.
render
(
'
index
'
,
{
title
:
'
Express
'
,
pov
:
'
w
'
,
fen
:
'
rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR
'
});
// res.render('index', { title: 'Express', pov: 'w', fen: 'rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR' });
res
.
render
(
'
index
'
,
{
title
:
'
Express
'
,
pov
:
'
b
'
,
fen
:
'
RNBKQBNR/PPPPPPPP/8/8/8/8/pppppppp/rnbkqbnr
'
});
});
module
.
exports
=
router
;
This diff is collapsed.
Click to expand it.
views/index.hbs
+
9
−
2
View file @
bb388948
...
...
@@ -4,7 +4,14 @@
<script
src=
"javascripts/renderChessboard.js"
></script>
<script>
//document.getElementById("chessboardElement").innerHTML = renderChessboard("
{{
pov
}}
"
);
renderCompleteChessboard(
"
{{
fen
}}
"
,
"
{{
pov
}}
"
);
// Task 2
// document.getElementById("chessboardElement").innerHTML = renderChessboard_task2("
{{
pov
}}
"
);
// Task 4
// renderChessboard_task4(
"
{{
fen
}}
"
,
"
{{
pov
}}
"
);
// Task 5
document.getElementById(
"
chessboardElement
"
).innerHTML = renderChessboard_task5(
"
{{
pov
}}
"
);
placePieces(
"
{{
fen
}}
"
);
</script>
\ No newline at end of file
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
register
or
sign in
to comment