| 84 | } |
| 85 | |
| 86 | class 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. |
| 106 | let headStr = ''; |
| 107 | if (this.direction === LEFT) { |
| 108 | // Get the mouth: |
| 109 | if (this.mouth === OPEN) { |
| 110 | headStr += '>'; |
| 111 | } else if (this.mouth === CLOSED) { |
| 112 | headStr += '='; |
| 113 | } |
| 114 | |
| 115 | // Get the eyes: |
| 116 | if (this.eyes === BEADY && this.body === CHUBBY) { |
| 117 | headStr += '"'; |
| 118 | } else if (this.eyes === BEADY && this.body === VERY_CHUBBY) { |
| 119 | headStr += '" '; |
| 120 | } else if (this.eyes === WIDE) { |
| 121 | headStr += "''"; |
| 122 | } else if (this.eyes === HAPPY) { |
| 123 | headStr += '^^'; |
| 124 | } else if (this.eyes === ALOOF) { |
| 125 | headStr += '``'; |
| 126 | } |
| 127 | |
| 128 | headStr += ') '; // Get the back of the head. |
| 129 | } |
| 130 | |
| 131 | if (this.direction === RIGHT) { |
| 132 | headStr += ' ('; // Get the back of the head. |
| 133 | |
| 134 | // Get the eyes: |
| 135 | if (this.eyes === BEADY && this.body === CHUBBY) { |
| 136 | headStr += '"'; |
| 137 | } else if (this.eyes === BEADY && this.body === VERY_CHUBBY) { |
| 138 | headStr += ' "'; |
| 139 | } else if (this.eyes === WIDE) { |
| 140 | headStr += "''"; |
| 141 | } else if (this.eyes === HAPPY) { |
| 142 | headStr += '^^'; |
| 143 | } else if (this.eyes === ALOOF) { |
nothing calls this directly
no outgoing calls
no test coverage detected