Tải bản đầy đủ (.doc) (62 trang)

Thực Tập Cơ Sở Lập Trình Game Di Động Với J2ME

Bạn đang xem bản rút gọn của tài liệu. Xem và tải ngay bản đầy đủ của tài liệu tại đây (1.29 MB, 62 trang )










 !"#$%&"'()*

  !"#$
Page 






+,"!-$



 !"
#$%&'()*+,-
.#/01%*+,-
2
*+,3%4562
3%4%&%708%77
%4 08%779
2 48%779


84:%4 08%77
%4 +%%4 08%77-
2;
#<%=>?0@ABCDE0 !3%4;
D8FG%4;
)HI001%%4;
2< !J K%4;
J0D& F%4&CL0KMN
O74%74% %22
%4% %2
8%77:% %01%8P%F:Q2;
+7R8S$% T F0U !2N
S0E2N
V
S7W8E/X

2SYJ0?RUZ/[01%8%4 2
S$A8G01%8%4  FC!
SYW8\G0U% %\IC!
Page 






9
(0]8 !3%4*+,01%4/4%79
3%4479
GF!AD&0K;

Page 2






."/01-
%&'()(*+,-(.(*./-!01-2345 647889:(.
;(1- !<'!=(> 345-?(@A3B0C5
-?'-.+3 (6:D(.--# (E3(F-?1.-.+3 BG
-H()--?I(JA5;-E+)*-+K-H()LMANB2$(JA-?#
O' A !-E-+&5-6A3J9(P+1-A5&'-?&
3-6-?4!()Q9R9STU5O'&'34>BV.3
-#4I.K9>4-W-&-?$34>()-!01-234(3--?I5J
-K46AX(JA5AN >4Y(K-55B
Page 






213
45/6-789!"#$
U5>4L-?#+5-Z-[\.3(E-E-B?E-JK(P(I4
?+1-]3A-?#()9(P+1-A5;!E]3J9^3.(J(E^
]3@;A-?#()_Q`5.H-1.K@'a
A-?#34>()B
3: ;$<=8=>?9@"0#$

:3.AW-;3A-?# ()^ A-?# UA5-3
\.3-/4A(E+)9:D-45#3-4DA545.^,]3-E-
+&B2;(K(JA!:@\.3-?Y+W-(HUBb-E;3-3c
\.3-/4(E^:3.;3F^L.W-dc4
()]3FBc4:3.^eJ+)9:D-945.^,45
#5f-?* A-?#d:3.B
A !+)
")A5413cYA5>34>4 ?A5+)(*G-? ^.H-
\.-?#!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-+&()B
7BB 4 q33
4F.s_33(*+&J.I([-54F+-> >BQF5^3.
(J(*.I-54F4]3-E-+&()B0J-IJ-4
_33i0? 3AQ3>y0QjA5+)+&4F+-> >9J14 '
.I4F+-> >]3-?#_33-5@;4(I!-?
Page ;






-E-+&()BJz3A5-E-+&5 f-?*0Q-#J-I!(*

-?#_Q`B
 !"#$%$&'
b#{V.-?#L/O' -E-+&()
7BBu W.#
W.#k%i >->9k4->%>> |.3- r-E-+&:E-H
!EKW.#j(&z3(P-4 0Q5(&z34)--*
AJ:6f-?*1?);-E-+&-.)A !k%B
7BB{ 1-?!
1-?!Qv%UiQ +A>v| ?43- %>>U? |A>y-@--E-+&
()j.WTUv-/-1 A-?#B1-?!(*L/
-?AW.#5.WK.-1^ -W.#B
(:H IFG?9'()*
BuB7 ")Qv%A>-
Page N






Qv%A>-A54)-O'_33(*-E-:E-(I!-?-E-+&()BQ)-
Qv%A>-O3A_33G+k%5Qv%UBQ)-+)Qv%A>-s44)-
 PK.Qv%A>-(*(JJG3.5w-? |A>_TRB}A>_TR^~
^5 15(P-5 (1- !B0W(K]3A-?#A5-! ?3Qv%A>-B
3.(/A5W.-?aA-?#]34)-Qv%A>-B
Q)-Qv%A>-Ju-OJ99ij9-J ij95@ J9K7ijB%
(/A54)-+):.A-?#]34)-Qv%A>-
5"K9
3+ ^M'A-E--? -1Qv%U5k%B
b54:-! )!? 9*L? ij

b54:-! (*-14)-A:Qv%A>-:()B
J99MNO
-O5(*Y++)\.ANO'::-! Qv%A>-5
4f:Qv%A>--?K-Z-?!-3.^>B
-J MNO
-O5Y+)\.ANO'4f:O'-!4Z
O'(3--B^M'3.^>T-3J4)--5.
]3Qv%A>-(I5+) O':B
Page V
import javax.microedition.midlet.*;
public classextends MIDlet
public void
public voidstartApp() { }
public voidpauseApp() { }
public voiddestroyApp







@ J9K7MNO
U-O5(*G:- -:hQv%A>-B?(J
J 5- 5+)(*AW+Qv%A>-B
JaNA5-W-O'Qv%A>-(*E-?3(K.:E-Z3-ZAQv%A>-J
^~-? Qv%UBkQv%A>-n4-? JPCL:"=K @"9"K:"@? 9:Q:k
5\.AN.:#^H]3O'Qv%A>-B
b#-?!-5c($]3QA>-
BuB TUv]3_Q`

Page 






b#•U/ATUv]3_Q`
_Q`.W34O(sY3 AQv%A>-BQO3 ibk>>Ajs4;
-5>L-+ L9} ?49TA>?-9k^-€mP(I4]3-54O
-WA5-D:.Ii:6GA!j -55:@
-I-3([-GN(*B5/4O-Wik ok>>AjCJCJBk
33^(*^M'-? -?#34>3O'e;
(H-*?+1-9(P(I4]3JA5D--D:.I9-3-3 -A5
(Ie(H-*A45#Bk33^dJ-I+,-^:1+n
WD4+W4B0#A54O-W w$A-?#-h34-3 -45
#B3A-?(K.n4-? JX()*'+'+',-
? -?#34>>4A54J^M'3-5-?9-? (J
-54O3 i>L-+ L9k^-9} ?4BBj(I-! 4>.34>c4O-W
i33^j(I-! ?3/-53 134>B
Page 






21(
'()* 2
U4)-(FJ-[\.3KA-?# ()9^3.(/>4L(*+,--3

5 A.@4)-4:E-O?W--a&]3_Q`A534>TUvBU3s4
34'
-1.AN-.E-34>TUv]3_Q`
@'A-?#_3334>]32>-+>3^
3: '()* 2
-E-3 5- 5J-IA5434>_Q`:E-OKA-?#()
_Q`95(P+1-A5-53 14O-W33^]3JBk33^
 w-3eA45#(1- !9Jf-?*e(H-*($
-n9($-?c9-@45.4)-G45#93J-I 4)-G45#
5 G(145(P-J5 f:€B0;@'-E-3J-IA54
(*4)--?#34>-Z((EO-!B.-$3A54
34>^e?W--H:w45:HA*@1A\.3(Ee3 1A5?W-AB
V.3-#4I.>4-W_Q`J4)-Jf-?*-H- A-?#34>YA5.
A534>TUvBA]3Jn4-?  javax.microedition.lcdui.game. Q)-^HA
\.3  -?Y  ]3  J    34>33^9  k3>?9  ?->^9  A>k3>?9  5
k3>?Q33>?B
• 34>33^:E-Z3-ZA33^9J-I (3A545#(1- !
• k3>?  D-  (*  ^M  '  -?  -E    (*  :E-  +  A  ?->  5
A>k3>?
Page 2
7 k33^
 kk3>?
u k?->
{ kA>k3>?
 kk3>?Q33>?







• ?->^A(I-! /-5(H-*.I()
• A>k3>?A(I-! :.:3.]334>5-! +(s
• k3>?Q33>?A\.AN?->^5A>k3>?
3^e(/-D-ZA4)-B
3:3 CJ=?JJ
34>33^:E--Z3-.)-D5-O]3A33^5J-4
4)-^H-O\.3-?Ya 14-$3-D- $(J-6
-H()?>|?>^]345#B2JJ-434?)^ 33^A52K??"$
-9rA*+h(.5 5R -SS rGG(14(IO3).
33^B
2K??"$-9
U-O  AW -@ -K  D4 +W4  ]3
(1- !(I+E-$Wa-#BmII.545-3,4?•W.-!
D4+W4]3(1- !B
Page 






b#‚2 :3>?>^{%9u?`- 
? 34>()$-3-$^M'D4O6(I-3 -BQ)-
34> 5CJ-IC-3 -D4O6A5lU9%ƒS29k`}9
Rvb5D4}vR`iD4+,jB3J-IGD4^H-O-3
D4O6+-?Bm1-Y3+H-?DD4O6(P-
3.(Ip-3 -B
Page 
Canvas






!""#$%
&
UP
DOWN
RIGH
T
LEFT
FIRE
lU
„%ƒS2
{k`}
•Rvb
}vR`






V.3-?A!-OE.4)--OAW
4F]3D4W--]3A33^A5^e:I4-?3-W-
D4L>4D45 W-#-O4]3A34>33^C
:I4-?3D4O6 (J-$3+E-(*D4+W4]3A
34>33^^e3]3A33^i:…-.-5YA5U AAv r
A*+h(.5 jB

0D'+E-D4+W4}vR`
b;31A,>4)-D4(*+W4+$G(*(P--? 
( !-?#APD]3-?#oA>i^R.j†€‡-L.W-
^M'JA5?W-AB
R -SS 
…  -.-  5  ^M  '    -O   !
 !(IAW).]333^5 5 +)(14Bˆ-]3
}?34>".||>?A54Y-3 -e-?33^^e(*-E-3 -G
(14^3.(JG-O"#! !(I(x)
.G(14?333^B0-E5-#}?34>".||>?J-H()eA
33^3A5e-?-EA33^#.#/
0%123!49-3C4W--43-3 -A5AW
).33^5 (H-*]3A?3^-O$ 95(x)
.-Z(H-*?3^5 33^-O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
J5 (J-> K.:4(ssB
"9"KT.I()
! #.I()]3/-+nwHA-E#
H3.B0D'-? 34>>4A54J^M'#/-iUA3>?j
5.I()(/-\.3-?c-!f]3JBmI-! (*#\.3
-#A54^3.
Page ;
Hnh 1 Hnh 2







b#92//Œ-UA3>?-? -?#34>
•-?J4)-AO37•h(*(^H-Z-> -O--Z-?^3
5-Z-?L.H9-> -O-5-#-?-! .I()\.3
]3/-B^M:D-]3-W4#AA5•{L•{L>A-#:D-]3
4f#hA57•L7•L>ABk?->.W4)-54-! ;3(I-! 
?->J.I()B
.#2!.#3!
• 43>(/A5Ai:D-•{j
• |?34>S-A5K.?)]34fhi7•j
• |?34>b>-A5K.3 ]34fhi7•j
+/$E.4.HJ.I()-3C-! 4)-4J^H-MA5^H
(I-! .I()9-?&]34A5C^H]3hw
-OB3Y.f(JA5R 5 B- = J:
0D'(I-! 4)-?->.I()s47•h-ZA-?(I-! -5
4)-.f#.I()\.3-?c*K.:4(ss9-?E--3
-! ?3(H-*^?->
$4.56.56
Page N






3.(J-! ?34C^H-I1 4)-.f|?34>^^3.
78#9$,.5.:.;.<.=.6.>.?.@.
5,.55.5:.5;.5<.5=
.HGA5.f (H-*^?->Z3:3+ B
&'9#9

E-\.]3+-3 --?A54)-.fH3.LEA
-E3.
10O-U"V9<K=-7W0#$=K5"
2E.4.H ?->I-&4)-|?34>'-I-3G-O
&'#
3J-I(&.I()+n-O
"'
""'
 =9$? K??"J"KT^3!4]3^?->J($+#;-
? A-?#34>-#:I4-?3^3!4;3/- P;3/-
(H-*:-$L.(*-D(EB0D'(I /-:@
w(*.I?3 5:.45#-#+E-(*:5
/-3!4+(IE.J!4($+-#^e([.I
*A!BQ)-D':9(IJ-I-D(I4 $-#+E-
(*:5 (!+,-?a\./(&Bk?->f-?*uA !+E-3!4
u(H-*:3.A5v43>9?->5A>k3>?B
     2!  .    .    .
AB"
 2!.AB"
Page V






     2!1B  .  A
B"
U-O-OW- +E-A1.J^3!4;3?->4)-:@B
@HA:E-Z3-ZAk3>?9A#:@J(I4-34E.

 (J-3L(&&-?DL5]3B34^H.HGL(&:I.3
!4A5-D-> -Z(I43-D-> ($+#;-]3
?->94P(&-?&5A5S?J -OA5E()L(&3!4(/A5L>4
Lw-($+]3?->5J3 3.3:@B
U-O-O3 +E-A1.?->J3!44)-?->::@
-O5C(ch3-34^H-34^H?->i(F+3 s4&-?D]3
J-?45#j5-34^HL>Ak>>A-#---O-OW-B
U-O.HGL(&A1.?->J3!44)-A>k3>?5 (J
3:@BU-O5G(IL(&?->J3!4(H-*
5 (J-? +(s3:@ŽNN(H-*-? +(s(/C:@
A5/-.I()B
> 4P(&-#E()L(&3!4A5-> ($+#;-]3
(H-*BE()5J(P(I4A5-3 -3 3!4C43
-D-(H9D'J4)-?->:D-uLu #]3
?->(JA!Cn4-? !4!•-Zi„9„j  i{9{j-? :.
($+]3?->B
mI:,'*(I45A?->.W4)--O wL
(&A!:.#;-B
Page 
Sprite
32
16






"#(..4!.
!!

0D'-?(IL(&3!4()DL3 -#-3(&z3
A!:.#;-^3.
&#(?.?.56.56
"/$+E-3!4^eDLBQPG-D- 3!4
3-?+#;-hBmIJ-IL(&DL^3!4-3
GE()L(&3!4-> UL>AB
2"L ?K??"J"KT3!4-> +D-
03!4-> UL>AL?3:(I4]34)-+-433 (I4
-O]34)-+-43:B.E()5(chK.DK
-$3L(&-> ($+;-B
X""Y"? "=Jr4(sY3
msY3 ]334> (* 3A543A ! A5/-i?->j 5:. K
i+3:? .?3^jB?->(FJ-?A5;/-.I()
-? 34>9-#+3:? .(*(&z3A5(sY3+/-
5A54@-?$(I/- !-()B
Q)--?#34>-$+3 s4?W-K.:.(sY3H-E
3.BQ)-:.A!s44)-^HA*A(H-*(sY3?->9A>9
?3^>L-€ (JJ4)--OA.-?;a^3  -E-:14
(*+)H!•]3(1- !B
0D'(/A54)-5:.-? 34>TA3o
Page 






b#77Q@Œ-^H:.-? 34>TA3S
2Lw-2#5 #e-?-3-W:K.]345#K(*AP
A!-3#^M'+)A.-W-#-?-3A.a!

43-?^H.-? (J4f-M-? 43-?-O4)--A>
-? AB
0D'C^M'4)-<A=J3-A>-#4)-43-?^3.(J-3J-Ie
(*4)-#KB

3(O)+,9V$Z"9"?
m^H-A>5-OA557-#4)-43-?^3.
Page 2






3^eJ-O4)-+3:? .
3HO)+,9F=[$K-@0\]=L^7@E$9_`9
"n^M'-A>(I-! +3:? .-3J-I-! ?3;+(s4
45:@-4B
3:a"? @7 =?JJ
QfAA>k3>?J4)-95(*3h-5-A>-> \.-,
-?94)-A>k3>?Js44)-4-A>(P--> -O-W-(&B•
]3A>k3>?(*/3?3K.-A>^5(*(^HBQ)-+(sJ-I
(*-! -Z4)-A>k3>?3K.A>k3>?B
b54-! ]3AA>k3>?^3.
  1B  .    4.    .  
2!.3!
Page 







•  A.4^A5^H)-]3A>k3>?93^H-A>^-? 4)-5
• R o^A5^H5]3A>k3>?93^H-A>^-? 4)-)-
• v43>A5]3A>k3>?
• -A>S-5-A>b>- +E-:D-]34)--A>
Q)-^H-O-3 -A>k3>?
4.H-3([).4)--A>]3A>k3>?-3J-O
".4.
ˆz3A5(P--A>J&-?Di A9? oj-? A>k3>?4)--A>JC^H
-A>v>LB
3dJ-I(P-4)-4K;--? A>k3>?+n4)--A>+n
-O
"#.4..(4.

•  A9? o9.4 A^9.R o^L(&4K;/-]-A>
• -A>v>LA5C^H]3-A>(>4]B
mIL(&C^H4)--A>-? A>k3>?-3G-O
.+A->->AAi- A9-? ojX
"? "9"Kr-A>()
A>A(*G(I-! ?3(H-*-z+(s9 (I-!
?34)-:.K-a&-3J-A>()i-A>5(A5-A>^
-3([#]3J^3.4)-.:#eA!45#jB-A>()A5;
(H-* !-():@&.^(K.:I]3$45 !-()->
.:#B+(I-! 4)--A>()^3.
mIL(&-A>5 A5-A>()-? 4)-A>k3>?-3G-O
C11
• ^-3-A>v>LA5C^H]3-A>-? A>k3>?
Page 

×