Added player class
This commit is contained in:
parent
df27b13e3b
commit
7b82f26def
18
src/index.js
18
src/index.js
@ -2,8 +2,9 @@ console.log('Uno Start')
|
||||
|
||||
import './css/uno-game.css';
|
||||
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)
|
||||
|
||||
@ -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')
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
export default class Card {
|
||||
constructor() {
|
||||
this._num = 0;
|
||||
this._color = 'red';
|
||||
constructor(num, color) {
|
||||
this._num = num;
|
||||
this._color = color;
|
||||
}
|
||||
get num() {
|
||||
return this._num;
|
||||
|
||||
16
src/js/player.js
Normal file
16
src/js/player.js
Normal 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)
|
||||
});
|
||||
}
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user