MCPcopy Create free account
hub / github.com/asweigart/PythonStdioGames / constructor

Method constructor

javascript_games/ducklings.js:87–102  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

85
86class Duckling {
87 constructor() {
88 // Create a new duckling with random body features.
89 this.direction = [LEFT, RIGHT][Math.floor(Math.random() * 2)];
90 this.body = [CHUBBY, VERY_CHUBBY][Math.floor(Math.random() * 2)];
91 this.mouth = [OPEN, CLOSED][Math.floor(Math.random() * 2)];
92 this.wing = [OUT, UP, DOWN][Math.floor(Math.random() * 3)];
93
94 if (this.body === CHUBBY) {
95 // Chubby ducklings can only have beady eyes.
96 this.eyes = BEADY;
97 } else {
98 this.eyes = [BEADY, WIDE, HAPPY, ALOOF][Math.floor(Math.random() * 4)];
99 }
100
101 this.partToDisplayNext = HEAD;
102 }
103
104 getHeadStr() {
105 // Returns the string of the duckling's head.

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected