Compare commits

...

6 Commits

10 changed files with 794909 additions and 37 deletions

3
.gitmodules vendored
View File

@ -1,3 +0,0 @@
[submodule "english-words"]
path = english-words
url = https://github.com/dwyl/english-words

794771
1_1_all_fullalpha.txt Normal file

File diff suppressed because it is too large Load Diff

View File

@ -1,12 +1,10 @@
wordlist.js: english-words
scripts/gen_wordlist.py english-words/words.txt 5 > wordlist.js
WORD_LENGTH=5
MIN_FREQUENCY=1
SOURCE_WORDLIST=1_1_all_fullalpha.txt
ALLOWED_TYPELIST=allowed_types
english-words: .SUBMODULES
wordlist.js:
./scripts/gen_wordlist.py ${SOURCE_WORDLIST} ${WORD_LENGTH} ${MIN_FREQUENCY} ${ALLOWED_TYPELIST} > wordlist.js
clean:
rm -rf wordlist.js
.SUBMODULES:
git submodule init
git submodule update

8
allowed_types Normal file
View File

@ -0,0 +1,8 @@
adj
prep
adv
num
int
verb
pron
conj

@ -1 +0,0 @@
Subproject commit 22d7c41119076750a96fca2acd664ed994cc0a75

30
game.js
View File

@ -8,6 +8,11 @@ var gameCompleted = null
// HTML items
const gameContainer = document.getElementById("game_container")
const body = document.getElementsByTagName("body")[0]
const endScreen = document.getElementById("end_screen")
const endScreenGuesses = document.getElementById("end_screen_guesses")
const endScreenMessage = document.getElementById("end_screen_message")
const endScreenTime = document.getElementById("end_screen_time")
const gridItems = []
// helper functions
@ -32,7 +37,11 @@ function checkGridRow() {
getGridRow(row).items.forEach(item => rowWord += item.letter)
console.log(rowWord)
if (!wordlist.includes(rowWord)) return
if (!wordlist.includes(rowWord)) {
body.classList.add("incorrect")
setTimeout( () => body.classList.remove("incorrect"), 500)
return
}
var correct_letters = 0
var dedupword = word
@ -55,11 +64,11 @@ function checkGridRow() {
console.log(gridItem.letter)
console.log(dedupword)
if (correct_letters == gridWidth) gameCompleted = true
if (correct_letters == gridWidth) endGame(true)
}
getGridRow(row).complete = true
if (row === gridHeight-1) gameCompleted = true
if (row === gridHeight-1) endGame(false)
}
@ -150,6 +159,20 @@ function setNextLetter(key) {
}
function endGame(won) {
gameCompleted = true
if (won) {
endScreenMessage.innerHTML = "niceeeeeeeee"
} else {
endScreenMessage.innerHTML = "damn. better luck nex time"
}
endScreenGuesses.innerHTML = `guesses: ${findCurrentLetterPosition()[0]+1}/${gridHeight}`
endScreen.style.display = "";
}
// create event listeners
document.addEventListener('keyup', (e) => {
console.log(e)
@ -158,3 +181,4 @@ document.addEventListener('keyup', (e) => {
init()
console.log(word)

View File

@ -3,22 +3,21 @@
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" type="text/css" href="styles.css">
<title>word guessing game: infinite</title>
<title>words</title>
</head>
<body>
<h1>word guessing game</h1>
<h1>words</h1>
<div id="game_container">
you need javascript enabled to play this game
<div id="letter_grid">
</div>
<div style="display: none"; id="end_screen">
<h2 id="end_screen_message"></h2>
<h3 id="end_screen_guesses"></h3>
<h3 id="end_screen_time"></h3>
<p> refresh page to play again </p>
</div>
<p>
built with ❤ and adequate amounts of care by
<a href="https://alv.cx">alv</a>
</p>
<p> built with ❤ and adequate amounts of care by <a href="https://alv.cx">alv</a> </p>
<script type="application/javascript" src="wordlist.js"></script>
<script type="application/javascript" src="game.js"></script>

3
readme
View File

@ -1 +1,4 @@
you know what it is
wordlist `1_1_all_fullalpha.txt` is from https://ucrel.lancs.ac.uk/bncfreq/flists.html

View File

@ -11,15 +11,32 @@ def get_args():
parser = argparse.ArgumentParser()
parser.add_argument('wordlist')
parser.add_argument('word_length', type=int)
parser.add_argument('frequency_min', type=int)
parser.add_argument('allowedtypelist')
return parser.parse_args()
def main(args):
""" Entry point for script """
with open(args.wordlist) as fp:
words = [ word.lower() for word in fp.read().split('\n') if len(word) == args.word_length and word.isalpha() ]
with open(args.allowedtypelist) as fp:
allowed_types = fp.read().split('\n')
types = set()
with open(args.wordlist) as fp:
words = [ (word[1], int(word[4]), word[2]) for word in [ word.lower().split('\t') for word in fp.read().strip().split('\n') ] ]
[ types.add(word[2]) for word in words ]
words = [ word[0] for word in words if word[1] >= args.frequency_min and word[0].isalpha() and len(word[0]) == args.word_length and word[2] in allowed_types ]
words.sort(key=lambda word: word[1])
# remove duplicates
words = list(set(words))
print(f"wordlist = {json.dumps(words)}")
print(f"{args}", file=sys.stderr)
print(f"{len(words)=}", file=sys.stderr)
print(f"{types=}", file=sys.stderr)
return 0

View File

@ -15,6 +15,12 @@
--brown: #a16946;
}
#game_container {
display: flex;
align-items: center;
justify-content: center;
}
#letter_grid {
width: fit-content;
margin: 0 auto;
@ -31,10 +37,11 @@
display: flex;
justify-content: center;
align-items: center;
border: 0.2em solid var(--dark-bg);
border: 0.2em solid var(--default-fg);
margin: 1em;
text-transform: uppercase;
font-weight: 800;
transition: 0.5s;
}
.grid_item * {
@ -44,4 +51,53 @@
.grid_correct { background-color: var(--green)}
.grid_present { background-color: var(--yellow)}
.grid_wrong { background-color: var(--brown)}
.grid_wrong { background-color: var(--default-bg)}
.correct {
animation: correct 0.5s;
}
.incorrect {
animation: incorrect 0.5s;
}
@keyframes correct {
0% {
background: var(--default-bg);
}
50% {
background: var(--green);
}
100% {
background: var(--default-bg);
}
}
@keyframes incorrect {
0% {
background: var(--default-bg);
}
50% {
background: var(--red);
}
100% {
background: var(--default-bg);
}
}
#end_screen {
position: fixed;
height: 100vh;
width: 100vw;
top: 0;
left: 0;
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
background-color: rgba(255, 255, 255, 0.8)
}
#end_screen * {
width: fit-content;
}