Skip to content

Instantly share code, notes, and snippets.

@natafaye
Created July 6, 2022 03:46
Show Gist options
  • Save natafaye/e6f1c49a8b6da963a90710569767db41 to your computer and use it in GitHub Desktop.
Save natafaye/e6f1c49a8b6da963a90710569767db41 to your computer and use it in GitHub Desktop.
7/5/22 - JS Week 6
class Die {
constructor(letters) {
this.topLetter = letters[0];
this.allLetters = letters;
}
roll() {
const randomIndex = Math.floor(Math.random() * this.allLetters.length)
this.topLetter = this.allLetters[randomIndex];
}
}
class Board {
constructor() {
this.dice = [];
for(let i = 0; i < 9; i++) {
this.dice.push( new Die(["A", "R", "C", "D", "E", "N"]) ) // all dies will have the same sides
}
}
shuffle() {
this.dice.sort(() => (Math.random() > 0.5) ? 1 : -1)
for(const die of this.dice) {
die.roll();
}
}
}
class Game {
constructor() {
this.board = null; // TODO
this.score = 0;
}
start() {
this.board.shuffle()
// starts off the game
prompt("What's a word you found?")
}
}
const game = new Game();
game.start();
// function doItManyTimes() {
// for(let i = 0; i < 3; i++) {
// doSomething()
// }
// }
// function doSomething() {
// for(let i = 0; i < 3; i++) {
// const message = "something "
// console.log(message + i)
// }
// }
// doItManyTimes();
class Player {
constructor(name, position) {
this.name = name;
this.position = position;
}
describe = () => {
return `${this.name} plays ${this.position}.`;
}
}
const expect = chai.expect;
describe("Player class", function() {
it("should save the name in the name property on a player", function() {
// Arrange and Act
const newPlayer = new Player("Mia", "defense");
// Assert
expect(newPlayer.name).to.equal("Mia")
})
it("should return the correct string from the describe method", function() {
// Arrange
const player = new Player("Amy", "forward");
// Act
const description = player.describe()
// Assert
expect(description).to.equal("Amy plays forward.")
})
})
// More professional organization:
// describe("Player class", function() {
// describe("#constructor", function() {
// it("should save the name in the name property on a player", function() {
// // Arrange and Act
// const newPlayer = new Player("Mia", "defense");
// // Assert
// expect(newPlayer.name).to.equal("Mia")
// })
// it("should save the position in the position property on a player", function() {
// // Arrange and Act
// const newPlayer = new Player("Mia", "defense");
// // Assert
// expect(newPlayer.position).to.equal("defense")
// })
// })
// describe("#describe", function() {
// it("should return the correct string from the describe method", function() {
// // Arrange
// const player = new Player("Amy", "forward");
// // Act
// const description = player.describe()
// // Assert
// expect(description).to.equal("Amy plays forward.")
// })
// it("should handle the position being empty", function() {
// // Arrange
// const player = new Player("Amy", null);
// // Act
// const description = player.describe()
// // Assert
// expect(description).to.equal("Amy doesn't play anything.")
// })
// })
// })
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment