Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
C
crossword
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
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Silas Dohm
crossword
Commits
41030d81
Commit
41030d81
authored
Sep 26, 2022
by
Silas Dohm
Browse files
Options
Downloads
Patches
Plain Diff
refactor
parent
451e10d2
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
classes.js
+4
-4
4 additions, 4 deletions
classes.js
cw.js
+12
-1
12 additions, 1 deletion
cw.js
main.js
+21
-34
21 additions, 34 deletions
main.js
with
37 additions
and
39 deletions
classes.js
+
4
−
4
View file @
41030d81
...
...
@@ -60,7 +60,7 @@ class Word {
let
o
=
Number
(
e
.
target
.
attributes
[
2
].
value
);
lastCell
=
activeCell
;
activeCell
=
mycell
[
x
][
y
]
m_orientation
=
o
;
activeDir
=
o
;
activeMode
=
mode
.
insert
;
endInput
();
}
...
...
@@ -72,7 +72,7 @@ class Word {
this
.
li
.
style
.
background
=
this
.
highlightColor
;
this
.
chars
.
forEach
(
element
=>
{
if
(
element
==
activeCell
)
element
.
draw
(
m_orientation
?
'
#ffe553
'
:
'
#ffab58
'
);
element
.
draw
(
activeDir
?
'
#ffe553
'
:
'
#ffab58
'
);
else
{
element
.
draw
(
this
.
highlightColor
);
}
...
...
@@ -83,7 +83,7 @@ class Word {
this
.
chars
.
forEach
(
element
=>
{
let
color
=
this
.
highlightColor
;
if
(
element
==
activeCell
)
color
=
m_orientation
?
'
#ffe553
'
:
'
#ffab58
'
;
color
=
activeDir
?
'
#ffe553
'
:
'
#ffab58
'
;
if
(
element
.
currentChar
.
toUpperCase
()
==
element
.
actualChar
.
toUpperCase
())
{
element
.
draw
(
color
,
"
green
"
);
}
...
...
@@ -93,7 +93,7 @@ class Word {
}
//highlight
ctx
.
strokeStyle
=
"
#bf060b
"
;
if
(
this
.
direction
==
m_orientation
)
{
if
(
this
.
direction
==
activeDir
)
{
this
.
li
.
style
.
borderColor
=
"
#bf060b
"
;
if
(
this
.
direction
)
ctx
.
strokeRect
(
this
.
chars
[
0
].
x
*
size
,
this
.
chars
[
0
].
y
*
size
,
size
,
this
.
chars
.
length
*
size
);
...
...
This diff is collapsed.
Click to expand it.
cw.js
+
12
−
1
View file @
41030d81
function
initTestPuzzle2
(){
function
initPuzzle
(){
columns
=
12
;
rows
=
12
;
ctx
.
canvas
.
width
=
size
*
columns
;
ctx
.
canvas
.
height
=
size
*
rows
;
mycell
=
new
Array
(
columns
);
//create array
for
(
i
=
0
;
i
<
columns
;
i
++
)
{
mycell
[
i
]
=
new
Array
(
rows
);
//make array 2D
for
(
j
=
0
;
j
<
rows
;
j
++
)
{
mycell
[
i
][
j
]
=
new
Cell
(
i
,
j
,
""
);
//create array of empty cells
}
}
words
.
push
(
new
Word
(
"
einverstanden
"
,
"
okay
"
,
1
,
1
,
0
));
words
.
push
(
new
Word
(
"
Hochziele
"
,
"
ideale
"
,
6
,
1
,
0
));
words
.
push
(
new
Word
(
"
Rauschgift
"
,
"
dope
"
,
1
,
2
,
0
));
...
...
This diff is collapsed.
Click to expand it.
main.js
+
21
−
34
View file @
41030d81
...
...
@@ -8,28 +8,15 @@ const mode = {
replace
:
2
};
let
activeMode
=
mode
.
visual
;
let
m_orientation
=
0
;
//0 = horizontal 1=vertical
let
activeCell
;
let
lastCell
;
let
activeDir
=
0
;
//0 = horizontal 1=vertical
let
activeCell
,
lastCell
;
let
size
=
80
;
let
words
=
new
Array
();
let
columns
;
let
rows
;
let
columns
,
rows
;
let
finished
=
false
;
let
mycell
;
columns
=
12
;
rows
=
12
;
ctx
.
canvas
.
width
=
size
*
columns
;
ctx
.
canvas
.
height
=
size
*
rows
;
let
mycell
=
new
Array
(
columns
);
//create array
for
(
i
=
0
;
i
<
columns
;
i
++
)
{
mycell
[
i
]
=
new
Array
(
rows
);
//make array 2D
for
(
j
=
0
;
j
<
rows
;
j
++
)
{
mycell
[
i
][
j
]
=
new
Cell
(
i
,
j
,
""
);
//create array of empty cells
}
}
initTestPuzzle2
();
initPuzzle
();
initNeighbours
();
activeCell
=
words
[
0
].
chars
[
0
];
//start cell
...
...
@@ -49,16 +36,16 @@ function logKey(e) {
activeMode
=
mode
.
visual
;
else
if
(
e
.
key
==
"
Backspace
"
)
{
activeCell
.
currentChar
=
""
;
if
(
m_orientation
&&
activeCell
.
word
[
m_orientation
]
==
activeCell
.
neighbour
[
1
].
word
[
m_orientation
])
{
if
(
activeDir
&&
activeCell
.
word
[
activeDir
]
==
activeCell
.
neighbour
[
1
].
word
[
activeDir
])
{
activeCell
=
activeCell
.
neighbour
[
1
];
}
else
if
(
!
m_orientation
&&
activeCell
.
word
[
m_orientation
]
==
activeCell
.
neighbour
[
0
].
word
[
m_orientation
])
{
else
if
(
!
activeDir
&&
activeCell
.
word
[
activeDir
]
==
activeCell
.
neighbour
[
0
].
word
[
activeDir
])
{
activeCell
=
activeCell
.
neighbour
[
0
];
}
}
else
if
(
e
.
keyCode
>
64
&&
e
.
keyCode
<
91
)
{
activeCell
.
currentChar
=
e
.
key
;
if
(
m_orientation
)
{
//down
if
(
activeDir
)
{
//down
if
(
activeCell
.
word
[
1
]
==
activeCell
.
neighbour
[
3
].
word
[
1
]
&&
activeCell
!=
activeCell
.
neighbour
[
3
])
activeCell
=
activeCell
.
neighbour
[
3
];
else
...
...
@@ -100,15 +87,15 @@ function logKey(e) {
break
;
case
"
I
"
:
//start of horizontal word
forceValidOrientation
();
if
(
activeCell
.
word
[
m_orientation
])
activeCell
=
activeCell
.
word
[
m_orientation
].
chars
[
0
];
if
(
activeCell
.
word
[
activeDir
])
activeCell
=
activeCell
.
word
[
activeDir
].
chars
[
0
];
case
"
R
"
:
case
"
i
"
:
forceValidOrientation
();
activeMode
=
mode
.
insert
;
break
;
case
"
a
"
:
activeCell
=
m_orientation
?
activeCell
.
neighbour
[
3
]
:
activeCell
.
neighbour
[
2
];
activeCell
=
activeDir
?
activeCell
.
neighbour
[
3
]
:
activeCell
.
neighbour
[
2
];
forceValidOrientation
();
activeMode
=
mode
.
insert
;
break
;
...
...
@@ -123,7 +110,7 @@ function logKey(e) {
var
x
=
activeCell
.
x
;
var
y
=
activeCell
.
y
;
while
(
true
)
{
if
(
m_orientation
)
{
//vertical
if
(
activeDir
)
{
//vertical
y
=
(
y
+
rows
-
1
)
%
rows
;
if
(
y
%
columns
==
rows
-
1
)
x
=
(
x
+
columns
-
1
)
%
columns
;
...
...
@@ -134,8 +121,8 @@ function logKey(e) {
if
(
x
%
columns
==
columns
-
1
)
y
=
(
y
+
rows
-
1
)
%
rows
;
}
if
(
mycell
[
x
][
y
].
word
[
m_orientation
]
&&
mycell
[
x
][
y
].
word
[
m_orientation
]
!=
activeCell
.
word
[
m_orientation
])
{
activeCell
=
mycell
[
x
][
y
].
word
[
m_orientation
].
chars
[
0
];
if
(
mycell
[
x
][
y
].
word
[
activeDir
]
&&
mycell
[
x
][
y
].
word
[
activeDir
]
!=
activeCell
.
word
[
activeDir
])
{
activeCell
=
mycell
[
x
][
y
].
word
[
activeDir
].
chars
[
0
];
break
;
}
}
...
...
@@ -146,7 +133,7 @@ function logKey(e) {
var
x
=
activeCell
.
x
;
var
y
=
activeCell
.
y
;
while
(
true
)
{
if
(
m_orientation
)
{
//vertical
if
(
activeDir
)
{
//vertical
y
=
(
y
+
1
)
%
rows
;
if
(
y
%
columns
==
0
)
x
=
(
x
+
1
)
%
columns
;
...
...
@@ -156,7 +143,7 @@ function logKey(e) {
if
(
x
%
columns
==
0
)
y
=
(
y
+
1
)
%
rows
;
}
if
(
mycell
[
x
][
y
].
word
[
m_orientation
]
&&
mycell
[
x
][
y
].
word
[
m_orientation
]
!=
activeCell
.
word
[
m_orientation
])
{
if
(
mycell
[
x
][
y
].
word
[
activeDir
]
&&
mycell
[
x
][
y
].
word
[
activeDir
]
!=
activeCell
.
word
[
activeDir
])
{
activeCell
=
mycell
[
x
][
y
];
break
;
}
...
...
@@ -169,7 +156,7 @@ function logKey(e) {
activeCell
.
currentChar
=
activeCell
.
actualChar
;
break
;
case
"
q
"
:
//swap orientation - key still undecided
m_orientation
=
m_orientation
?
0
:
1
;
//invert orientation
activeDir
=
activeDir
?
0
:
1
;
//invert orientation
break
;
default
:
break
;
...
...
@@ -187,15 +174,15 @@ canv.addEventListener('mousedown', function (e) { //mouse navigation
lastCell
=
activeCell
;
activeCell
=
mycell
[
x
][
y
]
if
(
activeCell
==
lastCell
)
m_orientation
=
m_orientation
?
0
:
1
;
//invert orientation
activeDir
=
activeDir
?
0
:
1
;
//invert orientation
activeMode
=
mode
.
insert
;
forceValidOrientation
();
endInput
();
}
});
function
forceValidOrientation
()
{
if
(
!
activeCell
.
word
[
m_orientation
])
//
m_orientation
=
m_orientation
?
0
:
1
;
//invert orientation
if
(
!
activeCell
.
word
[
activeDir
])
//
activeDir
=
activeDir
?
0
:
1
;
//invert orientation
}
function
endInput
()
{
if
(
activeMode
==
mode
.
insert
)
{
...
...
@@ -209,7 +196,7 @@ function endInput() {
if
(
lastCell
.
word
[
1
])
lastCell
.
word
[
1
].
clearHighlight
();
if
(
!
m_orientation
)
{
//highlight active words
if
(
!
activeDir
)
{
//highlight active words
if
(
activeCell
.
word
[
1
])
activeCell
.
word
[
1
].
highlight
();
if
(
activeCell
.
word
[
0
])
...
...
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