Asosiy kod...////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////
function rand(min:Number, max:Number):Number
{
return (Math.floor(Math.random()*(max-min+1))+min);
}
_global.space=0;
_global.tur=1;
var stat:Number=0;
var intervalID:Number = setInterval(myTimer, 2000);
function myTimer():Void {
var randcar:Number=rand(1,3);
_root.attachMovie("car"+randcar, "car1", i, {_x:rand(200,360),_y:-150});
//trace(Math.round(Math.random()*200));
stat++;
var format:TextFormat = new TextFormat();
format.size = 14;
format.font = "Arial";
format.align = "left";
_root.createTextField("stats_txt", 2, 3, 3, 530, 50);
stats_txt.bold;
stats_txt.textColor=0xffffff;
stats_txt.selectable = false;
stats_txt.text = "TUR "+tur;
stats_txt.setTextFormat(format);
_root.createTextField("mash_txt", 3, 3, 30, 530, 50);
mash_txt.bold;
mash_txt.selectable = false;
mash_txt.text ="Mashina "+stat;
mash_txt.textColor=0xffffff;
mash_txt.setTextFormat(format);
_root.createTextField("avar_txt", 4, 3, 60, 530, 50);
avar_txt.bold;
avar_txt.selectable = false;
avar_txt.text ="Xolat "+Math.round(_global.avar);
avar_txt.textColor=0xffffff;
avar_txt.setTextFormat(format);
}
function cfunc():Void
{
if (stat==15&&_global.avar>75) {tur++;stat=0; gotoAndplay("tur3");}
if (_global.avar<75) {stat=0; tur=1; _global.avar=100; gotoAndplay("play");}
if (car1.hitTest(car)==false){
car1._y+=20;}
else {
car1.gotoAndplay("hit");
car1._y+=50;
}
};
var carrun:Number= setInterval(cfunc,5);
////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////
1. tasodifiy sonlar generatori ishlatiladigan funktsiya. Biz bundan berilgan sonlar
oralig’idagi tasodifiy son generatori sifatida foydalanmiz.
function rand(min:Number, max:Number):Number
{
return (Math.floor(Math.random()*(max-min+1))+min);
}
Bu yerda
Math.floor
yaxlitlovchi matematik funktsiya.
Math.random()
tasodifiy sonlar generatori.
rand
identifikator funktsiyamiz nomi.
min:Number, max:Number funktsiyamiz parametrlari Number tipiga tegishli bu butun sonlar
tipiga mos keladi.
2. O’zgaruvchilarni ehlon qilish.
_global.space=0;
mashina tezligi. (Global o’zgaruvchi)
_global.tur=1;
navbatdagi turga optish (Global o’zgaruvchi)
var stat:Number=0;
rakib mashinalar soni
var intervalID:Number = setInterval(myTimer, 2000);
taymer vazifasini bajartirish o’zgaruvchisi
bu yerda
intervalID
identifikator
setinterval( );
2000 vakt birligida myTimer funktsiyani
yuklash buyrug’i.
var carrun:Number= setInterval(cfunc,5); xam mos ravishdagi buyruq.
var randcar:Number=rand(1,3);
rakib mashinani tanlash
o’zgaruvchisi
var format:TextFormat = new TextFormat();
{
format.size = 14;
format.font = "Arial";
format.align = "left";
}
Format nomi bilan ehlon qilingan matn formati .
3. Raqib mashinalarni tasodifiy tanlanishi va maydonga joylashtirilishi xamda statistik
mahlumotlar ekranga yozilishini tahminlaydigan fukntsiya
function myTimer():Void {
_root.attachMovie("car"+randcar, "car1", i, {_x:rand(200,360),_y:-150});
stat++;
_root.createTextField("stats_txt", 2, 3, 3, 530, 50);
stats_txt.bold;
stats_txt.textColor=0xffffff;
stats_txt.selectable = false;
stats_txt.text = "TUR "+tur;
stats_txt.setTextFormat(format);
_root.createTextField("mash_txt", 3, 3, 30, 530, 50);
mash_txt.bold;
mash_txt.selectable = false;
mash_txt.text ="Mashina "+stat;
mash_txt.textColor=0xffffff;
mash_txt.setTextFormat(format);
_root.createTextField("avar_txt", 4, 3, 60, 530, 50);
avar_txt.bold;
avar_txt.selectable = false;
avar_txt.text ="Xolat "+Math.round(_global.avar);
avar_txt.textColor=0xffffff;
avar_txt.setTextFormat(format);
}
Bu yerda
_root.attachMovie("car"+randcar, "car1", i, {_x:rand(200,360),_y:-150});
Funktsiyasi stsenamiz kutubxonasidan "car"+randcar nomli mashinani tanlab unga , "car1"
nom berib, x opqi bopylab rand(200,360), koprinishda u opqi bopylab -150 koordinatalarga
joylashtiradi.
stat++; mashinalar sonini jamlab turadigan o’zgaruvchi.
_root.createTextField("avar_txt", 4, 3, 60, 530, 50);
Matn maydonini yaratish buyrug’i. Bu yerda
"avar_txt"
matn maydoni nomi.
4
indeks
3,60
joylashish koordinatasi
530,50
matn maydoni bopyi va eni.
Mos ravishda
avar_txt.bold;
matn kalinlashtirish
avar_txt.selectable = false;
belgilanish ruxsat yo’q
avar_txt.text ="Xolat "+Math.round(_global.avar); matn
avar_txt.textColor=0xffffff;
matn rangi
avar_txt.setTextFormat(format);
matn formati ehlon qilingan formatda.
Dostları ilə paylaş: |