From 5a58b61b0331f92311890dda05bcc2eafe0ab69f Mon Sep 17 00:00:00 2001 From: Chris Trevino Date: Sun, 19 Jul 2020 19:49:45 -0500 Subject: [PATCH 1/2] changes --- 07week/dodgeBall/dodgeBall.html | 30 ++++++ 07week/dodgeBall/dodgeBall.js | 183 ++++++++++++++++++++++++++++++++ 08week/cardGame/api.html | 18 ++++ 08week/cardGame/api.js | 43 ++++++++ 4 files changed, 274 insertions(+) create mode 100644 07week/dodgeBall/dodgeBall.html create mode 100644 07week/dodgeBall/dodgeBall.js create mode 100644 08week/cardGame/api.html create mode 100644 08week/cardGame/api.js diff --git a/07week/dodgeBall/dodgeBall.html b/07week/dodgeBall/dodgeBall.html new file mode 100644 index 000000000..407b06c47 --- /dev/null +++ b/07week/dodgeBall/dodgeBall.html @@ -0,0 +1,30 @@ + + + + + + + + Dodge Ball + + +
+

List Of People

+ +
+ +
+

Dodge Ball Players

+ +
+
+

Blue Team

+ +
+
+

Red Team

+ +
+ + + \ No newline at end of file diff --git a/07week/dodgeBall/dodgeBall.js b/07week/dodgeBall/dodgeBall.js new file mode 100644 index 000000000..dcd4297dc --- /dev/null +++ b/07week/dodgeBall/dodgeBall.js @@ -0,0 +1,183 @@ +'use strict' + + +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" + }, + { + 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(id, name, age, skillSet, placeBorn, canThrowBall, canDodgeBall, hasPaid, isHealthy, yearsExperience) { + this.id = id; + this.name = name; + this.age = age; + this.skillSet = skillSet; + this.placeBorn = placeBorn; + this.canThrowBall = canThrowBall; + this.canDodgeBall = canDodgeBall; + this.hasPaid = hasPaid; + this.isHealthy = isHealthy; + this.yearsExperience = yearsExperience; + } +} +class blueTeammate extends player { + constructor(id, name, age, skillSet, placeBorn, canThrowBall, canDodgeBall, hasPaid, isHealthy, yearsExperience, color, mascot) { + super(id, name, age, skillSet, placeBorn, canThrowBall, canDodgeBall, hasPaid, isHealthy, yearsExperience); + this.color = color; + this.mascot = mascot; + } +} +class redTeammate extends player { + constructor(id, name, age, skillSet, placeBorn, canThrowBall, canDodgeBall, hasPaid, isHealthy, yearsExperience, color, mascot) { + super(id, name, age, skillSet, placeBorn, canThrowBall, canDodgeBall, hasPaid, isHealthy, yearsExperience); + this.color = color; + this.mascot = mascot; + } +} + + + +const listPeopleChoices = () => { + document.getElementById("generate-people").remove(); + const listElement = document.getElementById('people') + arrOfPeople.map(person => { + const li = document.createElement("li") + li.setAttribute("id", `person-${person.id}`) + const button = document.createElement("button") + button.innerHTML = "Make Player" + button.addEventListener('click', function () { makePlayer(person.id) }) + li.appendChild(button) + li.appendChild(document.createTextNode(person.name + " - " + person.skillSet)) + listElement.append(li) + }) +} + +const makePlayer = (id) => { + document.getElementById(`person-${id}`).remove() + + let selectedPlayer; + for (let i = 0; i < arrOfPeople.length; i++) { + if (arrOfPeople[i].id === id) { + selectedPlayer = arrOfPeople[i]; + } + } + + const unassignedPlayer = new player(selectedPlayer.id, selectedPlayer.name, selectedPlayer.age, selectedPlayer.skillSet, selectedPlayer.placeBorn); + listOfPlayers.push(unassignedPlayer); + + const listElement = document.getElementById("players"); + const li = document.createElement("li"); + li.setAttribute("id", `person-${selectedPlayer.id}`) + + const buttonAssignRed = document.createElement("button"); + buttonAssignRed.innerHTML = "Assign to Red Team"; + buttonAssignRed.setAttribute("id", "red-button"); + buttonAssignRed.addEventListener('click', function () { assignRedTeammate(id) }); + + const buttonAssignBlue = document.createElement("button"); + buttonAssignBlue.innerHTML = "Assign to Blue Team"; + buttonAssignBlue.setAttribute("id", "blue-button"); + buttonAssignBlue.addEventListener('click', function () { assignBlueTeammate(id) }); + + + li.appendChild(buttonAssignRed); + li.appendChild(buttonAssignBlue); + li.appendChild(document.createTextNode(selectedPlayer.name + " - " + selectedPlayer.skillSet)); + + listElement.append(li); + +} + +const assignRedTeammate = (id) => { + document.getElementById(`person-${id}`).remove(); + + let selectedPlayer; + for (let i = 0; i < arrOfPeople.length; i++) { + if (arrOfPeople[i].id === id) { + selectedPlayer = arrOfPeople[i]; + } + } + + const assignedPlayer = new redTeammate(selectedPlayer.id, selectedPlayer.name, selectedPlayer.age, selectedPlayer.skillSet, selectedPlayer.placeBorn, null, null, null, null, null, "red", "bulls"); + redTeam.push(assignedPlayer); + + const listElement = document.getElementById("red"); + const li = document.createElement("li"); + li.setAttribute("id", `person-${selectedPlayer.id}`) + li.appendChild(document.createTextNode(selectedPlayer.name + " - " + selectedPlayer.skillSet)); + listElement.append(li); +} + +const assignBlueTeammate = (id) => { + document.getElementById(`person-${id}`).remove() + + let selectedPlayer; + for (let i = 0; i < arrOfPeople.length; i++) { + if (arrOfPeople[i].id === id) { + selectedPlayer = arrOfPeople[i]; + } + }; + + const assignedPlayer = new blueTeammate(selectedPlayer.id, selectedPlayer.name, selectedPlayer.age, selectedPlayer.skillSet, selectedPlayer.placeBorn, null, null, null, null, null, "blue", "bluedevils"); + blueTeam.push(assignedPlayer); + + const listElement = document.getElementById("blue"); + const li = document.createElement("li"); + li.setAttribute("id", `person-${selectedPlayer.id}`) + li.appendChild(document.createTextNode(selectedPlayer.name + " - " + selectedPlayer.skillSet)); + listElement.append(li); + +} diff --git a/08week/cardGame/api.html b/08week/cardGame/api.html new file mode 100644 index 000000000..9ed10cde3 --- /dev/null +++ b/08week/cardGame/api.html @@ -0,0 +1,18 @@ + + + + + + robotWar + + +
+ You +
+
+ Computer +
+ RobotWar!!! + + + \ No newline at end of file diff --git a/08week/cardGame/api.js b/08week/cardGame/api.js new file mode 100644 index 000000000..cbf8b7253 --- /dev/null +++ b/08week/cardGame/api.js @@ -0,0 +1,43 @@ +'use strict' + +console.log("loading api.js file"); + +generateRobot("player1"); +generateRobot("player2"); + +class Player { + cards = []; + id = null; + divId = null; + + constructor(id, divId){ + this.id = Math.random(); + this.divId = divId; + } +} + +let player1 = new Player("Player 1"); +let player2 = new Player("Player 2"); + +function dealCards(){ + fetch("https://deckofcards") +} +function generateRobot(divId){ + fetch("https://robohash.org/" + player.id).then(function(response){ + console.log("processing the robot fetch response", response); + return response.blob() + +}).then(function(blob){ + console.log("processing the robot fetch payload", blob) + insertRobot(divId, blob); +}); +} + + +function insertRobot(divId, blob){ + console.log("Attempting to add the img to the div", divId) + let img = document.createElement("img"); + img.src = URL.createObjectURL(blob); + let playerDiv = document.getElementById(divId); + playerDiv.appendChild(img); +} From 35bb6ea16745f65d3c38c7ae3475683fc8bc2083 Mon Sep 17 00:00:00 2001 From: Chris Trevino Date: Sat, 25 Jul 2020 20:26:40 -0500 Subject: [PATCH 2/2] robo fineshed --- 08week/cardGame/api.html | 47 +++++++++--- 08week/cardGame/api.js | 158 +++++++++++++++++++++++++++++++-------- 2 files changed, 162 insertions(+), 43 deletions(-) diff --git a/08week/cardGame/api.html b/08week/cardGame/api.html index 9ed10cde3..4f5a77736 100644 --- a/08week/cardGame/api.html +++ b/08week/cardGame/api.html @@ -1,18 +1,41 @@ - - - robotWar + Robot War!! + -
- You -
-
- Computer -
- RobotWar!!! - +

Robot War!!

+
+
+ You +
+
+
+ Computer +
+
+
+ +
+ +
+ + + +
+ + - \ No newline at end of file + \ No newline at end of file diff --git a/08week/cardGame/api.js b/08week/cardGame/api.js index cbf8b7253..d93f98321 100644 --- a/08week/cardGame/api.js +++ b/08week/cardGame/api.js @@ -1,43 +1,139 @@ 'use strict' -console.log("loading api.js file"); +class Player { + cards = []; //the deck of cards belonging th this player (ie. their hand) + id = null; + divId = null; -generateRobot("player1"); -generateRobot("player2"); + constructor(divId) { + this.id = Math.random(); //the id of the player (used to generate the robot) + this.divId = divId; // the divid on the page + }; +}; -class Player { - cards = []; - id = null; - divId = null; - - constructor(id, divId){ - this.id = Math.random(); - this.divId = divId; - } +//make an API call to get the image of the robot + +// instaniating 2 player instances +let player1 = new Player("player1"); +let player2 = new Player("player2"); +// generate the robot for player1 +generateRobot(player1) +// generate the robot for player2 +generateRobot(player2) +// get thecards from the service, and split them between the 2 players +generateAndDealCards(); + +// uses the deckofcardsapi to generate a new deck, and then divy them between the players +function generateAndDealCards() { + fetch("https://deckofcardsapi.com/api/deck/new/shuffle/?deck_count=1") + .then(function(response) { + console.log("Process fetch response for deck of cards", response); + return response.json(); + }) + .then(function(json) { + console.log("Processing the deck of cards payload", json); + let deckId = json.deck_id; + dealCards(deckId); + }) } -let player1 = new Player("Player 1"); -let player2 = new Player("Player 2"); +// split the deck between the 2 players +function dealCards(deckId) { + fetch("https://deckofcardsapi.com/api/deck/"+deckId+"/draw/?count=52") + .then(function(response) { + console.log("Processing the response for drawing the cards", response); + return response.json(); + }) + .then(function(json) { + console.log("Processing the payload for drawing the cards", json); + for(let i=0; i v2) { + player1.cards.push(card1); + player1.cards.push(card2); + } + else if (v1 < v2) { + player2.cards.push(card1); + player2.cards.push(card2); + } + else { + player1.cards.push(card1); + player2.cards.push(card2); + } + + updatePlayerCardCount(player1) + updatePlayerCardCount(player2) + +} + +function getCardValue(card) { + let value = card.value; + if(value == "JACK") { + return 11; + } + else if(value == "QUEEN") { + return 12; + } + else if(value == "KING") { + return 13; + } + else if(value == "ACE") { + return 14; + } + else { + return parseInt(value); + } +}; \ No newline at end of file