Public
Edited
Dec 29, 2023
Paused
1 fork
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
gameloop = {
if(currentLevel < 4 && correctGuess === true) mutable currentLevel++
if(currentLevel === 4) {
finishGame()
}
yield true;
}
Insert cell
finishGame = () => {
mutable gameComplete = true
}
Insert cell
startGame = (newPuzzleIndex) => {
mutable startTime = new Date()
mutable puzzleIndexReal = newPuzzleIndex
mutable currentLevel = 1
mutable message = ''
mutable incorrectGuessCount = -3
mutable gameComplete = false
}
Insert cell
drawBoard = (board, width) => {
return Plot.plot({
width: width,
height: width,
marks: [
Plot.cell(board, {
// cells
x: "x",
y: "y",
stroke: "black",
strokeWidth: 3,
}),
Plot.cell(board, {
// blanks
x: "x",
y: "y",
filter: (d) => d.letter === "_",
stroke: "black",
fill: "black"
}),
Plot.text(board, {
x: "x",
y: "y",
text: "letter",
fill: "black",
fontSize: width / 10
})
],
x: { type: "band", axis: false, padding: 0 },
y: { type: "band", axis: false, padding: 0 },
})
}
Insert cell
mutable guess = ''
Insert cell
boardFromString = boardstring => boardstring
.split("")
.map((l,i) => ({
x: i % 4,
y: Math.floor(i/4.0),
letter: l
}))
Insert cell
picks
Insert cell
boardFromString(currentBoard.boardstring)
Insert cell
updateGuess = (str) => mutable guess = str.toUpperCase()
Insert cell
updateGuessCount = (i) => mutable incorrectGuessCount++
Insert cell
correctGuess = guess === currentBoard.word
Insert cell
currentBoard = picks
.filter(x => x.game_index === puzzleIndexReal)
.filter(x => x.game_level === Math.min(currentLevel,3))[0]
Insert cell
mutable startTime = new Date()
Insert cell
mutable puzzleIndexReal = 1
Insert cell
mutable currentLevel = 1
Insert cell
mutable incorrectGuessCount = -3
Insert cell
picks
select difficulty, min(game_index) as first_index
from picks
group by 1
Insert cell
picks = FileAttachment("output_csv.csv").csv({typed: true})
Insert cell
puzzleIndexMax = Math.max(...picks.map(x=> x.game_index)) - 1
Insert cell
selectedDifficulty = picks.filter(x=> x.game_index === puzzleIndex)[0].difficulty
Insert cell
selectedDifficultyReal = picks.filter(x=> x.game_index === puzzleIndexReal)[0].difficulty
Insert cell
mutable message = 'Find a big word in the board. Then find two more. Scroll down for more rules.'
Insert cell
mutable gameComplete = false
Insert cell
viewof selectDifficulty = {
const difficulties = difficulties_sql.map(x=>x.difficulty);
const radioInput = Inputs.radio(difficulties, {value: selectedDifficultyReal});
return radioInput
}
Insert cell
completeMessage = {
const totalSeconds = ((new Date() - startTime) / 1000).toFixed(2);
const oneWrong = incorrectGuessCount === 1 ? '' : 'es';
const puzzleIndexInput = difficulties_sql.filter(x => x.difficulty === selectDifficulty)[0].first_index;

const nextPuzzle = selectDifficulty === selectedDifficultyReal ? puzzleIndexReal + 1 : puzzleIndexInput
const startNextGame = () => startGame(nextPuzzle)
let el = html`<h3>Level Complete!</h3>
<div>You solved 3 Big Words Puzzle #${puzzleIndexReal} in ${totalSeconds} seconds</div>
<button>Play Puzzle #${nextPuzzle}</button>
<div>Or change the difficulty:</div>
<div>${viewof selectDifficulty}</div>
`;

el.querySelector("button").addEventListener("click", startNextGame);

return el;
}
Insert cell
<style>
.guess {
font-family: 'Courier New', Courier, monospace;
background-color: #D3D3D3;
color: #686868;
padding: 15px 32px;
text-decoration: none;
display: inline-block;
font-size: 36px;
font-weight: bold;
min-width: 600px;
margin: 2px 1px;
cursor: pointer;
text-transform: uppercase;
}
.boardContainer {
display: ${gameComplete === true ? "None" : "flex"};
justify-content: space-between;
}
.messageContainer {
display: ${gameComplete === false ? "None" : "flex"};
font-size: 20px;
font-weight: bold;
border: 2px solid #686868;
margin: 2px 1px;
}
</style>
Insert cell

One platform to build and deploy the best data apps

Experiment and prototype by building visualizations in live JavaScript notebooks. Collaborate with your team and decide which concepts to build out.
Use Observable Framework to build data apps locally. Use data loaders to build in any language or library, including Python, SQL, and R.
Seamlessly deploy to Observable. Test before you ship, use automatic deploy-on-commit, and ensure your projects are always up-to-date.
Learn more