Skip to content
This repository has been archived by the owner on Mar 25, 2024. It is now read-only.

Feature/str78 #64

Merged
merged 27 commits into from
Mar 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
2daec65
added word attributes
jamespilcher Mar 21, 2023
296c84c
added get_words function, list of dicts
jamespilcher Mar 21, 2023
b729fe4
created words json
Joshua-Weaver1 Mar 21, 2023
d946bf2
added some words to the model
Joshua-Weaver1 Mar 22, 2023
fc13f55
added words to words.json
jamespilcher Mar 22, 2023
99b25da
word updates
jamespilcher Mar 22, 2023
fc01bc5
replaced definition with hint
jamespilcher Mar 22, 2023
6f34144
removed definition from word model
jamespilcher Mar 22, 2023
22033d4
removed definition from word model
jamespilcher Mar 22, 2023
12fdb29
linting fix
jamespilcher Mar 22, 2023
db9532b
Merge branch 'dev' of https://github.com/jamespilcher/campus-sustaina…
jamespilcher Mar 22, 2023
3c16bf3
removed endblock from wordsearch
jamespilcher Mar 22, 2023
dd2b0aa
removed userWon from hangman, added it to play (so it can be defined!)
jamespilcher Mar 22, 2023
dd3b7d1
hangman updates, init update
jamespilcher Mar 22, 2023
8953f7a
fixed remaining selected letters error
jamespilcher Mar 22, 2023
e6369ad
generated words dict using words data
jamespilcher Mar 22, 2023
98b33d2
removed userWon
jamespilcher Mar 22, 2023
24f1498
word data works with wordsearhc,
jamespilcher Mar 22, 2023
37acf4b
fixed lint
jamespilcher Mar 22, 2023
364c2a6
removed userWon from trivia. added wisdom button
jamespilcher Mar 22, 2023
9750d5a
removed userWon from tictactoe
jamespilcher Mar 22, 2023
f1e2426
did my best to change the background of wordsearch.
jamespilcher Mar 22, 2023
b34fe3d
Merge branch 'dev' into feature/STR78
jamespilcher Mar 23, 2023
4bef1c4
removed questions model + questions.json
jamespilcher Mar 23, 2023
a070603
migration fixes
jamespilcher Mar 23, 2023
0ee5875
linting fix
jamespilcher Mar 23, 2023
57f7ef3
fixed linting on migraitons
jamespilcher Mar 23, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion streatham_go/accounts/migrations/0001_initial.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# flake8: noqa

# Generated by Django 4.1.6 on 2023-03-21 21:21
# Generated by Django 4.1.6 on 2023-03-23 00:06

from django.conf import settings
from django.db import migrations, models
Expand Down
88 changes: 31 additions & 57 deletions streatham_go/app/migrations/0001_initial.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# flake8: noqa
# Generated by Django 4.1.6 on 2023-03-22 23:52

# Generated by Django 4.1.6 on 2023-03-23 00:06

from django.conf import settings
from django.db import migrations, models
Expand All @@ -16,71 +17,44 @@ class Migration(migrations.Migration):

operations = [
migrations.CreateModel(
name="Game",
name='Game',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('name', models.CharField(max_length=50)),
('file', models.CharField(max_length=50)),
],
),
migrations.CreateModel(
name='Word',
fields=[
(
"id",
models.BigAutoField(
auto_created=True,
primary_key=True,
serialize=False,
verbose_name="ID",
),
),
("name", models.CharField(max_length=50)),
("file", models.CharField(max_length=50)),
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('word', models.CharField(max_length=20)),
('hint', models.CharField(max_length=200)),
('fact', models.CharField(max_length=200)),
],
),
migrations.CreateModel(
name="Location",
name='Location',
fields=[
(
"id",
models.BigAutoField(
auto_created=True,
primary_key=True,
serialize=False,
verbose_name="ID",
),
),
("name", models.CharField(max_length=50)),
("latitude", models.CharField(max_length=50)),
("longitude", models.CharField(max_length=50)),
("message", models.CharField(max_length=200)),
(
"icon",
models.ImageField(blank=True, null=True, upload_to="app/icons/"),
),
(
"game",
models.ForeignKey(
on_delete=django.db.models.deletion.CASCADE, to="app.game"
),
),
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('name', models.CharField(max_length=50)),
('latitude', models.CharField(max_length=50)),
('longitude', models.CharField(max_length=50)),
('message', models.CharField(max_length=200)),
('icon', models.ImageField(blank=True, null=True, upload_to='app/icons/')),
('game', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='app.game')),
],
),
migrations.CreateModel(
name="Leaderboard",
name='Leaderboard',
fields=[
(
"id",
models.BigAutoField(
auto_created=True,
primary_key=True,
serialize=False,
verbose_name="ID",
),
),
("level", models.IntegerField(default=1)),
("xp", models.IntegerField(default=0)),
("quiz_count", models.IntegerField(default=0)),
(
"user",
models.OneToOneField(
on_delete=django.db.models.deletion.CASCADE,
to=settings.AUTH_USER_MODEL,
),
),
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('level', models.IntegerField(default=1)),
('xp', models.IntegerField(default=0)),
('numGamesPlayed', models.IntegerField(default=0)),
('timesPlayedToday', models.IntegerField(default=0)),
('profilePictureIndex', models.IntegerField(default=0)),
('user', models.OneToOneField(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL)),
],
),
]

This file was deleted.

This file was deleted.

19 changes: 19 additions & 0 deletions streatham_go/app/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,25 @@ class Game(models.Model):
file = models.CharField(max_length=50)


# Word Model
class Word(models.Model):
word = models.CharField(max_length=20)
hint = models.CharField(max_length=200)
fact = models.CharField(max_length=200)

# Gets the word data for all words
@classmethod
def get_words(self, word_data):
words = []
for word in word_data:
words.append({
'word': word.word,
'hint': word.hint,
'fact': word.fact
})
return words


# Location model
class Location(models.Model):
# the name of the building
Expand Down
30 changes: 12 additions & 18 deletions streatham_go/app/static/app/crossword.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,29 +11,11 @@ and the words to place */
const gridSize = 12;
const wordsToPlace = 6;
const wordsDict = {
'recycling': 'Reusing waste materials to create new products',
'sustainable': 'Eco-friendly practices for long-term resource use',
'renewable': 'Energy source that can be replenished naturally',
'ecosystem': 'Community of living organisms and their environment',
'conservation': 'Protection and preservation of natural resources',
'organic': 'Pertaining to farming without synthetic chemicals',
'pollution': 'Contamination of air, water, or soil by harmful substances',
'vegan': 'Person who abstains from animal products in diet',
'vegetarian': 'Person who excludes meat from their diet',
'reusable': 'Able to be used multiple times, reducing waste',
'compost': 'Organic matter decomposed for use as fertilizer',
'solar': 'Relating to energy derived from the sun\'s rays',
'carpooling': 'Shared vehicle rides to decrease fuel use and emissions',
'deforestation': 'Clearing of forests for agriculture or development',
'afforestation': 'Planting trees to create new forests or woodlands',
'biofuel': 'Renewable energy derived from organic materials, like plants',
'endangered': 'Species at risk of extinction due to habitat loss or other factors',
};

let usableWords = [];
let placedWords = [];
let currentOrientation;
let userWon = false;

// Create a 2d array of size gridSize x gridSize to store the value of each cell
const gridValues = new Array(gridSize);
Expand All @@ -47,10 +29,22 @@ let orientations = {
down: 0,
};

generateWordsDict();

// Call functions to create and generate the crossword grid
createGrid();
generateGrid();

/**
* populates the wordsDict using the Words Model data.
*/
function generateWordsDict() {
for (let i = 0; i < words.length; i++) {
wordsDict[words[i].word] = words[i].hint;
}
}


/**
* Creates a grid by populating an HTML table with gridSize x gridSize cells.
*/
Expand Down
50 changes: 12 additions & 38 deletions streatham_go/app/static/app/hangman.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,39 +7,12 @@ const finalMessage = document.getElementById("final-message");

// get the element with the class name "points"
let pointsElement = document.querySelector(".points");

// Flag to indicate if user won
let userWon = false;

// Get all the body parts of the figure as a NodeList
const figureParts = document.querySelectorAll(".person-part");

// Array of words related to the environment and sustainability
const words = [
"renewable",
"solar",
"wind",
"recycle",
"compost",
"sustainability",
"green",
"carbon",
"footprint",
"conservation",
"ecosystem",
"organic",
"biodiversity",
"climate",
"ozone",
"pollution",
"reduction",
"reuse",
"energy",
"efficient",
];

// Randomly select a word from the words array
let selectedWord = words[Math.floor(Math.random() * words.length)];
let selectedWord = words[Math.floor(Math.random() * words.length)]
let selectedWordWord = selectedWord.word;

// Arrays to hold the correctly and incorrectly guessed letters
const correctLetters = [];
Expand All @@ -48,8 +21,7 @@ const wrongLetters = [];
// Display the selected word with correctly guessed letters and input boxes for the remaining letters
function displayWord() {
wordE1.innerHTML = `
${selectedWord
.split("")
${selectedWordWord.split("")
.map(
(letter, index) =>
`<span class="letter" data-index="${index}">${
Expand All @@ -70,7 +42,7 @@ function displayWord() {
const innerWord = wordE1.innerText.replace(/\n/g, "");

// If all the letters have been correctly guessed
if (innerWord === selectedWord) {
if (innerWord === selectedWordWord) {
// Set userWon flag to true and display final message
userWon = true;
finalMessage.innerText = "Congratulations! You won!";
Expand All @@ -83,10 +55,11 @@ function handleInputBoxInput(e) {
const inputLetter = e.target.value;
const index = parseInt(e.target.parentNode.getAttribute("data-index"));
if (inputLetter && inputLetter.length === 1) {
const selectedLetter = selectedWord[index];
const remainingSelectedLetters = selectedWord
const selectedLetter = selectedWordWord[index];
const remainingSelectedLetters = selectedWordWord
.split("")
.slice(index + 1)
.concat(selectedWord.slice(0, index));
.concat(selectedWordWord.slice(0, index));
// If the input letter matches the selected letter, add it to correctLetters array
if (
!correctLetters.includes(selectedLetter) &&
Expand Down Expand Up @@ -117,7 +90,7 @@ function handleInputBoxKeyDown(e) {
const inputLetter = e.target.value.toUpperCase();
const index = parseInt(e.target.parentNode.getAttribute("data-index"));
if (inputLetter && inputLetter.length === 1) {
if (selectedWord[index] === inputLetter) {
if (selectedWordWord[index] === inputLetter) {
correctLetters.push(inputLetter);
displayWord();
} else {
Expand Down Expand Up @@ -164,7 +137,7 @@ window.addEventListener("keydown", (e) => {
if (e.keyCode >= 65 && e.keyCode <= 90) {
const letter = e.key;

if (selectedWord.includes(letter)) {
if (selectedWordWord.includes(letter)) {
if (!correctLetters.includes(letter)) {
correctLetters.push(letter);

Expand All @@ -190,7 +163,8 @@ playAgainBtn.addEventListener("click", () => {
correctLetters.splice(0);
wrongLetters.splice(0);

selectedWord = words[Math.floor(Math.random() * words.length)];
let selectedWord = words[Math.floor(Math.random() * words.length)]
let selectedWordWord = selectedWord.word;

displayWord();

Expand Down
1 change: 0 additions & 1 deletion streatham_go/app/static/app/tictactoe.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ let currentPlayer = "X";
let startingPlayer = currentPlayer;
let xScore = 0;
let oScore = 0;
let userWon = false;
let gamesPlayed = 1;

const PLAYER_X = "X";
Expand Down
1 change: 0 additions & 1 deletion streatham_go/app/static/app/trivia.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ let currentQuestion = {};
let score = 0;
let availableQuestions = [];
let questionCounter = 0;
let userWon = false;

// An array that contains the questions, answers, and correct answer
let questions = [
Expand Down
Loading