Code: Alles auswählen
#!/usr/bin/env node
'use strict';
const MOVES = ['rock', 'paper', 'scissors'];
class Player {
move() {
return 'rock';
}
learn(myMove, otherMove) {}
}
function beats(move, counterMove) {
return move === 'rock' && counterMove === 'scissors' ||
move === 'scissors' && counterMove === 'paper' ||
move === 'paper' && counterMove === 'rock';
}
class Game {
constructor(playerA, playerB) {
this.playerA = playerA;
this.playerB = playerB;
}
playRound() {
const moveA = this.playerA.move();
const moveB = this.playerB.move();
console.log('Player 1: ' + moveA + ' Player 2: ' + moveB);
this.playerA.learn(moveA, moveB);
this.playerB.learn(moveB, moveA);
}
playGame() {
console.log('Game start!');
for (var i = 0; i < 3; i++) {
console.log('Round ' + i + ':');
this.playRound();
}
console.log('Game over!');
}
}
function main() {
const game = new Game(new Player(), new Player());
game.playGame();
};
if (require.main === module) {
main();
}