-
Notifications
You must be signed in to change notification settings - Fork 0
/
99bottles.c
158 lines (147 loc) · 4.37 KB
/
99bottles.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
//A program to display and "sing" "99 Bottles of Beer on the Wall"
//Written by Matt Goldman
//Last Updated: 2013-07-30
#define TEMPO 300 //BPM
#define QNOTE (3600/TEMPO)
#define PlayNote(_a,_b) PlayImmediateTone(_a,(_b-3));wait10Msec(_b)
task main(){
int iBotts=99;
string sBotts="";
bool go=true;
int syls=3;//"nine-ty nine" has 3 syllables
int nextsyls=0;
eraseDisplay();
nVolume=kMaxVolumeLevel;
while(go){
//DISPLAY LYRICS
sprintf(sBotts,"%d",iBotts);
//need to use these dumb temp strings because ROBOTC 3.60 doesn't let you
// put the ?: in the display function arguments
string temp1=(iBotts>0?sBotts:"No");
string temp2=(iBotts==1?"":"s");
//nxtDisplayCenteredTextLine(0,"%s bottle%s of",(iBotts>0?sBotts:"No"),(iBotts==1?"":"s"));
nxtDisplayCenteredTextLine(0,"%s bottle%s of",temp1,temp2);
nxtDisplayCenteredTextLine(1,"beer on the wall");
//nxtDisplayCenteredTextLine(2,"%s bottle%s of",(iBotts>0?sBotts:"No"),(iBotts==1?"":"s"));
nxtDisplayCenteredTextLine(2,"%s bottle%s of",temp1,temp2);
nxtDisplayCenteredTextLine(3,"beer!");
if(iBotts==0){
nxtDisplayCenteredTextLine(4,"Go to the store,");
nxtDisplayCenteredTextLine(5,"buy some more,");
go=false;
}
else{
nxtDisplayCenteredTextLine(4,"Take one down,");
nxtDisplayCenteredTextLine(5,"pass it around,");
}
sprintf(sBotts,"%d",(iBotts==0?iBotts=99:--iBotts));
temp1=(iBotts>0?sBotts:"No");
temp2=(iBotts==1?"":"s");
//nxtDisplayCenteredTextLine(6,"%s bottle%s of",(iBotts>0?sBotts:"No"),(iBotts==1?"":"s"));
nxtDisplayCenteredTextLine(6,"%s bottle%s of",temp1,temp2);
nxtDisplayCenteredTextLine(7,"beer on the wall!");
//add syllables
if(iBotts/10==7)
nextsyls=4;
else if(iBotts/10==1)
nextsyls=2;
else if(iBotts/10==0)
nextsyls=1;
else
nextsyls=3;
if(iBotts%10==7)
nextsyls++;
else if(iBotts%10==0)
nextsyls--;
if(iBotts==11)
nextsyls=11;//special case for e-LEV-en
else if(iBotts==12 || iBotts==0)
nextsyls=1;
//PLAY MUSIC
//FIRST LINE
if(syls==2){
PlayNote(587,(2*QNOTE));//sev-
PlayNote(587,QNOTE);//en
}
else if(syls==11){
PlayNote(587,(QNOTE/2));//e-
PlayNote(587,(3*QNOTE)/2);//LEV-
PlayNote(587,(QNOTE));//en
}
else{
for(int i=0;i<syls;++i)
{PlayNote(587,(3*QNOTE)/syls);}//nine-
}
PlayNote(440,QNOTE);//bott-
PlayNote(440,QNOTE);//les
PlayNote(440,QNOTE);//of
PlayNote(587,QNOTE);//beer
PlayNote(587,QNOTE);//on
PlayNote(587,QNOTE);//the
PlayNote(587,3*QNOTE);//wall
//SECOND LINE
if(syls==2){
PlayNote(660,(2*QNOTE));//sev-
PlayNote(660,QNOTE);//en
}
else if(syls==11){
PlayNote(660,(QNOTE/2));//e-
PlayNote(660,(3*QNOTE)/2);//LEV-
PlayNote(660,(QNOTE));//en
}
else{
for(int i=0;i<syls;++i)
{PlayNote(660,(3*QNOTE)/syls);}//nine-
}
PlayNote(494,QNOTE);//bott-
PlayNote(494,QNOTE);//les
PlayNote(494,QNOTE);//of
PlayNote(660,3*QNOTE);//beer!
PlayNote(0,3*QNOTE);
//THIRD LINE
if(iBotts==99){
PlayNote(554,QNOTE);//go
PlayNote(554,QNOTE);//to
PlayNote(554,QNOTE);//the
PlayNote(554,3*QNOTE);//store
}
else{
PlayNote(554,2*QNOTE);//take
PlayNote(554,QNOTE);//one
PlayNote(554,3*QNOTE);//down
}
if(iBotts==99){
PlayNote(554,2*QNOTE);//buy
PlayNote(554,QNOTE);//some
PlayNote(554,3*QNOTE);//more
}
else{
PlayNote(554,QNOTE);//pass
PlayNote(554,QNOTE);//it
PlayNote(554,QNOTE);//a-
PlayNote(554,3*QNOTE);//round
}
//FOURTH LINE
if(nextsyls==2){
PlayNote(440,(2*QNOTE));//sev-
PlayNote(440,QNOTE);//en
}
else if(nextsyls==11){
PlayNote(440,(QNOTE/2));//e-
PlayNote(440,(3*QNOTE)/2);//LEV-
PlayNote(440,(QNOTE));//en
}
else{
for(int i=0;i<nextsyls;++i)
{PlayNote(440,(3*QNOTE)/nextsyls);}//nine-
}
PlayNote(494,QNOTE);//bott-
PlayNote(494,QNOTE);//les
PlayNote(554,QNOTE);//of
PlayNote(587,QNOTE);//beer
PlayNote(587,QNOTE);//on
PlayNote(587,QNOTE);//the
PlayNote(587,3*QNOTE);//wall
syls=nextsyls;
}
}