Skip to content

Commit

Permalink
V1
Browse files Browse the repository at this point in the history
  • Loading branch information
tweakimp authored Apr 23, 2017
1 parent 1ed7442 commit 14788cd
Show file tree
Hide file tree
Showing 5 changed files with 489 additions and 441 deletions.
9 changes: 6 additions & 3 deletions CSS/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,12 @@
border-collapse: collapse;
}

.markedField {
border: #dee529;
border-width: 3px;
.markedField1 {
background-color: #f3787f;
}

.markedField2 {
background-color: #59e262;
}

.player1 {
Expand Down
232 changes: 137 additions & 95 deletions JS/Game.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,99 +2,141 @@
/* globals GameArea, Player, twisted, fieldScore*/

function Game(player1, player2, timelimit) {
this.timelimit = timelimit; // time per move
this.board = new GameArea("customStart", true);
this.player1 = new Player(1, player1);
this.player2 = new Player(2, player2);

this.turnnumber = 1;

this.getLegalMoves = function () {
const allMoves = [ /*"l", "r", */ 0, 1, 2, 3, 4, 5, 6];
let moves = allMoves;
let matrix = twisted.board.getMatrix();
for (let i = 0; i < 7; i++) {
if (!(matrix[i].includes(0))) {
moves = moves.filter(item => item !== i);
}
}

if (moves.length === allMoves.length - 7) {
throw "BOARD IS FULL";
}
return moves;
};

this.time = 0;
this.countdown = function () {
this.time--;
// time limit reached, lose game
if (this.time === 0) {
if (this.whoseturn === 1) {} else {}
}

};
this.history = [];

this.start = function () {
twisted.board.fillMatrix();
twisted.board.drawMatrix();
this.nextTurn();
};

// start from here
this.customStartMatrix = [
[0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0],
];

// plan ahead from here
this.customMatrix = [
[0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0],
];

this.nextTurn = function () {

let move;
let player;

if (this.turnnumber % 2 === 1) {
move = this.player1.getMove();
player = 1;
} else {
move = this.player2.getMove();
player = 2;
}

// alles in betweenturn
this.history.push(move);
this.board.makeMove(move, player);

// check HERE for wins

let possibleWinner = twisted.board.getWinner();

this.board.drawMatrix();

fieldScore.draw(this.board.matrix);

this.turnnumber++;
if (possibleWinner === 0) {
setTimeout(function () {
twisted.nextTurn();
}, 450);
}

};
this.timelimit = timelimit; // time per move
this.board = new GameArea("customStart", true);
this.player1 = new Player(1, player1);
this.player2 = new Player(2, player2);

this.turnnumber = 1;

this.getLegalMoves = function () {
const allMoves = [ /*"l", "r", */ 0, 1, 2, 3, 4, 5, 6];
let moves = allMoves;
let matrix = twisted.board.getMatrix();
for (let i = 0; i < 7; i++) {
if (!(matrix[i].includes(0))) {
moves = moves.filter(item => item !== i);
}
}

if (moves.length === allMoves.length - 7) {
throw "BOARD IS FULL";
}
return moves;
};

this.time = 0;
this.countdown = function () {
this.time--;
// time limit reached, lose game
if (this.time === 0) {
if (this.whoseturn === 1) {} else {}
}

};
this.history = [];

this.start = function () {
twisted.board.fillMatrix();
twisted.board.drawMatrix();
fieldScore.draw(this.board.matrix);
this.nextTurn();
};

// start from here
this.customStartMatrix = [
[0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0],
];

// plan ahead from here
this.customMatrix = [
[0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0],
];

this.nextTurn = function () {

let move;
let player;

if (this.turnnumber % 2 === 1) {
move = this.player1.getMove();
player = 1;

if (this.player1.identity !== "human") {

// alles in betweenturn
this.history.push(move);
this.board.makeMove(move, player);

this.nextTurnWait();
}

if (this.player1.identity === "human") {
// its a trap
let node = document.getElementsByClassName("column");
for (let i = 0; i < 7; i++) {
node[i].addEventListener("click", function () {
twisted.board.makeMove(i, 1);
twisted.nextTurnWait();
});
}

}

} else if (this.turnnumber % 2 === 0) {
move = this.player2.getMove();
player = 2;

if (this.player2.identity !== "human") {

// alles in betweenturn
this.history.push(move);
this.board.makeMove(move, player);

this.nextTurnWait();

}
if (this.player2.identity === "human") {
// its a trap
let node = document.getElementsByClassName("column");
for (let i = 0; i < 7; i++) {
node[i].addEventListener("click", function () {
twisted.board.makeMove(i, 2);
twisted.nextTurnWait();
});
}

}

}

};

this.nextTurnWait = function () {
this.board.drawMatrix();
let possibleWinner = twisted.board.getWinner();

fieldScore.draw(this.board.matrix);

this.turnnumber++;
if (possibleWinner === 0) {
setTimeout(function () {
twisted.nextTurn();
}, 200);
}

};

}
Loading

0 comments on commit 14788cd

Please sign in to comment.