/* TIC TAC TOE
by AlexF
*/
var btns = [" "," "," "," "," "," "," "," "," "];
var Player=1;
var Round=0;
function OnStart() {
lay=app.CreateLayout("Linear","FillXY");
for (var i=1; i<4; i++) {
layN=app.CreateLayout("Linear", "Horizontal");
for (var j=1; j<4; j++) AddButton(layN,i,j); lay.AddChild( layN );
}
app.AddLayout(lay);
app.ShowPopup( "It's Player 1s turn!","bottom" );
}
function AddButton( layN,i,j) {
btn = app.CreateButton( btns[3*(i-1)+j-1],0.3,0.2,"Alum" );
btn.SetTextSize(60);
btn.SetOnTouch( tap );
layN.AddChild( btn );
}
function tap() {
Btn=app.GetLastButton();
btntxt=Btn.GetText();
if ((btntxt != "O") && (btntxt != "X")) {
btns[btntxt.length -1] = Player
Btn.SetText(("XO")[Player-1]);
proof();
Player=3-Player;
app.ShowPopup( "It's Player " +Player+ "s turn!" ,"bottom");
}
}
function proof()
{
Round++
for (var i=0; i<8; i++) {
var row = "";
for (var j=0; j<3; j++) row += btns[["123","456","789","147","258","369","159","753"][i][j]-1];
if (row == "111" || row =="222") {
alert("Player "+ Player + " won!")
app.Exit();
}
}
if(Round==9) {alert("Draw!"); app.Exit()}
}
I assume when Manuel suggested AI, he wants the app to be able to play against the user.
I like the rotated text for playing across a table but it would be nice to have an option to turn it off, when players are not situated like that.
Can I also suggest for the old and forgetful like me that there be some indication on the screen of whether the current user is playing "O" or "X"
Perhaps something as simple as
txt1= PlayerText( "Player 1 (X)\nPoints : 0" );
And finally, can you please explain why you are using app.Execute()
Can you please tell me how to pause the app with app.Alert() like alert()? Because I can't set a headline with alert()
I need it because if both players are computers multiple dialogs will open - so I changed it to alert() for now.
Thanks and best regards
Alex :)
function strCount(str, sought)
{
var arr = str.split(sought);
return arr.length -1;
}
They need to be at least in beta before it knows about them.
It looks like you must have used a new alpha feature.
When the spk does not work in previous versions, what line does it fail on?
If that does not help, is there anything in the release notes you recognise https://groups.google.com/d/msg/droidscriptbeta/j_NKgLkUvDU/1Vmp1VGlAAAJ ?
As far as the permissions are concerned, they also usually only change if you use an extra feature, though they can be fooled by comments.
If your apk is asking for permissions you don't need, we can fix that with a build.json file.
In previous versions the error was shown every time on the first line of code
I dont know how to use build.json
Thanks for your help :)
I suggest trying
settings.SetVisibilty("Show");
and
settings.SetVisibilty("Hide");
if( round==3 )
if( order[2]%2 )
if( order[0]%2 ) pos=[1,3,5,7]
else pos=[0,2,6,8]
else pos=[1,3,5,7]
%2?
order list the buttons in the order they're pressed.
%2 =0 -> corner/middle
=1 -> edge
I found some methods to win in impossible mode. I'll fix them.
Hm I already made it slow, but I can make it slower