0
Candycrush code

I have to make a simple candycrush-like game code in scilab, I have managed to get elements in a matrix to move to other places, but what can I do to make those items to disappear when 3 of them have the same value, and then make the matrix replace the new free slots in it?

PLEASE HELP, ITS URGENT.

function candycrush()

a=ceil(rand(8,8)*4)
disp(a)
f=input("Select the row you wish to move: ")
c=input("Select the column you wish to move: ")
m=input("Select the direction you want to move in:")
t=1 //number of turns, maximum of 20//
p=0 //number of points//
    if m==1 then
        temp=a(f,c)
        a(f,c)=a(f-1,c)
        a(f-1,c)=temp
        t=(t+1)
    elseif m==2 then
        temp=a(f,c)
        a(f,c)=a(f+1,c)
        a(f+1,c)=temp
        t=(t+1)
    elseif m==3 then
        temp=a(f,c)
        a(f,c)=a(f,c+1)
        a(f,c+1)=temp
        t=(t+1)
    elseif m==4 then
        temp=a(f,c)
        a(f,c)=a(f,c-1)
        a(f,c-1)=temp
        t=(t+1)
    end
//My question is in this part of the code, when 3 items match, how to make them go and be replaced
    if a(f,c)=a(f-2,c) & a(f,c)=a(f-3,c) then
    elseif a(f,c)=a(f+2,c) & a(f,c)=a(f+3,c) then
    elseif a(f,c)=a(f,c+2) & a(f,c)=a(f,c+3) then
    elseif a(f,c)=a(f,c-2) & a(f,c)=a(f,c-3) then
    end



//Up=1 Down=2 Right=3 Left=4//
disp(a)
endfunction


Scilab 07-05-19, 6:38 a.m. luisdri
0

Let us say you have to remove k tiles from row f to f+k from column c and refill it. A function will help here:

function removetiles(a,k,f,c)
    a(1+k:f+k,c) = a(1:f,c)
    for tile=k:-1:1 do
         a(tile,c) = rand(8,8)
endfunction

For pure horizontal matching, k will be 1, f will be the row number, and c will be the three column numbers from which you have to remove.

For pure vertical matching, k will be 3, f will be the three row numbers, and c will be the column number from which you have to remove.

28-06-19, 5:36 p.m. sunilshetye
function removetiles(a,k,f,c)
    a(1+k:f+k,c) = a(1:f,c)
    for tile=k:-1:1 do
         a(tile,c) = rand(8,8)
end
endfunction

28-06-19, 5:46 p.m. sunilshetye

Login to add comment


-1
Window are mostly used in operating system fix connections to wireless displays in windows 10 how to fix connections for bluetooth audio devices and wireless displays in windows 10.
10-11-21, 5:44 p.m. berlin0099


Log-in to answer to this question.