**Dice** You play by throwing a dice after which if the number on your side coincides with the number at the center, you earn points. The one who earns 10 point earlier than the other is the winner. \\ [[http://mycode.ucoz.net/files/spk/Dice_v1.spk|Here]] is the spk. //Called when application is started. var a = 0 var b =0 var chk = true function OnStart() { //Create a layout with objects vertically centered. lay = app.CreateLayout( "linear", "VCenter,Horizontal,FillXY" ); //Create Layout layhor= app.CreateLayout( "Linear", "VCenter" ); layhor.SetSize(0.45,1) //Create a text label and add it to layout. txt = app.CreateText( "You" ); txt.SetTextSize( 25 ); layhor.AddChild( txt ); lay.AddChild( layhor ); //Create Text txts = app.CreateText(0) layhor.AddChild(txts ); //CreateButton btn1 = app.CreateButton("Throw") btn1.SetOnTouch( clc ); layhor.AddChild(btn1 ); // Create text txtsc = app.CreateText(0) layhor.AddChild(txtsc ); //Create layout laycent= app.CreateLayout( "Linear", "Vcenter" ); laycent.SetSize(.1,1 ); //Create Text txtdice= app.CreateText( "45" ); txtdice.SetTextSize(35 ); laycent.AddChild( txtdice ); lay.AddChild(laycent ); //Create Layout layhor2 = app.CreateLayout( "Linear", "VCenter" ); layhor2.SetSize(0.45,1 ); txt2 = app.CreateText( "Phone" ); txt2.SetTextSize( 25 ); layhor2.AddChild( txt2 ); // Create Text texts = app.CreateText(0) layhor2.AddChild(texts ); //Create Button btn2 = app.CreateButton("Throw") btn2.SetOnTouch( clc2 ); layhor2.AddChild(btn2 ); // Create Text textsc = app.CreateText(0) layhor2.AddChild(textsc ); lay.AddChild( layhor2 ); //Add layout to app. app.AddLayout( lay ); } function clc() { txts.SetTextColor( "#ffffffff" ); if(chk){ texts.SetTextColor( "#44ffffff" ); txtdice.SetTextColor( "#ffffff" ); var num = Math.floor(Math.random()*10) var num2= Math.floor(Math.random()*10) txtdice.SetText(num ); txts.SetText(num2 ); if(num==num2){ a++ txtsc.SetText(a); txts.SetTextColor( "#22ff22" ); txtdice.SetTextColor( "#22ff22" ); over() } chk= false app.Wait(1.5) if(a<10||b<10){ app.SimulateTouch(btn2 ); } } else{app.ShowPopup("Not You")} } function clc2() { texts.SetTextColor( "#ffffffff" ); if(!chk){ txts.SetTextColor( "#44ffffff" ); txtdice.SetTextColor( "#ffffff" ); var num = Math.floor(Math.random()*10) var num2= Math.floor(Math.random()*10) txtdice.SetText(num ); texts.SetText(num2 ); if(num==num2){ b++ textsc.SetText(b); txtdice.SetTextColor( "#ff00ffff" ); texts.SetTextColor( "#ff00ffff" ); over() } chk = true } else{ app.ShowPopup("Not You" );} } function over(){ if(a>9){ alert( txt.GetText()+" have won") replay() } if(b>9){ alert("The "+txt2.GetText()+" has won") replay() } } function replay(){ if(confirm("Do you want to play again")){ a=0 b=0 txtsc.SetText(0); textsc.SetText(0 ); } else{app.Exit()} } [[:|Home]]>>[[sample_code:|Sample Code]]\\