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 WORD_LENGTH=5
scripts/gen_wordlist.py english-words/words.txt 5 > wordlist.js 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: clean:
rm -rf wordlist.js 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

46
game.js
View File

@ -8,6 +8,11 @@ var gameCompleted = null
// HTML items // HTML items
const gameContainer = document.getElementById("game_container") 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 = [] const gridItems = []
// helper functions // helper functions
@ -20,7 +25,7 @@ const isLetter = string => /^[a-zA-Z]$/.test(string)
function setGridLetter(row, column, letter) { function setGridLetter(row, column, letter) {
console.log([row, column]) console.log([row, column])
console.log(letter) console.log(letter)
getGridItem(row, column).letter = letter getGridItem(row, column).letter = letter
getGridItem(row, column).HTMLItem.getElementsByClassName("grid_item_p")[0].innerHTML = letter !== null ? letter : "" getGridItem(row, column).HTMLItem.getElementsByClassName("grid_item_p")[0].innerHTML = letter !== null ? letter : ""
} }
@ -30,10 +35,14 @@ function checkGridRow() {
var [row, _ ] = findCurrentLetterPosition() var [row, _ ] = findCurrentLetterPosition()
var rowWord = '' var rowWord = ''
getGridRow(row).items.forEach(item => rowWord += item.letter) getGridRow(row).items.forEach(item => rowWord += item.letter)
console.log(rowWord) 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 correct_letters = 0
var dedupword = word var dedupword = word
@ -41,7 +50,7 @@ function checkGridRow() {
gridItem = getGridItem(row, column) gridItem = getGridItem(row, column)
// letters are removed from dedupword as letters are matched // letters are removed from dedupword as letters are matched
if (gridItem.letter === null) return if (gridItem.letter === null) return
if (gridItem.letter === word[column]) { if (gridItem.letter === word[column]) {
gridItem.HTMLItem.classList.add('grid_correct') gridItem.HTMLItem.classList.add('grid_correct')
correct_letters += 1 correct_letters += 1
@ -50,16 +59,16 @@ function checkGridRow() {
} else { } else {
gridItem.HTMLItem.classList.add('grid_wrong') gridItem.HTMLItem.classList.add('grid_wrong')
} }
dedupword = dedupword.replace(gridItem.letter, '') dedupword = dedupword.replace(gridItem.letter, '')
console.log(gridItem.letter) console.log(gridItem.letter)
console.log(dedupword) console.log(dedupword)
if (correct_letters == gridWidth) gameCompleted = true if (correct_letters == gridWidth) endGame(true)
} }
getGridRow(row).complete = 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 // create event listeners
document.addEventListener('keyup', (e) => { document.addEventListener('keyup', (e) => {
console.log(e) console.log(e)
@ -157,4 +180,5 @@ document.addEventListener('keyup', (e) => {
}) })
init() init()
console.log(word)

View File

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

3
readme
View File

@ -1 +1,4 @@
you know what it is 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 = argparse.ArgumentParser()
parser.add_argument('wordlist') parser.add_argument('wordlist')
parser.add_argument('word_length', type=int) parser.add_argument('word_length', type=int)
parser.add_argument('frequency_min', type=int)
parser.add_argument('allowedtypelist')
return parser.parse_args() return parser.parse_args()
def main(args): def main(args):
""" Entry point for script """ """ 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"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 return 0

View File

@ -15,6 +15,12 @@
--brown: #a16946; --brown: #a16946;
} }
#game_container {
display: flex;
align-items: center;
justify-content: center;
}
#letter_grid { #letter_grid {
width: fit-content; width: fit-content;
margin: 0 auto; margin: 0 auto;
@ -31,10 +37,11 @@
display: flex; display: flex;
justify-content: center; justify-content: center;
align-items: center; align-items: center;
border: 0.2em solid var(--dark-bg); border: 0.2em solid var(--default-fg);
margin: 1em; margin: 1em;
text-transform: uppercase; text-transform: uppercase;
font-weight: 800; font-weight: 800;
transition: 0.5s;
} }
.grid_item * { .grid_item * {
@ -44,4 +51,53 @@
.grid_correct { background-color: var(--green)} .grid_correct { background-color: var(--green)}
.grid_present { background-color: var(--yellow)} .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;
}