| 70 | |
| 71 | |
| 72 | class Duckling: |
| 73 | def __init__(self): |
| 74 | """Create a new duckling with random body features.""" |
| 75 | self.direction = random.choice([LEFT, RIGHT]) |
| 76 | self.body = random.choice([CHUBBY, VERY_CHUBBY]) |
| 77 | self.mouth = random.choice([OPEN, CLOSED]) |
| 78 | self.wing = random.choice([OUT, UP, DOWN]) |
| 79 | |
| 80 | if self.body == CHUBBY: |
| 81 | # Chubby ducklings can only have beady eyes. |
| 82 | self.eyes = BEADY |
| 83 | else: |
| 84 | self.eyes = random.choice([BEADY, WIDE, HAPPY, ALOOF]) |
| 85 | |
| 86 | self.partToDisplayNext = HEAD |
| 87 | |
| 88 | def getHeadStr(self): |
| 89 | """Returns the string of the duckling's head.""" |
| 90 | headStr = '' |
| 91 | if self.direction == LEFT: |
| 92 | # Get the mouth: |
| 93 | if self.mouth == OPEN: |
| 94 | headStr += '>' |
| 95 | elif self.mouth == CLOSED: |
| 96 | headStr += '=' |
| 97 | |
| 98 | # Get the eyes: |
| 99 | if self.eyes == BEADY and self.body == CHUBBY: |
| 100 | headStr += '"' |
| 101 | elif self.eyes == BEADY and self.body == VERY_CHUBBY: |
| 102 | headStr += '" ' |
| 103 | elif self.eyes == WIDE: |
| 104 | headStr += "''" |
| 105 | elif self.eyes == HAPPY: |
| 106 | headStr += '^^' |
| 107 | elif self.eyes == ALOOF: |
| 108 | headStr += '``' |
| 109 | |
| 110 | headStr += ') ' # Get the back of the head. |
| 111 | |
| 112 | if self.direction == RIGHT: |
| 113 | headStr += ' (' # Get the back of the head. |
| 114 | |
| 115 | # Get the eyes: |
| 116 | if self.eyes == BEADY and self.body == CHUBBY: |
| 117 | headStr += '"' |
| 118 | elif self.eyes == BEADY and self.body == VERY_CHUBBY: |
| 119 | headStr += ' "' |
| 120 | elif self.eyes == WIDE: |
| 121 | headStr += "''" |
| 122 | elif self.eyes == HAPPY: |
| 123 | headStr += '^^' |
| 124 | elif self.eyes == ALOOF: |
| 125 | headStr += '``' |
| 126 | |
| 127 | # Get the mouth: |
| 128 | if self.mouth == OPEN: |
| 129 | headStr += '<' |