User Tools

Site Tools


Sidebar

Privacy Policy

News

Version 2.50 is out since Jan 1st 2022


Frequently Asked Questions


Namespaces

Note for contributors

If you wish to create a new page in the DroidScript wiki, please click on the most appropriate namespace above and follow the notes for contributors there.

Because of spam, it has been necessary to add a CAPTCHA to the registration form and the save option for editing pages. You will not need to prove you are human if you are logged in, so please register.

Please feel free to improve any existing page, as well as adding new pages to increase the sum of public knowledge about DroidScript.

Formatting Syntax

sample_code:dice

This is an old revision of the document!


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.
Here is the spk.

dice.js
//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/dice.1472845850.txt.gz · Last modified: 2016/09/03 03:50 (external edit)