Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
71 changes: 7 additions & 64 deletions 05week/checkers.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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(" ");
Expand All @@ -91,31 +50,16 @@ class Board {
}
console.log(string);
}

// Your code here
}
// Your code here

class Game {
constructor() {
this.board = new Board();
}
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]);
}
}
}

Expand All @@ -129,7 +73,6 @@ function getPrompt() {
});
}

//dont change below
const game = new Game();
game.start();

Expand Down
22 changes: 0 additions & 22 deletions 07week/API.html

This file was deleted.

62 changes: 0 additions & 62 deletions 07week/api.js

This file was deleted.

31 changes: 31 additions & 0 deletions 08week/Dodgeball/Dodgeball.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta http-equiv="X-UA-Compatible" content="ie=edge" />
<title>Dodge Ball</title>
</head>
<body>
<div>
<h4>List Of People</h4>
<ul id="people"></ul>
</div>
<button onclick="listPeopleChoices()">List People</button>
<div>
<h4>Dodge Ball Players</h4>
<ul id="players"></ul>
</div>
<div>
<h4>Blue Team</h4>

<ul id="blue"></ul>
</div>
<div>
<h4>Red Team</h4>
<ul id="red"></ul>
</div>

<script src="./main.js"></script>
</body>
</html>
Loading