diff --git a/05week/checkers.js b/05week/checkers.js index bed8c88bf..92f4476ef 100644 --- a/05week/checkers.js +++ b/05week/checkers.js @@ -7,55 +7,14 @@ const rl = readline.createInterface({ output: process.stdout }); +function Checker() { + // Your code here +} + class Board { constructor() { this.grid = []; - this.checkers = []; - this.redPiece = "X"; - this.blackPiece = "O"; - this.playerTrn = this.blackPiece; - } - - initializeGrid() { - for (let row = 0; row < 3; row++) { - for (let column = 0; column < 8; column++) { - if (column % 2 === 1 && row % 2 === 0) { - this.grid[row][column] = this.redPiece; - this.checkers.push(this.redPiece); - } else if (column % 2 === 0 && row % 2 === 1) { - this.grid[row][column] = this.redPiece; - this.checkers.push(this.redPiece); - } - } - } - for (let row = 5; row < 8; row++) { - for (let column = 0; column < 8; column++) { - if (column % 2 === 1 && row % 2 === 0) { - this.grid[row][column] = this.blackPiece; - this.checkers.push(this.blackPiece); - } else if (column % 2 === 0 && row % 2 === 1) { - this.grid[row][column] = this.blackPiece; - this.checkers.push(this.blackPiece); - } - } - } } - selectChecker(row, col) { - return this.grid[row][col]; - } - - killChecker(position) { - let checker = this.selectChecker(position[0], position[1]); - let indexChecker = this.checkers.indexOf(checker); - this.checkers.splice(indexChecker, 1); - - this.grid[position[0]][position[1]] = null; - } - - // important numbers - // 11 -11 9 -9 1 4 jump - // -22 22 -18 18 2 jump - // method that creates an 8x8 array, filled with null values createGrid() { // loop to create the 8 rows @@ -78,7 +37,7 @@ class Board { // if the location is "truthy" (contains a checker piece, in this case) if (this.grid[row][column]) { // push the symbol of the check in that location into the array - rowOfCheckers.push(this.grid[row][column]); + rowOfCheckers.push(this.grid[row][column].symbol); } else { // just push in a blank space rowOfCheckers.push(" "); @@ -91,8 +50,9 @@ class Board { } console.log(string); } + + // Your code here } -// Your code here class Game { constructor() { @@ -100,22 +60,6 @@ class Game { } start() { this.board.createGrid(); - this.board.initializeGrid(); - } - moveChecker(start, end) { - const startX = parseInt(start[0]); - const startY = parseInt(start[1]); - const endX = parseInt(end[0]); - const endY = parseInt(end[1]); - - const checker = this.board.selectChecker(start[0], start[1]); - - this.board.grid[endX][endY] = checker; - this.board.grid[startX][startY] = null; - - if (Math.sqrt((endX - startX) ^ (2 + (endY - startY)) ^ 2) >= 2) { - this.board.killChecker([(endX + startX) / 2, (endY + startY) / 2]); - } } } @@ -129,7 +73,6 @@ function getPrompt() { }); } -//dont change below const game = new Game(); game.start(); diff --git a/07week/API.html b/07week/API.html deleted file mode 100644 index 3cce4d72c..000000000 --- a/07week/API.html +++ /dev/null @@ -1,22 +0,0 @@ - - - - - Fetch - - - - - - -

- - - - - diff --git a/07week/api.js b/07week/api.js deleted file mode 100644 index 1d2e7cf5a..000000000 --- a/07week/api.js +++ /dev/null @@ -1,62 +0,0 @@ -// // document.getElementById("getAPI").addEventListener('click', getAPI) -// const ul = document.getElementById("authors"); // Get the list where we will place our authors -// const url = "https://randomuser.me/api/?results=10"; -// let data = { -// name: "Sara" -// }; -// // The parameters we are gonna pass to the fetch function -// let fetchData = { -// method: "POST", -// body: data, -// headers: new Headers() -// }; -// fetch(url, fetchData); -// function createNode(element) { -// return document.createElement(element); // Create the type of element you pass in the parameters -// } - -// function append(parent, el) { -// return parent.appendChild(el); // Append the second parameter(element) to the first one -// } - -// // function getAPI(){ -// fetch("https://randomuser.me/api/") -// .then(res => res.json()) -// .then(data => { -// let authors = data.results; // Get the results -// return authors.map(function(author) { -// // Map through the results and for each run the code below -// let li = createNode("li"), // Create the elements we need -// img = createNode("img"), -// span = createNode("span"); -// img.src = author.picture.medium; // Add the source of the image to be the src of the img element -// span.innerHTML = `${author.name.first} ${author.name.last}`; // Make the HTML of our span to be the first and last name of our author -// append(li, img); // Append all our elements -// append(li, span); -// append(ul, li); -// return authors -// }); -// }); - -// document.getElementById("getAPI").innerHTML = output; - -// document.getElementById("getAPI").addEventListener("click", getAPI); - -function getAPI() { - fetch("https://randomuser.me/api/") - .then((res) => res.json()) - .then((data) => { - let output = "

Api Posts

"; - data.forEach(function(post) { - output += ` - - - `; - }); - - document.getElementById("input").innerHTML = output; - }); -} diff --git a/08week/Dodgeball/Dodgeball.html b/08week/Dodgeball/Dodgeball.html new file mode 100644 index 000000000..a5ef83dfb --- /dev/null +++ b/08week/Dodgeball/Dodgeball.html @@ -0,0 +1,31 @@ + + + + + + + Dodge Ball + + +
+

List Of People

+ +
+ +
+

Dodge Ball Players

+ +
+
+

Blue Team

+ + +
+
+

Red Team

+ +
+ + + + diff --git a/08week/Dodgeball/dodgeball.js b/08week/Dodgeball/dodgeball.js new file mode 100644 index 000000000..c0cd36db6 --- /dev/null +++ b/08week/Dodgeball/dodgeball.js @@ -0,0 +1,285 @@ +const arrOfPeople = [ + { + id: 2, + name: "Charles Young", + age: 55, + skillSet: "welding", + placeBorn: "Omaha, Nebraska" + }, + { + id: 3, + name: "Judy Twilight", + age: 35, + skillSet: "fishing", + placeBorn: "Louisville, Kentucky" + }, + { + id: 4, + name: "Cynthia Doolittle", + age: 20, + skillSet: "tic tac toe", + placeBorn: "Pawnee, Texas" + }, + { + id: 5, + name: "John Willouby", + age: 28, + skillSet: "pipe fitting", + placeBorn: "New York, New York" //test + }, + { + id: 6, + name: "Stan Honest", + age: 20, + skillSet: "boom-a-rang throwing", + placeBorn: "Perth, Australia" + }, + { + id: 7, + name: "Mia Watu", + age: 17, + skillSet: "acrobatics", + placeBorn: "Los Angeles, California" + }, + { + id: 8, + name: "Walter Cole", + age: 32, + skillSet: "jump rope", + placeBorn: "New Orleans, Louisiana" + } +]; + +const listofPlayers = []; +const blueTeam = []; +const redTeam = []; + +class Player { + constructor(person) { + this.person = person; + this.isPlayer = false; + this.color = null; + } +} + +class BlueTeammate extends Player { + constructor(player) { + super(player.person); + this.color = "blue"; + } +} + +class RedTeammate extends Player { + constructor(player) { + super(player.person); + this.color = "red"; + } +} + +const listPeopleChoices = () => { + const listElement = document.getElementById("people"); + listElement.innerHTML = ""; + arrOfPeople + .filter(person => !person.isPlayer) // filters if a person is a player. + .map(person => { + const li = document.createElement("li"); + const button = document.createElement("button"); + button.innerHTML = "Make a Player"; + button.addEventListener("click", function() { + makePlayer(person.id); //makes the player + }); + li.appendChild(button); + li.appendChild( + document.createTextNode(person.name + " - " + person.skillSet) + ); + listElement.append(li); + }); +}; + +function makePlayer(id, skillSet) { + //function that actually makes the player + arrOfPeople.forEach((person, index) => { + if (person.id === id) { + let newplayer = new Player(person); + listofPlayers.push(newplayer); //pushes selected player + newplayer.isPlayer = true; + arrOfPeople.splice(index, 1); + listPlayer(); + listPeopleChoices(); + } + }); +} + +function listPlayer() { + document.getElementById("players").innerHTML = ""; + listofPlayers.map(player => { + const listPlayerEle = document.getElementById("players"); + const li = document.createElement("li"); + const redButton = document.createElement("button"); + redButton.innerHTML = "Red Team"; + const xButton = document.createElement("button"); + xButton.innerHTML = "X"; + xButton.addEventListener("click", function() { + xButton.remove(); + li.remove(); + }); + + redButton.addEventListener("click", function() { + redteam(player.person.id.name); + }); + + li.appendChild(redButton); + + const blueButton = document.createElement("button"); + blueButton.innerHTML = "Blue Team"; + blueButton.addEventListener("click", function() { + blueteam(player.person.id); + }); + + li.appendChild(blueButton); + li.appendChild(document.createTextNode(player.person.name)); + li.appendChild(xButton); + console.log(li, "test"); + listPlayerEle.append(li); + }); +} + +function blueteam(id) { + document.getElementById("blue").innerHTML = ""; + listofPlayers.map(player => { + const listPlayerEle = document.getElementById("blue"); + const li = document.createElement("li"); + const xButton = document.createElement("button"); + xButton.innerHTML = "X"; + xButton.addEventListener("click", function() { + xButton.remove(); + li.remove(); + }); + li.appendChild(document.createTextNode(player.person.name)); + li.appendChild(xButton); + listPlayerEle.append(li); + }); +} + +function redteam(id) { + document.getElementById("red").innerHTML = ""; + listofPlayers.map(player => { + const listPlayerEle = document.getElementById("red"); + const li = document.createElement("li"); + const xButton = document.createElement("button"); + xButton.innerHTML = "X"; + xButton.addEventListener("click", function() { + xButton.remove(); + li.remove(); + }); + li.appendChild(document.createTextNode(player.person.name)); + li.appendChild(xButton); + listPlayerEle.append(li); + }); +} + +// blueTeam.push(listofPlayers[id - 2]); +// const li = document.createElement("li"); +// blueteam.map(player => { +// const blueRoster = document.createElement("li"); +// blueRoster.append(li); +// console.log(blueRoster); +// }); +// } + +// ("use strict"); + +// let assert = require("assert"); + +// let jobTypes = { +// pilot: "MAV", +// mechanic: "Repair Ship", +// commander: "Main Ship", +// programmer: "Any Ship!" +// }; + +// class CrewMember { +// constructor(name, job, specialSkill, ship) { +// this.name = name; +// this.job = job; +// this.specialSkill = specialSkill; +// this.ship = ship; +// } + +// enterShip(shipParm) { +// this.ship = shipParm.name; +// shipParm.crew.push(this); +// } +// } + +// class Ship { +// constructor(name, type, ability, crew) { +// this.name = name; +// this.type = type; +// this.ability = ability; +// this.crew = []; +// } + +// missionStatement() { +// if (this.crew.length > 0) { +// return this.ability; +// } else { +// return "Can't perform a mission yet."; +// } +// } +// } + +// //tests +// if (typeof describe === "function") { +// describe("CrewMember", function() { +// it("should have a name, a job, a specialSkill and ship upon instantiation", function() { +// var crewMember1 = new CrewMember("Rick Martinez", "pilot", "chemistry"); +// assert.equal(crewMember1.name, "Rick Martinez"); +// assert.equal(crewMember1.job, "pilot"); +// assert.equal(crewMember1.specialSkill, "chemistry"); +// assert.equal(crewMember1.ship, null); +// }); + +// it("can enter a ship", function() { +// let mav = new Ship("Mars Ascent Vehicle", "MAV", "Ascend into low orbit"); +// let crewMember1 = new CrewMember("Rick Martinez", "pilot", "chemistry"); +// crewMember1.enterShip(mav); +// assert.equal(crewMember1.ship, "Mars Ascent Vehicle"); +// assert.equal(mav.crew.length, 1); +// assert.equal(mav.crew[0], crewMember1); +// }); +// }); + +// describe("Ship", function() { +// it("should have a name, a type, an ability and an empty crew upon instantiation", function() { +// let mav = new Ship("Mars Ascent Vehicle", "MAV", "Ascend into low orbit"); +// assert.equal(mav.name, "Mars Ascent Vehicle"); +// assert.equal(mav.type, "MAV"); +// assert.equal(mav.ability, "Ascend into low orbit"); +// assert.equal(mav.crew.length, 0); +// }); + +// it("can return a mission statement correctly", function() { +// let mav = new Ship("Mars Ascent Vehicle", "MAV", "Ascend into low orbit"); +// let crewMember1 = new CrewMember("Rick Martinez", "pilot", "chemistry"); +// let hermes = new Ship( +// "Hermes", +// "Main Ship", +// "Interplanetary Space Travel" +// ); +// let crewMember2 = new CrewMember( +// "Commander Lewis", +// "commander", +// "geology" +// ); +// assert.equal(mav.missionStatement(), "Can't perform a mission yet."); +// assert.equal(hermes.missionStatement(), "Can't perform a mission yet."); + +// crewMember1.enterShip(mav); +// assert.equal(mav.missionStatement(), "Ascend into low orbit"); + +// crewMember2.enterShip(hermes); +// assert.equal(hermes.missionStatement(), "Interplanetary Space Travel"); +// }); +// }); +// } diff --git a/08week/bootstrap/index.html b/08week/bootstrap/index.html deleted file mode 100644 index 7d10fd5f4..000000000 --- a/08week/bootstrap/index.html +++ /dev/null @@ -1,16 +0,0 @@ - - - - - Bootstrap - - - - -
- - - - - - diff --git a/08week/bootstrap/script.js b/08week/bootstrap/script.js deleted file mode 100644 index ad9a93a7c..000000000 --- a/08week/bootstrap/script.js +++ /dev/null @@ -1 +0,0 @@ -'use strict'; diff --git a/08week/bootstrap/style.css b/08week/bootstrap/style.css deleted file mode 100644 index d3f5a12fa..000000000 --- a/08week/bootstrap/style.css +++ /dev/null @@ -1 +0,0 @@ - diff --git a/08week/fetch/index.html b/08week/fetch/index.html deleted file mode 100644 index 6411e1ae2..000000000 --- a/08week/fetch/index.html +++ /dev/null @@ -1,49 +0,0 @@ - - - - - Fetch - - - - -
- - - - - - - - - diff --git a/09week/hackernews/index.html b/09week/hackernews/index.html deleted file mode 100644 index d8518af73..000000000 --- a/09week/hackernews/index.html +++ /dev/null @@ -1,14 +0,0 @@ - - - - - Hacker News - - -
- - - - - - diff --git a/09week/hackernews/script.js b/09week/hackernews/script.js deleted file mode 100644 index b1f4cb20e..000000000 --- a/09week/hackernews/script.js +++ /dev/null @@ -1,51 +0,0 @@ -'use strict'; -// document.getElementById("getText").addEventListener('click', getText) -// document.getElementById("getJson").addEventListener('click', getJson) -document.getElementById("getAPI").addEventListener('click', getAPI) - - -// function getText(){ -// fetch("text.txt") -// .then(function(data) { -// // console.log(data.text()) -// Return data.text() -// }).then(function(res)){ -// document.getElementById("input").innerHTML= output; -// }) - - -// function getJson(){ -// fetch("color.json") -// .then((res)=> res.json()) -// .then((data)=>{ -// let output = '

Color

' -// data.forEach(function(color){ -// output += ' - -//