summaryrefslogtreecommitdiff
path: root/apps/plugins
diff options
context:
space:
mode:
authorDaniel Stenberg <daniel@haxx.se>2003-07-24 09:40:15 +0000
committerDaniel Stenberg <daniel@haxx.se>2003-07-24 09:40:15 +0000
commit611e3592c71688e25c658b5178810bc6b0badb37 (patch)
tree9061b68d0ca32840bf9874621ef9fc9bd158ef31 /apps/plugins
parentafd704261e8189add57955c8bdc103d50c72ac0f (diff)
downloadrockbox-611e3592c71688e25c658b5178810bc6b0badb37.tar.gz
rockbox-611e3592c71688e25c658b5178810bc6b0badb37.zip
Pierre Delore's jackpot game plugin for the Player/Studio
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@3871 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'apps/plugins')
-rw-r--r--apps/plugins/jackpot.c278
1 files changed, 278 insertions, 0 deletions
diff --git a/apps/plugins/jackpot.c b/apps/plugins/jackpot.c
new file mode 100644
index 0000000000..7cf6e10588
--- /dev/null
+++ b/apps/plugins/jackpot.c
@@ -0,0 +1,278 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
9 *
10 * Copyright (C) 2003 Pierre Delore
11 *
12 * All files in this archive are subject to the GNU General Public License.
13 * See the file COPYING in the source tree root for full license agreement.
14 *
15 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
16 * KIND, either express or implied.
17 *
18 ****************************************************************************/
19/*
20History:
21* V1.0: 21/07/03
22 First version with a dirty definition of the patterns.
23* V1.1: 24/07/03
24 Clean definition of the patterns.
25 Init message change
26*/
27
28#include "plugin.h"
29
30#ifdef HAVE_LCD_CHARCELLS
31
32/* Jackpot game for the player */
33
34static unsigned char pattern[]={
35 0x00, 0x0A, 0x1F, 0x1F, 0x1F, 0x0e, 0x04, /* (+00)Coeur */
36 0x00, 0x04, 0x0E, 0x1F, 0x1F, 0x04, 0x0E, /* (+07)Pique */
37 0x00, 0x04, 0x0E, 0x1F, 0x0E, 0x04, 0x00, /* (+14)Carreau */
38 0x00, 0x15, 0x0E, 0x1F, 0x0E, 0x15, 0x00, /* (+21)Treffle */
39 0x03, 0x04, 0x0e, 0x1F, 0x1F, 0x1F, 0x0e, /* (+28)Cerise */
40 0x00, 0x04, 0x04, 0x1F, 0x04, 0x0E, 0x1F, /* (+35)Carreau */
41 0x04, 0x0E, 0x15, 0x04, 0x0A, 0x0A, 0x11, /* (+42)Homme */
42 0x00, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x00, /* (+49)Carre */
43 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* (+56)Empty */
44 0x00, 0x0A, 0x1F, 0x1F, 0x1F, 0x0e, 0x04 /* (+63)Coeur */
45};
46
47static unsigned char str[12]; /*Containt the first line*/
48static unsigned char h1,h2,h3; /*Handle for the pattern*/
49
50/* here is a global api struct pointer. while not strictly necessary,
51 it's nice not to have to pass the api pointer in all function calls
52 in the plugin */
53static struct plugin_api* rb;
54
55/*Display the first line*/
56static void display_first_line(int g)
57{
58 rb->snprintf(str,sizeof(str),"[ ]$%d",g);
59 rb->lcd_puts(0,0,str);
60
61 rb->lcd_putc(1,0, h1);
62 rb->lcd_putc(2,0, h2);
63 rb->lcd_putc(3,0, h3);
64}
65
66/*Call when the program exit*/
67static void jackpot_exit(void)
68{
69 /* Restore the old pattern (i don't find another way to do this. Any
70 idea?) */
71 rb->lcd_unlock_pattern(h1);
72 rb->lcd_unlock_pattern(h2);
73 rb->lcd_unlock_pattern(h3);
74
75 /* Clear the screen */
76 rb->lcd_clear_display();
77}
78
79
80/* this is the plugin entry point */
81enum plugin_status plugin_start(struct plugin_api* api, void* parameter)
82{
83 int i,button,w,j;
84 int s[3];
85 int n[3];
86 int g=20;
87 bool exit=false;
88 bool go;
89
90 /* this macro should be called as the first thing you do in the plugin.
91 it test that the api version and model the plugin was compiled for
92 matches the machine it is running on */
93 TEST_PLUGIN_API(api);
94
95 /* if you don't use the parameter, you can do like
96 this to avoid the compiler warning about it */
97 (void)parameter;
98
99 /* if you are using a global api pointer, don't forget to copy it!
100 otherwise you will get lovely "I04: IllInstr" errors... :-) */
101 rb = api;
102 rb->srand(*rb->current_tick);
103
104 /*Get the pattern handle*/
105 h1=rb->lcd_get_locked_pattern();
106 h2=rb->lcd_get_locked_pattern();
107 h3=rb->lcd_get_locked_pattern();
108
109 /*Init message*/
110 rb->lcd_define_pattern(h1, pattern);
111 rb->lcd_define_pattern(h2, pattern+7);
112 rb->lcd_define_pattern(h3, pattern+28);
113 rb->snprintf(str,sizeof(str),"%c%cJackpot%c%c",h1,h2,h2,h1);
114 rb->lcd_puts(0,0,str);
115 rb->snprintf(str,sizeof(str)," %c V1.1 %c",h3,h3);
116 rb->lcd_puts(0,1,str);
117 rb->sleep(HZ*2);
118 rb->lcd_clear_display();
119
120 /*First display*/
121 rb->snprintf(str,sizeof(str),"[ ]$%d",g);
122 rb->lcd_puts(0,0,str);
123 rb->lcd_puts_scroll(0,1,"PLAY to begin");
124
125 /*Empty the event queue*/
126 while (rb->button_get(false)!=BUTTON_NONE);
127
128 /* Define the start pattern */
129 s[0]=(rb->rand()%9)*7;
130 s[1]=(rb->rand()%9)*7;
131 s[2]=(rb->rand()%9)*7;
132
133 /*Main loop*/
134 while (!exit)
135 {
136 /*Keyboard loop*/
137 go=false;
138 while (!go)
139 {
140 button = rb->button_get(true);
141 switch ( button )
142 {
143 case BUTTON_STOP|BUTTON_REL:
144 exit = true;
145 go = true;
146 break;
147
148 case BUTTON_PLAY|BUTTON_REL:
149 exit = false;
150 if (g>0)
151 {
152 go = true;
153 g--;
154 }
155 break;
156
157 case SYS_USB_CONNECTED:
158 rb->usb_screen();
159 jackpot_exit();
160 return PLUGIN_USB_CONNECTED;
161 }
162 }
163
164 /*Clear the Second line*/
165 rb->lcd_puts_scroll(0,1,"Good luck");
166
167 /*GO !!!!*/
168 if ( go && !exit )
169 {
170 /* How many pattern? */
171 n[0]=(rb->rand()%15+5)*7;
172 n[1]=(rb->rand()%15+5)*7;
173 n[2]=(rb->rand()%15+5)*7;
174
175 display_first_line(g);
176 /* Jackpot Animation */
177 while((n[0]>=0) || (n[1]>=0) || (n[2]>=0))
178 {
179 if (n[0]>=0)
180 rb->lcd_define_pattern(h1, pattern+s[0]);
181 if (n[1]>=0)
182 rb->lcd_define_pattern(h2, pattern+s[1]);
183 if (n[2]>=0)
184 rb->lcd_define_pattern(h3, pattern+s[2]);
185 rb->sleep(HZ/24);
186 rb->lcd_putc(1,0, h1);
187 rb->lcd_putc(2,0, h2);
188 rb->lcd_putc(3,0, h3);
189 for(i=0;i<3;i++)
190 {
191 if (n[i]>=0)
192 {
193 n[i]--;
194 s[i]++;
195 if (s[i]>=63)
196 s[i]=0;
197 }
198 }
199 }
200
201 /* You won? */
202 s[0]--;
203 s[1]--;
204 s[2]--;
205 w=(s[0]/7)*100+(s[1]/7)*10+(s[2]/7);
206
207 j=0;
208 switch (w)
209 {
210 case 111 :
211 j=20;
212 break;
213 case 000 :
214 j=15;
215 break;
216 case 333 :
217 j=10;
218 break;
219 case 222 :
220 j=8;
221 break;
222 case 555 :
223 j=5;
224 break;
225 case 777 :
226 j=4;
227 break;
228 case 251 :
229 j=4;
230 break;
231 case 510 :
232 j=4;
233 break;
234 case 686 :
235 j=3;
236 break;
237 case 585 :
238 j=3;
239 break;
240 case 282 :
241 j=3;
242 break;
243 case 484 :
244 j=3;
245 break;
246 case 787 :
247 j=2;
248 break;
249 case 383 :
250 j=2;
251 break;
252 case 80 :
253 j=2;
254 break;
255 }
256 if (j==0)
257 {
258 rb->lcd_puts(0,1,"None...");
259 if (g<=0)
260 rb->lcd_puts_scroll(0,1,"You lose...STOP to quit");
261 }
262 else
263 {
264 g+=j;
265 display_first_line(g);
266 rb->snprintf(str,sizeof(str),"You win %d$",j);
267 rb->lcd_puts(0,1,str);
268 }
269 }
270 }
271
272 /* This is the end */
273 jackpot_exit();
274 /* Bye */
275 return PLUGIN_OK;
276}
277
278#endif