Added player class

This commit is contained in:
Eunchong Kim 2021-07-17 10:44:13 +09:00
parent df27b13e3b
commit 7b82f26def
3 changed files with 36 additions and 4 deletions

View File

@ -2,8 +2,9 @@ console.log('Uno Start')
import './css/uno-game.css'; import './css/uno-game.css';
import Card from './js/card.js'; import Card from './js/card.js';
import Player from './js/player.js';
let card = new Card(); let card = new Card(1, 'green');
console.log(card.num) console.log(card.num)
@ -13,4 +14,19 @@ document.addEventListener('DOMContentLoaded', () => {
}); });
const _all_colors = ['red', 'yellow', 'green', 'blue'];
function generateCards() {
let cards = [];
for (let i=0; i<7; i++) {
cards.push({
num: Math.floor( Math.random() * 14 ),
color: _all_colors[ Math.floor( Math.random() * 4 ) ],
});
}
const player = new Player(cards);
player.printCards();
}
generateCards()
console.log('Uno End') console.log('Uno End')

View File

@ -1,7 +1,7 @@
export default class Card { export default class Card {
constructor() { constructor(num, color) {
this._num = 0; this._num = num;
this._color = 'red'; this._color = color;
} }
get num() { get num() {
return this._num; return this._num;

16
src/js/player.js Normal file
View File

@ -0,0 +1,16 @@
import Card from './card.js';
export default class Player {
constructor(cards) {
this._n = cards.length;
this._cards = [];
cards.forEach( (card) => {
this._cards.push( new Card( card['num'], card['color'] ) );
});
}
printCards() {
this._cards.forEach( (card) => {
console.log(card.num)
});
}
}