-
can you make text in boxes randomly
-
Client Software Programmer
sometimes the random selected text will repeat I will leave it like that as ok with you?
PHP Code:
var current_selected=null
var drag_mode_enabled=false
var box_available=null
var circle_array=[circle_1,circle_2,circle_3,circle_4,circle_5,circle_6,circle_7,circle_8,circle_9]
var box_array=[box_1,box_2,box_3,box_4,box_5,box_6,box_7,box_8,box_9]
var text_array=['txt1','txt2','txt3','txt4','txt5','txt6','txt7','txt8','txt9']
for(var i=0;i<circle_array.length;i++){
circle_array[i].startX=circle_array[i]._x
circle_array[i].startY=circle_array[i]._y
}
for(var m=0;m<box_array.length;m++){
box_array[m].taken=false
box_array[m].num=m
box_array[m].data_field.text=text_array[randomBetween(0,text_array.length-1)]
box_array[m].onPress=function(){
if(this.taken==false){
drag_mode_enabled=true
box_available=this.num
}
}
}
for(var j=0;j<circle_array.length;j++){
circle_array[j].onPress=function(){
if(drag_mode_enabled){
this.swapDepths(300)
this.atBox=false
this.startDrag(5)
}
}
circle_array[j].onRelease=circle_array[j].onReleaseOutside=function(){
for(var k=0;k<box_array.length;k++){
trace(box_array[0]._width)
if(this.atBox==false&&distanceChecker(this._x,box_array[k]._x)<=box_array[0]._width/2&&distanceChecker(this._y,box_array[k]._y)<=box_array[0]._height/2&&box_array[k].taken==false&&box_available==k){
this.stopDrag(5)
this.enabled=false
this.data_field.text=box_array[k].data_field.text
box_array[k].taken=true
this._x=box_array[k]._x
this._y=box_array[k]._y
drag_mode_enabled=false
this.atBox=true
this._alpha=50
}else if(!this.atBox&&k==box_array.length-1){
this._alpha=100
this._x=this.startX
this._y=this.startY
this.stopDrag(5)
}
}
}
}
function randomBetween(a,b){
return(Math.floor(Math.random()*(b-a+1))+a);
}
function distanceChecker(a,b){
if(a>b){
return(a-b)
}else{
return(b-a);
}
}
-
can you make it without repeat please
-
Client Software Programmer
PHP Code:
var current_selected=null
var drag_mode_enabled=false
var box_available=null
var circle_array=[circle_1,circle_2,circle_3,circle_4,circle_5,circle_6,circle_7,circle_8,circle_9]
var box_array=[box_1,box_2,box_3,box_4,box_5,box_6,box_7,box_8,box_9]
var text_array=['txt1','txt2','txt3','txt4','txt5','txt6','txt7','txt8','txt9']
var random_temp=null;
for(var i=0;i<circle_array.length;i++){
circle_array[i].startX=circle_array[i]._x
circle_array[i].startY=circle_array[i]._y
}
for(var m=0;m<box_array.length;m++){
box_array[m].taken=false
box_array[m].num=m
random_temp=randomBetween(0,text_array.length-1)
box_array[m].data_field.text=text_array[random_temp]
text_array.splice(random_temp,1)
box_array[m].onPress=function(){
if(this.taken==false){
drag_mode_enabled=true
box_available=this.num
}
}
}
for(var j=0;j<circle_array.length;j++){
circle_array[j].onPress=function(){
if(drag_mode_enabled){
this.swapDepths(300)
this.atBox=false
this.startDrag(5)
}
}
circle_array[j].onRelease=circle_array[j].onReleaseOutside=function(){
for(var k=0;k<box_array.length;k++){
trace(box_array[0]._width)
if(this.atBox==false&&distanceChecker(this._x,box_array[k]._x)<=box_array[0]._width/2&&distanceChecker(this._y,box_array[k]._y)<=box_array[0]._height/2&&box_array[k].taken==false&&box_available==k){
this.stopDrag(5)
this.enabled=false
this.data_field.text=box_array[k].data_field.text
box_array[k].taken=true
this._x=box_array[k]._x
this._y=box_array[k]._y
drag_mode_enabled=false
this.atBox=true
this._alpha=50
}else if(!this.atBox&&k==box_array.length-1){
this._alpha=100
this._x=this.startX
this._y=this.startY
this.stopDrag(5)
}
}
}
}
function randomBetween(a,b){
return(Math.floor(Math.random()*(b-a+1))+a);
}
function distanceChecker(a,b){
if(a>b){
return(a-b)
}else{
return(b-a);
}
}
-
-
Client Software Programmer
Not a problem, those are functions I find myself using everyday on other projects.
Last edited by AS3.0; 01-21-2021 at 01:42 AM.
-
hello Alloy Bacon
when i press box1 i change text color = blue and it is ok by add this code to your script
PHP Code:
this.data_field._text.textColor = 0x0000FF;
and if i press another box , i want box1 text return red again
it means:
if i press any box = only this box text is blue and others is red
thanks for help
-
Client Software Programmer
PHP Code:
var current_selected=null
var drag_mode_enabled=false
var box_available=null
var circle_array=[circle_1,circle_2,circle_3,circle_4,circle_5,circle_6,circle_7,circle_8,circle_9]
var box_array=[box_1,box_2,box_3,box_4,box_5,box_6,box_7,box_8,box_9]
var text_array=['txt1','txt2','txt3','txt4','txt5','txt6','txt7','txt8','txt9']
var random_temp=null;
var prev_selected=null;
for(var i=0;i<circle_array.length;i++){
circle_array[i].startX=circle_array[i]._x
circle_array[i].startY=circle_array[i]._y
}
for(var m=0;m<box_array.length;m++){
box_array[m].taken=false
box_array[m].num=m
box_array[m].data_field.textColor=0xFF0000
random_temp=randomBetween(0,text_array.length-1)
box_array[m].data_field.text=text_array[random_temp]
text_array.splice(random_temp,1)
box_array[m].onPress=function(){
if(this.taken==false){
prev_selected.data_field.textColor=0xFF0000
this.data_field.textColor=0x0000FF
prev_selected=this
drag_mode_enabled=true
box_available=this.num
}
}
}
for(var j=0;j<circle_array.length;j++){
circle_array[j].onPress=function(){
if(drag_mode_enabled){
this.swapDepths(300)
this.atBox=false
this.startDrag(5)
}
}
circle_array[j].onRelease=circle_array[j].onReleaseOutside=function(){
for(var k=0;k<box_array.length;k++){
if(this.atBox==false&&distanceChecker(this._x,box_array[k]._x)<=box_array[0]._width/2&&distanceChecker(this._y,box_array[k]._y)<=box_array[0]._height/2&&box_array[k].taken==false&&box_available==k){
this.stopDrag(5)
this.enabled=false
this.data_field.text=box_array[k].data_field.text
box_array[k].taken=true
this._x=box_array[k]._x
this._y=box_array[k]._y
drag_mode_enabled=false
this.atBox=true
this._alpha=50
}else if(!this.atBox&&k==box_array.length-1){
this._alpha=100
this._x=this.startX
this._y=this.startY
this.stopDrag(5)
}
}
}
}
function randomBetween(a,b){
return(Math.floor(Math.random()*(b-a+1))+a);
}
function distanceChecker(a,b){
if(a>b){
return(a-b)
}else{
return(b-a);
}
}
-
thank you very much my friend
but when i change your script
PHP Code:
box_array[m].data_field._textColor=0xFF0000
to
PHP Code:
box_array[m].data_field._text.textColor=0xFF0000
now it is working with me
thanks for help
-
hello Alloy Bacon
how can i do this
if i droped into box1 and droped into box2 and droped into box3 = trace("Horizontal_1")
if i droped into box4 and droped into box5 and droped into box6 = trace("Horizontal_2")
if i droped into box7 and droped into box8 and droped into box9 = trace("Horizontal_3")
if i droped into box1 and droped into box4 and droped into box7 = trace("vertical_1")
if i droped into box2 and droped into box5 and droped into box8 = trace("vertical_2")
if i droped into box3 and droped into box6 and droped into box9 = trace("vertical_3")
if i droped into box1 and droped into box5 and droped into box9 = trace("curve_1")
if i droped into box3 and droped into box5 and droped into box7 = trace("curve_2")
I know this is difficult, but I am sure you can
thanks for help
-
Client Software Programmer
if there are multiple combo's that happened, the loop will output them all.
PHP Code:
var current_selected=null
var drag_mode_enabled=false
var box_available=null
var circle_array=[circle_1,circle_2,circle_3,circle_4,circle_5,circle_6,circle_7,circle_8,circle_9]
var box_array=[box_1,box_2,box_3,box_4,box_5,box_6,box_7,box_8,box_9]
var text_array=['txt1','txt2','txt3','txt4','txt5','txt6','txt7','txt8','txt9']
var random_temp=null;
var prev_selected=null;
for(var i=0;i<circle_array.length;i++){
circle_array[i].startX=circle_array[i]._x
circle_array[i].startY=circle_array[i]._y
}
for(var m=0;m<box_array.length;m++){
box_array[m].taken=false
box_array[m].num=m
box_array[m].data_field.textColor=0xFF0000
random_temp=randomBetween(0,text_array.length-1)
box_array[m].data_field.text=text_array[random_temp]
text_array.splice(random_temp,1)
box_array[m].onPress=function(){
if(this.taken==false){
prev_selected.data_field.textColor=0xFF0000
this.data_field.textColor=0x0000FF
prev_selected=this
drag_mode_enabled=true
box_available=this.num
}
}
}
for(var j=0;j<circle_array.length;j++){
circle_array[j].onPress=function(){
if(drag_mode_enabled){
this.swapDepths(300)
this.atBox=false
this.startDrag(5)
}
}
circle_array[j].onRelease=circle_array[j].onReleaseOutside=function(){
for(var k=0;k<box_array.length;k++){
if(this.atBox==false&&distanceChecker(this._x,box_array[k]._x)<=box_array[0]._width/2&&distanceChecker(this._y,box_array[k]._y)<=box_array[0]._height/2&&box_array[k].taken==false&&box_available==k){
this.stopDrag(5)
this.enabled=false
this.data_field.text=box_array[k].data_field.text
box_array[k].taken=true
this._x=box_array[k]._x
this._y=box_array[k]._y
drag_mode_enabled=false
this.atBox=true
this._alpha=50
checkCombo(box_array[k]._name.split("_")[1])
}else if(!this.atBox&&k==box_array.length-1){
this._alpha=100
this._x=this.startX
this._y=this.startY
this.stopDrag(5)
}
}
}
}
var combo_order=[0,1,2,"hor_1",3,4,5,"hor_2",6,7,8,"hor_3",0,3,6,"ver_1",1,4,7,"ver_2",2,5,8,"ver_3",0,4,8,"cur_1",2,4,6,"cur_2"]
var combo_array=[0,0,0, 0,0,0, 0,0,0]
function checkCombo(a){
combo_array[int(a)-1]=1
for(var i=0;i<combo_order.length;i+=4){
if(combo_array[combo_order[i]]==1&&combo_array[combo_order[i+1]]==1&&combo_array[combo_order[i+2]]==1){
trace(combo_order[i+3])//combo name that happened
}
}
}
function randomBetween(a,b){
return(Math.floor(Math.random()*(b-a+1))+a);
}
function distanceChecker(a,b){
if(a>b){
return(a-b)
}else{
return(b-a);
}
}
-
yes but the game have 2 players
player1 have 9 circles (circle_1,circle_2,circle_3......)
player2 have 9 circles (anyname_1,anyname_2,anyname_3......)
game start :
player1 ==> press any box and drag and drop circle_1 to this box
player2 ==> press any box and drag and drop anyname_1 to this box
the winer is who can makes his circle horizontal or vertical or curve
in your script any 3 circles are ok but i want only the same circles for one player
can you make it
excuse me for my bad english
thanks for help
-
Client Software Programmer
rename circle instance names to: circle_1_p1 circle_2_p1 etc..
new set of other 9 circles instance names to: circle_1_p2 circle_2_p2 etc..
PHP Code:
var current_selected=null
var drag_mode_enabled=false
var box_available=null
var player_turn=1
var circle_array_1=[circle_1_p1,circle_2_p1,circle_3_p1,circle_4_p1,circle_5_p1,circle_6_p1,circle_7_p1,circle_8_p1,circle_9_p1]
var circle_array_2=[circle_1_p2,circle_2_p2,circle_3_p2,circle_4_p2,circle_5_p2,circle_6_p2,circle_7_p2,circle_8_p2,circle_9_p2]
var box_array=[box_1,box_2,box_3,box_4,box_5,box_6,box_7,box_8,box_9]
var text_array=['txt1','txt2','txt3','txt4','txt5','txt6','txt7','txt8','txt9']
var random_temp=null;
var prev_selected=null;
for(var i=0;i<circle_array_1.length;i++){
circle_array_1[i].startX=circle_array_1[i]._x
circle_array_1[i].startY=circle_array_1[i]._y
circle_array_2[i].startX=circle_array_2[i]._x
circle_array_2[i].startY=circle_array_2[i]._y
}
for(var m=0;m<box_array.length;m++){
box_array[m].taken=false
box_array[m].num=m
box_array[m].data_field.textColor=0xFF0000
random_temp=randomBetween(0,text_array.length-1)
box_array[m].data_field.text=text_array[random_temp]
text_array.splice(random_temp,1)
box_array[m].onPress=function(){
if(this.taken==false){
prev_selected.data_field.textColor=0xFF0000
this.data_field.textColor=0x0000FF
prev_selected=this
drag_mode_enabled=true
box_available=this.num
}
}
}
for(var j=0;j<circle_array_1.length;j++){
circle_array_1[j].onPress=function(){
if(drag_mode_enabled&&player_turn==1){
this.swapDepths(300)
this.atBox=false
this.startDrag(5)
}
}
circle_array_2[j].onPress=function(){
if(drag_mode_enabled&&player_turn==2){
this.swapDepths(300)
this.atBox=false
this.startDrag(5)
}
}
circle_array_1[j].onRelease=circle_array_1[j].onReleaseOutside=circle_array_2[j].onRelease=circle_array_2[j].onReleaseOutside=function(){
for(var k=0;k<box_array.length;k++){
if(this.atBox==false&&distanceChecker(this._x,box_array[k]._x)<=box_array[0]._width/2&&distanceChecker(this._y,box_array[k]._y)<=box_array[0]._height/2&&box_array[k].taken==false&&box_available==k){
this.stopDrag(5)
this.enabled=false
this.data_field.text=box_array[k].data_field.text
box_array[k].taken=true
this._x=box_array[k]._x
this._y=box_array[k]._y
drag_mode_enabled=false
this.atBox=true
this._alpha=50
checkCombo(box_array[k]._name.split("_")[1])
if(player_turn==1){
player_turn=2;
}else{
player_turn=1
}
}else if(!this.atBox&&k==box_array.length-1){
this._alpha=100
this._x=this.startX
this._y=this.startY
this.stopDrag(5)
}
}
}
}
var combo_order=[0,1,2,"hor_1",3,4,5,"hor_2",6,7,8,"hor_3",0,3,6,"ver_1",1,4,7,"ver_2",2,5,8,"ver_3",0,4,8,"cur_1",2,4,6,"cur_2"]
var combo_array_p1=[0,0,0, 0,0,0, 0,0,0]
var combo_array_p2=[0,0,0, 0,0,0, 0,0,0]
function checkCombo(a){
if(player_turn==1){
combo_array_p1[int(a)-1]=1
}else{
combo_array_p2[int(a)-1]=1
}
for(var i=0;i<combo_order.length;i+=4){
if(player_turn==1&&combo_array_p1[combo_order[i]]==1&&combo_array_p1[combo_order[i+1]]==1&&combo_array_p1[combo_order[i+2]]==1){
trace("player 1 wins " + combo_order[i+3])//combo name that happened
}
if(player_turn==2&&combo_array_p2[combo_order[i]]==1&&combo_array_p2[combo_order[i+1]]==1&&combo_array_p2[combo_order[i+2]]==1){
trace("player 2 wins " + combo_order[i+3])//combo name that happened
}
}
}
function randomBetween(a,b){
return(Math.floor(Math.random()*(b-a+1))+a);
}
function distanceChecker(a,b){
if(a>b){
return(a-b)
}else{
return(b-a);
}
}
-
You are really a genius, my friend
but the player1 is always start
can you make it randomly it means if i press (random_player_start ) button = my be player1 or player2
thank you very very much
-
Client Software Programmer
You need to add a text field to the stage with an instance name of: data_field
PHP Code:
var current_selected=null
var drag_mode_enabled=false
var box_available=null
var player_turn=randomBetween(1,2)
data_field.text= "player "+ player_turn + " start."
var circle_array_1=[circle_1_p1,circle_2_p1,circle_3_p1,circle_4_p1,circle_5_p1,circle_6_p1,circle_7_p1,circle_8_p1,circle_9_p1]
var circle_array_2=[circle_1_p2,circle_2_p2,circle_3_p2,circle_4_p2,circle_5_p2,circle_6_p2,circle_7_p2,circle_8_p2,circle_9_p2]
var box_array=[box_1,box_2,box_3,box_4,box_5,box_6,box_7,box_8,box_9]
var text_array=['txt1','txt2','txt3','txt4','txt5','txt6','txt7','txt8','txt9']
var random_temp=null;
var prev_selected=null;
for(var i=0;i<circle_array_1.length;i++){
circle_array_1[i].startX=circle_array_1[i]._x
circle_array_1[i].startY=circle_array_1[i]._y
circle_array_2[i].startX=circle_array_2[i]._x
circle_array_2[i].startY=circle_array_2[i]._y
}
for(var m=0;m<box_array.length;m++){
box_array[m].taken=false
box_array[m].num=m
box_array[m].data_field.textColor=0xFF0000
random_temp=randomBetween(0,text_array.length-1)
box_array[m].data_field.text=text_array[random_temp]
text_array.splice(random_temp,1)
box_array[m].onPress=function(){
if(this.taken==false){
prev_selected.data_field.textColor=0xFF0000
this.data_field.textColor=0x0000FF
prev_selected=this
drag_mode_enabled=true
box_available=this.num
}
}
}
for(var j=0;j<circle_array_1.length;j++){
circle_array_1[j].onPress=function(){
if(drag_mode_enabled&&player_turn==1){
this.swapDepths(300)
this.atBox=false
this.startDrag(5)
}
}
circle_array_2[j].onPress=function(){
if(drag_mode_enabled&&player_turn==2){
this.swapDepths(300)
this.atBox=false
this.startDrag(5)
}
}
circle_array_1[j].onRelease=circle_array_1[j].onReleaseOutside=circle_array_2[j].onRelease=circle_array_2[j].onReleaseOutside=function(){
for(var k=0;k<box_array.length;k++){
if(this.atBox==false&&distanceChecker(this._x,box_array[k]._x)<=box_array[0]._width/2&&distanceChecker(this._y,box_array[k]._y)<=box_array[0]._height/2&&box_array[k].taken==false&&box_available==k){
this.stopDrag(5)
this.enabled=false
this.data_field.text=box_array[k].data_field.text
box_array[k].taken=true
this._x=box_array[k]._x
this._y=box_array[k]._y
drag_mode_enabled=false
this.atBox=true
this._alpha=50
if(player_turn==1){
player_turn=2;
data_field.text= "player "+ player_turn + "'s turn."
}else{
player_turn=1
data_field.text= "player "+ player_turn + "'s turn."
}
checkCombo(box_array[k]._name.split("_")[1])
}else if(!this.atBox&&k==box_array.length-1){
this._alpha=100
this._x=this.startX
this._y=this.startY
this.stopDrag(5)
}
}
}
}
var combo_order=[0,1,2,"hor_1",3,4,5,"hor_2",6,7,8,"hor_3",0,3,6,"ver_1",1,4,7,"ver_2",2,5,8,"ver_3",0,4,8,"cur_1",2,4,6,"cur_2"]
var combo_array_p1=[0,0,0, 0,0,0, 0,0,0]
var combo_array_p2=[0,0,0, 0,0,0, 0,0,0]
function checkCombo(a){
if(player_turn==1){
combo_array_p1[int(a)-1]=1
}else{
combo_array_p2[int(a)-1]=1
}
for(var i=0;i<combo_order.length;i+=4){
if(player_turn==1&&combo_array_p1[combo_order[i]]==1&&combo_array_p1[combo_order[i+1]]==1&&combo_array_p1[combo_order[i+2]]==1){
trace("player 1 wins " + combo_order[i+3])//combo name that happened
data_field.text="player 1 wins " + combo_order[i+3]
}
if(player_turn==2&&combo_array_p2[combo_order[i]]==1&&combo_array_p2[combo_order[i+1]]==1&&combo_array_p2[combo_order[i+2]]==1){
trace("player 2 wins " + combo_order[i+3])//combo name that happened
data_field.text="player 2 wins " + combo_order[i+3]
}
}
}
function randomBetween(a,b){
return(Math.floor(Math.random()*(b-a+1))+a);
}
function distanceChecker(a,b){
if(a>b){
return(a-b)
}else{
return(b-a);
}
}
Last edited by AS3.0; 01-21-2021 at 04:57 PM.
-
Client Software Programmer
//reset() to reset the game. I put a 5 second timer to reset after a win. // setTimeout(reset,5000)
PHP Code:
var current_selected=null
var drag_mode_enabled=false
var box_available=null
var player_turn=randomBetween(1,2)
data_field.text= "player "+ player_turn + " start."
var circle_array_1=[circle_1_p1,circle_2_p1,circle_3_p1,circle_4_p1,circle_5_p1,circle_6_p1,circle_7_p1,circle_8_p1,circle_9_p1]
var circle_array_2=[circle_1_p2,circle_2_p2,circle_3_p2,circle_4_p2,circle_5_p2,circle_6_p2,circle_7_p2,circle_8_p2,circle_9_p2]
var box_array=[box_1,box_2,box_3,box_4,box_5,box_6,box_7,box_8,box_9]
var text_array=['txt1','txt2','txt3','txt4','txt5','txt6','txt7','txt8','txt9']
var random_temp=null;
var prev_selected=null;
for(var i=0;i<circle_array_1.length;i++){
circle_array_1[i].startX=circle_array_1[i]._x
circle_array_1[i].startY=circle_array_1[i]._y
circle_array_2[i].startX=circle_array_2[i]._x
circle_array_2[i].startY=circle_array_2[i]._y
}
function reset(){
current_selected=null
drag_mode_enabled=false
for(var i=0;i<circle_array_1.length;i++){
box_array[i].data_field.textColor=0xFF0000
circle_array_1[i]._x=circle_array_1[i].startX
circle_array_1[i]._y=circle_array_1[i].startY
circle_array_1[i].data_field.text=""
circle_array_1[i]._alpha=100
circle_array_1[i].enabled=true
circle_array_2[i]._x=circle_array_2[i].startX
circle_array_2[i]._y=circle_array_2[i].startY
circle_array_2[i].data_field.text=""
circle_array_2[i]._alpha=100
circle_array_2[i].enabled=true
box_array[i].taken=false
}
combo_array_p1=[0,0,0, 0,0,0, 0,0,0]
combo_array_p2=[0,0,0, 0,0,0, 0,0,0]
player_turn=randomBetween(1,2)
data_field.text= "player "+ player_turn + " start."
}
for(var m=0;m<box_array.length;m++){
box_array[m].taken=false
box_array[m].num=m
box_array[m].data_field.textColor=0xFF0000
random_temp=randomBetween(0,text_array.length-1)
box_array[m].data_field.text=text_array[random_temp]
text_array.splice(random_temp,1)
box_array[m].onPress=function(){
if(this.taken==false){
prev_selected.data_field.textColor=0xFF0000
this.data_field.textColor=0x0000FF
prev_selected=this
drag_mode_enabled=true
box_available=this.num
}
}
}
for(var j=0;j<circle_array_1.length;j++){
circle_array_1[j].onPress=function(){
if(drag_mode_enabled&&player_turn==1){
this.swapDepths(300)
this.atBox=false
this.startDrag(5)
}
}
circle_array_2[j].onPress=function(){
if(drag_mode_enabled&&player_turn==2){
this.swapDepths(300)
this.atBox=false
this.startDrag(5)
}
}
circle_array_1[j].onRelease=circle_array_1[j].onReleaseOutside=circle_array_2[j].onRelease=circle_array_2[j].onReleaseOutside=function(){
for(var k=0;k<box_array.length;k++){
if(this.atBox==false&&distanceChecker(this._x,box_array[k]._x)<=box_array[0]._width/2&&distanceChecker(this._y,box_array[k]._y)<=box_array[0]._height/2&&box_array[k].taken==false&&box_available==k){
this.stopDrag(5)
this.enabled=false
this.data_field.text=box_array[k].data_field.text
box_array[k].taken=true
this._x=box_array[k]._x
this._y=box_array[k]._y
drag_mode_enabled=false
this.atBox=true
this._alpha=50
if(player_turn==1){
player_turn=2;
data_field.text= "player "+ player_turn + "'s turn."
}else if(player_turn==2){
player_turn=1
data_field.text= "player "+ player_turn + "'s turn."
}
checkCombo(box_array[k]._name.split("_")[1])
}else if(!this.atBox&&k==box_array.length-1){
this._alpha=100
this._x=this.startX
this._y=this.startY
this.stopDrag(5)
}
}
}
}
var combo_order=[0,1,2,"hor_1",3,4,5,"hor_2",6,7,8,"hor_3",0,3,6,"ver_1",1,4,7,"ver_2",2,5,8,"ver_3",0,4,8,"cur_1",2,4,6,"cur_2"]
var combo_array_p1=[0,0,0, 0,0,0, 0,0,0]
var combo_array_p2=[0,0,0, 0,0,0, 0,0,0]
function checkCombo(a){
if(player_turn==1){
combo_array_p1[int(a)-1]=1
}else{
combo_array_p2[int(a)-1]=1
}
for(var i=0;i<combo_order.length;i+=4){
if(player_turn==1&&combo_array_p1[combo_order[i]]==1&&combo_array_p1[combo_order[i+1]]==1&&combo_array_p1[combo_order[i+2]]==1){
trace("player 1 wins " + combo_order[i+3])//combo name that happened
data_field.text="player 1 wins " + combo_order[i+3]
player_turn=3
setTimeout(reset,5000);
}
if(player_turn==2&&combo_array_p2[combo_order[i]]==1&&combo_array_p2[combo_order[i+1]]==1&&combo_array_p2[combo_order[i+2]]==1){
trace("player 2 wins " + combo_order[i+3])//combo name that happened
data_field.text="player 2 wins " + combo_order[i+3]
player_turn=3
setTimeout(reset,5000);
}
}
}
function randomBetween(a,b){
return(Math.floor(Math.random()*(b-a+1))+a);
}
function distanceChecker(a,b){
if(a>b){
return(a-b)
}else{
return(b-a);
}
}
Last edited by AS3.0; 01-21-2021 at 05:24 PM.
-
you are a great person
-
it is possible to calculate time for drag and drop it means:
1- when player press box , new text field timer_over start = (20 second) 20 , 19 , 18 ...to 0
2- in a new text field new timer_up start (20 second) 1 , 2 , 3 ...to 20
3- when player drag and drop = calculate the time ( time : 5 second for example
4 in a new text field in circle = timer_up
thanks for help
-
Client Software Programmer
//the calculated ( time_start going down - time_drag going up ) is traced when the circle is in the box, but I dont see why to subtract this way.
//the circle time recounts down when redragged from an out of the blue release. ok?
you need to put on the stage a text field with instance name of: timer_over
you need to put in the circle a text field with instance name of: timer_up
// I changed startDrag(5) to startDrag(0) so you can read the text time, the mouse was covering the time.
PHP Code:
var current_selected=null
var drag_mode_enabled=false
var box_available=null
var player_turn=randomBetween(1,2)
data_field.text= "player "+ player_turn + " start."
var circle_array_1=[circle_1_p1,circle_2_p1,circle_3_p1,circle_4_p1,circle_5_p1,circle_6_p1,circle_7_p1,circle_8_p1,circle_9_p1]
var circle_array_2=[circle_1_p2,circle_2_p2,circle_3_p2,circle_4_p2,circle_5_p2,circle_6_p2,circle_7_p2,circle_8_p2,circle_9_p2]
var box_array=[box_1,box_2,box_3,box_4,box_5,box_6,box_7,box_8,box_9]
var text_array=['txt1','txt2','txt3','txt4','txt5','txt6','txt7','txt8','txt9']
var random_temp=null;
var prev_selected=null;
var counter_circle=null
var time_drag=0
for(var i=0;i<circle_array_1.length;i++){
circle_array_1[i].startX=circle_array_1[i]._x
circle_array_1[i].startY=circle_array_1[i]._y
circle_array_2[i].startX=circle_array_2[i]._x
circle_array_2[i].startY=circle_array_2[i]._y
}
function reset(){
current_selected=null
drag_mode_enabled=false
for(var i=0;i<circle_array_1.length;i++){
box_array[i].data_field.textColor=0xFF0000
circle_array_1[i]._x=circle_array_1[i].startX
circle_array_1[i]._y=circle_array_1[i].startY
circle_array_1[i].data_field.text=""
circle_array_1[i]._alpha=100
circle_array_1[i].enabled=true
circle_array_2[i]._x=circle_array_2[i].startX
circle_array_2[i]._y=circle_array_2[i].startY
circle_array_2[i].data_field.text=""
circle_array_2[i]._alpha=100
circle_array_2[i].enabled=true
box_array[i].taken=false
}
combo_array_p1=[0,0,0, 0,0,0, 0,0,0]
combo_array_p2=[0,0,0, 0,0,0, 0,0,0]
player_turn=randomBetween(1,2)
data_field.text= "player "+ player_turn + " start."
}
for(var m=0;m<box_array.length;m++){
box_array[m].taken=false
box_array[m].num=m
box_array[m].data_field.textColor=0xFF0000
random_temp=randomBetween(0,text_array.length-1)
box_array[m].data_field.text=text_array[random_temp]
text_array.splice(random_temp,1)
box_array[m].onPress=function(){
if(this.taken==false){
countDown(20)
prev_selected.data_field.textColor=0xFF0000
this.data_field.textColor=0x0000FF
prev_selected=this
drag_mode_enabled=true
box_available=this.num
}
}
}
for(var j=0;j<circle_array_1.length;j++){
circle_array_1[j].onPress=function(){
if(drag_mode_enabled&&player_turn==1){
this.swapDepths(300)
this.atBox=false
this.startDrag(0)
counter_circle=this
countUp("start")
}
}
circle_array_2[j].onPress=function(){
if(drag_mode_enabled&&player_turn==2){
this.swapDepths(300)
this.atBox=false
this.startDrag(0)
counter_circle=this
countUp("start")
}
}
circle_array_1[j].onRelease=circle_array_1[j].onReleaseOutside=circle_array_2[j].onRelease=circle_array_2[j].onReleaseOutside=function(){
for(var k=0;k<box_array.length;k++){
if(this.atBox==false&&distanceChecker(this._x,box_array[k]._x)<=box_array[0]._width/2&&distanceChecker(this._y,box_array[k]._y)<=box_array[0]._height/2&&box_array[k].taken==false&&box_available==k){
this.stopDrag(5)
this.enabled=false
this.data_field.text=box_array[k].data_field.text
box_array[k].taken=true
this._x=box_array[k]._x
this._y=box_array[k]._y
drag_mode_enabled=false
this.atBox=true
this._alpha=50
time_drag=count_down_time-count_up_number
clearTimeout(count_up_timeout)
trace(int(int(timer_over.text)-int(counter_circle.timer_up.text)))
if(player_turn==1){
player_turn=2;
data_field.text= "player "+ player_turn + "'s turn."
}else if(player_turn==2){
player_turn=1
data_field.text= "player "+ player_turn + "'s turn."
}
checkCombo(box_array[k]._name.split("_")[1])
}else if(!this.atBox&&k==box_array.length-1){
this._alpha=100
this._x=this.startX
this._y=this.startY
this.stopDrag(5)
}
}
}
}
var combo_order=[0,1,2,"hor_1",3,4,5,"hor_2",6,7,8,"hor_3",0,3,6,"ver_1",1,4,7,"ver_2",2,5,8,"ver_3",0,4,8,"cur_1",2,4,6,"cur_2"]
var combo_array_p1=[0,0,0, 0,0,0, 0,0,0]
var combo_array_p2=[0,0,0, 0,0,0, 0,0,0]
function checkCombo(a){
if(player_turn==1){
combo_array_p1[int(a)-1]=1
}else{
combo_array_p2[int(a)-1]=1
}
for(var i=0;i<combo_order.length;i+=4){
if(player_turn==1&&combo_array_p1[combo_order[i]]==1&&combo_array_p1[combo_order[i+1]]==1&&combo_array_p1[combo_order[i+2]]==1){
trace("player 1 wins " + combo_order[i+3])//combo name that happened
data_field.text="player 1 wins " + combo_order[i+3]
player_turn=3
setTimeout(reset,5000);
}
if(player_turn==2&&combo_array_p2[combo_order[i]]==1&&combo_array_p2[combo_order[i+1]]==1&&combo_array_p2[combo_order[i+2]]==1){
trace("player 2 wins " + combo_order[i+3])//combo name that happened
data_field.text="player 2 wins " + combo_order[i+3]
player_turn=3
setTimeout(reset,5000);
}
}
}
var count_down_time=null;
var count_down_timeout=null
function countDown(a){
if(a!=null){
clearTimeout(count_down_timeout)
count_down_time=a
}
if(count_down_time>-1){
timer_over.text=count_down_time
count_down_time--
count_down_timeout=setTimeout(countDown,1000);
}
}
var count_up_timeout=null
var count_up_number=0;
function countUp(a){
if(a=="start"){
clearTimeout(count_up_timeout)
count_up_number=1
}
if(counter_circle!=null){
counter_circle.timer_up.text=count_up_number
}
count_up_number++
count_up_timeout=setTimeout(countUp,1000,"continue");
}
function randomBetween(a,b){
return(Math.floor(Math.random()*(b-a+1))+a);
}
function distanceChecker(a,b){
if(a>b){
return(a-b)
}else{
return(b-a);
}
}
Last edited by AS3.0; 01-22-2021 at 02:45 AM.
-
yes i want timer_over return to 0 after droped
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|