I like the game puzzle forge but its was way to easy once you learned the system, so I'm going to add "threes" like separate base elements (as opposed to its simplified clone 2048); or example the base elements are copper and iron, 3 of each make refined versions. 2 iron and 1 copper makes bronze, 2 copper 1 iron makes tin(?) etc.
I would like a proper functional like pattern matching to do this, because imagine that going out 4 or 5 tiers and the 4 and 5 combination cases, thats allot of messy if statements, I'm like nah. But google searches talk about string whatevers.
Also is there a better way to do this function? Besides cleaning up the repetition
Code: Select all
function combinecheck(x,y,size)
function touchingcheck(xx,yy,f)
if grid[xx][yy]==size then
f(xx,yy)
--------
if (not (x == xx+1 and y== yy ) and grid[xx+1][yy ]==size) then f(xx+1,yy ) end
if (not (x == xx-1 and y== yy ) and grid[xx-1][yy ]==size) then f(xx-1,yy ) end
if (not (x == xx and y== yy+1) and grid[xx ][yy+1]==size) then f(xx ,yy+1) end
if (not (x == xx and y== yy-1) and grid[xx ][yy-1]==size) then f(xx ,yy-1) end
end
end
touchingcount = 0
function count(xx,yy)
touchingcount = touchingcount + 1
end
function zero(xx,yy)
grid[xx][yy]= 0
end
touchingcheck(x+1,y ,count)
touchingcheck(x-1,y ,count)
touchingcheck(x ,y+1,count)
touchingcheck(x ,y-1,count)
------
if (touchingcount >= 2) then
touchingcheck(x+1,y ,zero)
touchingcheck(x-1,y ,zero)
touchingcheck(x ,y+1,zero)
touchingcheck(x ,y-1,zero)
grid[x][y]=size+1
combinecheck(x,y,size+1)
end
end