-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3afb887
commit e767a32
Showing
17 changed files
with
197 additions
and
13 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
export default class UIManager { | ||
constructor () { | ||
this.records = []; | ||
} | ||
|
||
updateSelected(fish, value) { | ||
fish.selected = value; | ||
|
||
// Todo- Update the UI | ||
let selectedFish = fishInTank.filter(fish => fish.selected); | ||
let selectedFishDiv = document.querySelector("#selected-fish"); | ||
selectedFishDiv.innerHTML = ""; | ||
|
||
selectedFish.forEach(fish => { | ||
// Construct the new element | ||
let fishDiv = document.createElement("div"); | ||
|
||
let fishImage = document.createElement("img"); | ||
fishImage.src = `assets/fish/fish${fish.type}.png`; | ||
|
||
// Create paragraphs for the name and personality | ||
let nameParagraph = document.createElement("p"); | ||
nameParagraph.innerHTML = `<b>Name: </b>${fish.name}`; | ||
|
||
fishDiv.appendChild(fishImage); | ||
fishDiv.appendChild(nameParagraph); | ||
|
||
// Add it to the selected fish div | ||
selectedFishDiv.appendChild(fishDiv); | ||
}); | ||
} | ||
|
||
addRecord(text, fish1, fish2) { | ||
this.records.unshift({ | ||
text, fish1, fish2 | ||
}); | ||
|
||
if (this.records.length > 15) { | ||
this.records = this.records.slice(0, 15) | ||
} | ||
|
||
// Update the records | ||
let recordsDiv = document.querySelector("#records"); | ||
recordsDiv.innerHTML = ""; | ||
|
||
this.records.forEach(record => { | ||
let recordDiv = document.createElement("div"); | ||
|
||
// Replace placeholders in the text with fish names | ||
let formattedText = record.text.replace("FISH1", record.fish1.name); | ||
if (record.fish2) { | ||
formattedText = formattedText.replace("FISH2", record.fish2.name); | ||
} | ||
|
||
// Set the formatted text inside recordDiv | ||
recordDiv.textContent = formattedText; | ||
|
||
// Add the "record" class to recordDiv | ||
recordDiv.classList.add("record"); | ||
|
||
// Add a click handler to recordDiv | ||
recordDiv.addEventListener("click", function() { | ||
console.log('clicked', record.fish1); | ||
|
||
// Update the selected status of all fishInTank to false | ||
fishInTank.forEach(fish => { | ||
if (fish.selected) { | ||
this.updateSelected(fish, false) | ||
} | ||
}); | ||
|
||
// Update the selected status of fish1 to true | ||
this.updateSelected(record.fish1, true); | ||
|
||
// If fish2 is not null, update its selected status to true | ||
if (record.fish2) { | ||
this.updateSelected(record.fish2, true); | ||
} | ||
}.bind(this)); | ||
|
||
// Append recordDiv to recordsDiv | ||
recordsDiv.appendChild(recordDiv); | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
* { | ||
box-sizing: border-box; | ||
} | ||
html, body { | ||
background-color: #000; | ||
font-family: ui-monospace, 'Cascadia Code', 'Source Code Pro', Menlo, Consolas, 'DejaVu Sans Mono', monospace; | ||
} | ||
#game { | ||
margin-left: auto; | ||
margin-right: auto; | ||
display: flex; | ||
justify-content: center; | ||
width: 1368px; | ||
border: 1px solid #03343d; | ||
background-color: #7a8d9b; | ||
} | ||
.sidebar { | ||
padding: 20px; | ||
text-align: center; | ||
width: 300px; | ||
} |