Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Nums={};Nums[2]="║░░2░░░║";Nums[4]="║▒▒4▒▒▒║";Nums[8]="║▓▓8▓▓▓║";Nums[16]="║██16██║";Nums[32]="║██32██║";Nums[64]="║██64██║";Nums[128]="║█128██║";Nums[256]="║█256██║"
- Nums[512]="║█512██║";Nums[1024]="║█1024█║";Nums[2047]="║WINNER║";Nums[2048]="║█2048█║";Nums[4096]="║█4096█║";Nums[8192]="║█8192█║";Nums[16385]="║Wowie!║";Nums[16384]="║16384█║";Nums[32768]="║32768█║";Nums[65536]="║65536█║"
- Nums[131072]="║131072║";Nums[0]="║ ║"
- score=0
- Slt={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}
- failed=false
- Recurses=0
- kc=0
- math.randomseed(math.random(os.time()))
- function fixdd()
- for fff=1,16,1 do
- if (Slt[fff]==2047) then
- Slt[fff]=2048
- end
- if (Slt[fff]==16385) then
- Slt[fff]=16384
- end
- end
- end
- function checkLose()
- local losecheck = 0
- local failupdown=true
- local failleftright=true
- for checklinetop=1, 4, 1 do
- losecheck = checklinetop
- for checklinesub=checklinetop+4, checklinetop+12, 4 do
- if Slt[checklinesub]==0 then
- failupdown=false
- end
- if Slt[checklinesub]==Slt[losecheck] then
- failupdown=false
- else
- losecheck=checklinesub
- end
- end
- end
- for checklineside=1, 13, 4 do
- losecheck = checklineside
- for checklinesude=checklineside+1, checklineside+3, 1 do
- if Slt[checklinesude]==0 then
- failleftright=false
- end
- if Slt[checklinesude]==Slt[losecheck] then
- failleftright=false
- else
- losecheck=checklinesub
- end
- end
- end
- if (failupdown==false) or (failleftright==false) then
- failed=false
- else
- failed=true
- end
- end
- function left()
- fixdd()
- os.execute("clear")
- if kc==4 or kc==6 then
- if kc==6 then
- print("!??")
- else
- print("!?")
- end
- kc=kc+1
- else
- kc=0
- end
- movemade=false
- for row=1, 13, 4 do
- TV=row
- FMP=0
- if Slt[row]==0 then
- FMP=row
- end
- for column=row+1, row+3, 1 do
- if Slt[column]~=0 then
- if Slt[column]==Slt[TV] then
- score=score+Slt[TV]*2
- Slt[TV]=Slt[TV]*2
- Slt[column]=0
- movemade=true
- TV=column
- else
- TV=column
- end
- end
- if Slt[column]~=0 then
- if FMP~=0 then
- Slt[FMP]=Slt[column]
- Slt[column]=0
- TV=FMP
- FMP=FMP+1
- movemade=true
- end
- else
- if FMP==0 then
- FMP=column
- end
- end
- end
- end
- if(movemade==true) then
- newBlock()
- checkLose()
- end
- drawUI()
- end
- function right()
- fixdd()
- os.execute("clear")
- if kc==5 or kc==7 then
- if kc==7 then
- print("!??")
- else
- print("!?")
- end
- kc=kc+1
- else
- kc=0
- end
- movemade=false
- for row=4, 16, 4 do
- TV=row
- FMP=0
- if Slt[row]==0 then
- FMP=row
- end
- for column=row-1, row-3, -1 do
- if Slt[column]~=0 then
- if Slt[column]==Slt[TV] then
- score=score+Slt[TV]*2
- Slt[TV]=Slt[TV]*2
- Slt[column]=0
- movemade=true
- TV=column
- else
- TV=column
- end
- end
- if Slt[column]~=0 then
- if FMP~=0 then
- Slt[FMP]=Slt[column]
- Slt[column]=0
- TV=FMP
- FMP=FMP-1
- movemade=true
- end
- else
- if FMP==0 then
- FMP=column
- end
- end
- end
- end
- if(movemade==true) then
- newBlock()
- checkLose()
- end
- drawUI()
- end
- function start()
- if kc==10 then
- os.execute("clear")
- Slt={2047,2047,2047,2047,4096,4096,4096,4096,8192,8192,8192,8192,16385,16385,16385,16385}
- score=1203012314000000000000000000000000
- drawUI("WOWOWOWOW")
- else
- print("(debug command):1: attempt to call global 'start' (a nil value)")
- end
- end
- function up()
- fixdd()
- os.execute("clear")
- movemade=false
- for row=1, 4, 1 do
- TV=row
- FMP=0
- if Slt[row]==0 then
- FMP=row
- end
- for column=row+4, row+12, 4 do
- if Slt[column]~=0 then
- if Slt[column]==Slt[TV] then
- score=score+Slt[TV]*2
- Slt[TV]=Slt[TV]*2
- Slt[column]=0
- movemade=true
- TV=column
- else
- TV=column
- end
- end
- if Slt[column]~=0 then
- if FMP~=0 then
- Slt[FMP]=Slt[column]
- Slt[column]=0
- TV=FMP
- FMP=FMP+4
- movemade=true
- end
- else
- if FMP==0 then
- FMP=column
- end
- end
- end
- end
- if kc==0 or kc==1 then
- kc=kc+1
- else
- kc=0
- end
- if(movemade==true) then
- newBlock()
- checkLose()
- end
- os.execute("clear")
- drawUI()
- end
- function down()
- fixdd()
- os.execute("clear")
- movemade=false
- for row=13, 16, 1 do
- TV=row
- FMP=0
- if Slt[row]==0 then
- FMP=row
- end
- for column=row-4, row-12, -4 do
- if Slt[column]~=0 then
- if Slt[column]==Slt[TV] then
- score=score+Slt[TV]*2
- Slt[TV]=Slt[TV]*2
- Slt[column]=0
- movemade=true
- TV=column
- else
- TV=column
- end
- end
- if Slt[column]~=0 then
- if FMP~=0 then
- Slt[FMP]=Slt[column]
- Slt[column]=0
- TV=FMP
- FMP=FMP-4
- movemade=true
- end
- else
- if FMP==0 then
- FMP=column
- end
- end
- end
- end
- if kc==2 or kc==3 then
- kc=kc+1
- else
- kc=0
- end
- if(movemade==true) then
- newBlock()
- checkLose()
- end
- drawUI()
- end
- function newBlock()
- local amntavbl=0
- local AvblTbl={}
- for cuslt=1, 16, 1 do
- if Slt[cuslt]==0 then
- amntavbl=amntavbl+1
- AvblTbl[amntavbl]=cuslt
- end
- end
- if amntavbl>0 then
- Slt[AvblTbl[math.random(amntavbl)]]=math.random(2)*2
- else
- checkLose()
- end
- end
- function a()
- if kc==9 then
- kc=kc+1
- print("!!!!!!1!!!")
- else
- kc=0
- print("(debug command):1: attempt to call global 'a' (a nil value)")
- end
- end
- function drawUI(type)
- Recurses=Recurses+1
- if type=="first" then
- os.execute("clear")
- print("After 180 recursions, the game will give you a code.")
- print("After this, the game is unsafe, as it is known to crash at 200 recursions.")
- print("Mistyped Commands count toward this number, but are not able to be shown.")
- end
- print("Recursions: "..Recurses)
- print("Controls: Type 'left()', 'right()', 'up()', 'down()', or 'newGame()'")
- print("Enter 'saveGame()' to get a code, and enter 'loadSave(\"[code]\")' to load the code")
- print("Score: "..score)
- print("╔════════╤════════╤════════╤════════╗")
- print("║╔══════╗│╔══════╗│╔══════╗│╔══════╗║")
- print("║"..Nums[Slt[1]].."│"..Nums[Slt[2]].."│"..Nums[Slt[3]].."│"..Nums[Slt[4]].."║")
- print("║╚══════╝│╚══════╝│╚══════╝│╚══════╝║")
- print("╟────────┼────────┼────────┼────────╢")
- print("║╔══════╗│╔══════╗│╔══════╗│╔══════╗║")
- print("║"..Nums[Slt[5]].."│"..Nums[Slt[6]].."│"..Nums[Slt[7]].."│"..Nums[Slt[8]].."║")
- print("║╚══════╝│╚══════╝│╚══════╝│╚══════╝║")
- print("╟────────┼────────┼────────┼────────╢")
- print("║╔══════╗│╔══════╗│╔══════╗│╔══════╗║")
- print("║"..Nums[Slt[9]].."│"..Nums[Slt[10]].."│"..Nums[Slt[11]].."│"..Nums[Slt[12]].."║")
- print("║╚══════╝│╚══════╝│╚══════╝│╚══════╝║")
- print("╟────────┼────────┼────────┼────────╢")
- print("║╔══════╗│╔══════╗│╔══════╗│╔══════╗║")
- print("║"..Nums[Slt[13]].."│"..Nums[Slt[14]].."│"..Nums[Slt[15]].."│"..Nums[Slt[16]].."║")
- print("║╚══════╝│╚══════╝│╚══════╝│╚══════╝║")
- print("╚════════╧════════╧════════╧════════╝")
- if type=="WOWOWOWOW" then
- print("incredible \n", "konami \n", "haha wow \n good job")
- end
- winstate=false
- for ch2048=1, 16, 1 do
- if (Slt[ch2048]>=2048) then
- winstate=true
- end
- end
- if type=="load" then
- print("Save code loaded!")
- end
- if Recurses >= 180 then
- saveGame()
- print("Here is the save code. Copy it down.")
- end
- if failed==true then
- print("you lose!")
- end
- if winstate==true then
- print("You Won!!")
- end
- debug.debug()
- end
- function newGame()
- print("Are you sure?")
- print("yes()/no()")
- allowyes=true
- end
- function saveGame()
- print(","..Slt[1]..","..Slt[2]..","..Slt[3]..","..Slt[4]..","..Slt[5]..","..Slt[6]..","..Slt[7]..","..Slt[8]..","..Slt[9]..","..Slt[10]..","..Slt[11]..","..Slt[12]..","..Slt[13]..","..Slt[14]..","..Slt[15]..","..Slt[16]..","..score)
- end
- function yes()
- if allowyes==true then
- Slt={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}
- newBlock()
- newBlock()
- score=0
- failed=false
- drawUI("first")
- end
- end
- function no()
- print("cancelled")
- allowyes=false
- end
- function b()
- if kc==8 then
- kc=kc+1
- print("??!!!??")
- else
- kc=0
- print("(debug command):1: attempt to call global 'b' (a nil value)")
- end
- end
- file=io.open("save.txt")
- function loadSave(code)
- if type(code)~="nil" then
- Slt={}
- Prev=code
- for get=1,17,1 do
- Slt[get]=tonumber(string.match(Prev, "%d+"))
- Prev=string.sub(Prev, string.len(string.match(Prev, "%d+"))+2)
- end
- score=Slt[17]
- os.execute("clear")
- drawUI("load")
- else
- print("no save to load")
- end
- end
- newGame()
- yes()
Advertisement
Add Comment
Please, Sign In to add comment