scottycool64

simply, 2048

Dec 18th, 2022
40
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.58 KB | None | 0 0
  1. 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██║"
  2. 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█║"
  3. Nums[131072]="║131072║";Nums[0]="║ ║"
  4. score=0
  5. Slt={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}
  6. failed=false
  7. Recurses=0
  8. kc=0
  9. math.randomseed(math.random(os.time()))
  10. function fixdd()
  11. for fff=1,16,1 do
  12. if (Slt[fff]==2047) then
  13. Slt[fff]=2048
  14. end
  15. if (Slt[fff]==16385) then
  16. Slt[fff]=16384
  17. end
  18. end
  19. end
  20. function checkLose()
  21. local losecheck = 0
  22. local failupdown=true
  23. local failleftright=true
  24. for checklinetop=1, 4, 1 do
  25. losecheck = checklinetop
  26. for checklinesub=checklinetop+4, checklinetop+12, 4 do
  27. if Slt[checklinesub]==0 then
  28. failupdown=false
  29. end
  30. if Slt[checklinesub]==Slt[losecheck] then
  31. failupdown=false
  32. else
  33. losecheck=checklinesub
  34. end
  35. end
  36. end
  37. for checklineside=1, 13, 4 do
  38. losecheck = checklineside
  39. for checklinesude=checklineside+1, checklineside+3, 1 do
  40. if Slt[checklinesude]==0 then
  41. failleftright=false
  42. end
  43. if Slt[checklinesude]==Slt[losecheck] then
  44. failleftright=false
  45. else
  46. losecheck=checklinesub
  47. end
  48. end
  49. end
  50. if (failupdown==false) or (failleftright==false) then
  51. failed=false
  52. else
  53. failed=true
  54. end
  55. end
  56. function left()
  57. fixdd()
  58. os.execute("clear")
  59. if kc==4 or kc==6 then
  60. if kc==6 then
  61. print("!??")
  62. else
  63. print("!?")
  64. end
  65. kc=kc+1
  66. else
  67. kc=0
  68. end
  69. movemade=false
  70. for row=1, 13, 4 do
  71. TV=row
  72. FMP=0
  73. if Slt[row]==0 then
  74. FMP=row
  75. end
  76. for column=row+1, row+3, 1 do
  77. if Slt[column]~=0 then
  78. if Slt[column]==Slt[TV] then
  79. score=score+Slt[TV]*2
  80. Slt[TV]=Slt[TV]*2
  81. Slt[column]=0
  82. movemade=true
  83. TV=column
  84. else
  85. TV=column
  86. end
  87. end
  88.  
  89. if Slt[column]~=0 then
  90. if FMP~=0 then
  91. Slt[FMP]=Slt[column]
  92. Slt[column]=0
  93. TV=FMP
  94. FMP=FMP+1
  95. movemade=true
  96. end
  97. else
  98. if FMP==0 then
  99. FMP=column
  100. end
  101. end
  102. end
  103. end
  104. if(movemade==true) then
  105. newBlock()
  106. checkLose()
  107. end
  108. drawUI()
  109. end
  110. function right()
  111. fixdd()
  112. os.execute("clear")
  113. if kc==5 or kc==7 then
  114. if kc==7 then
  115. print("!??")
  116. else
  117. print("!?")
  118. end
  119. kc=kc+1
  120. else
  121. kc=0
  122. end
  123. movemade=false
  124. for row=4, 16, 4 do
  125. TV=row
  126. FMP=0
  127. if Slt[row]==0 then
  128. FMP=row
  129. end
  130. for column=row-1, row-3, -1 do
  131. if Slt[column]~=0 then
  132. if Slt[column]==Slt[TV] then
  133. score=score+Slt[TV]*2
  134. Slt[TV]=Slt[TV]*2
  135. Slt[column]=0
  136. movemade=true
  137. TV=column
  138. else
  139. TV=column
  140. end
  141. end
  142.  
  143. if Slt[column]~=0 then
  144. if FMP~=0 then
  145. Slt[FMP]=Slt[column]
  146. Slt[column]=0
  147. TV=FMP
  148. FMP=FMP-1
  149. movemade=true
  150. end
  151. else
  152. if FMP==0 then
  153. FMP=column
  154. end
  155. end
  156. end
  157. end
  158. if(movemade==true) then
  159. newBlock()
  160. checkLose()
  161. end
  162. drawUI()
  163. end
  164. function start()
  165. if kc==10 then
  166. os.execute("clear")
  167. Slt={2047,2047,2047,2047,4096,4096,4096,4096,8192,8192,8192,8192,16385,16385,16385,16385}
  168. score=1203012314000000000000000000000000
  169. drawUI("WOWOWOWOW")
  170. else
  171. print("(debug command):1: attempt to call global 'start' (a nil value)")
  172. end
  173. end
  174. function up()
  175. fixdd()
  176. os.execute("clear")
  177. movemade=false
  178. for row=1, 4, 1 do
  179. TV=row
  180. FMP=0
  181. if Slt[row]==0 then
  182. FMP=row
  183. end
  184. for column=row+4, row+12, 4 do
  185. if Slt[column]~=0 then
  186. if Slt[column]==Slt[TV] then
  187. score=score+Slt[TV]*2
  188. Slt[TV]=Slt[TV]*2
  189. Slt[column]=0
  190. movemade=true
  191. TV=column
  192. else
  193. TV=column
  194. end
  195. end
  196.  
  197. if Slt[column]~=0 then
  198. if FMP~=0 then
  199. Slt[FMP]=Slt[column]
  200. Slt[column]=0
  201. TV=FMP
  202. FMP=FMP+4
  203. movemade=true
  204. end
  205. else
  206. if FMP==0 then
  207. FMP=column
  208. end
  209. end
  210. end
  211. end
  212. if kc==0 or kc==1 then
  213. kc=kc+1
  214. else
  215. kc=0
  216. end
  217. if(movemade==true) then
  218. newBlock()
  219. checkLose()
  220. end
  221. os.execute("clear")
  222. drawUI()
  223. end
  224. function down()
  225. fixdd()
  226. os.execute("clear")
  227. movemade=false
  228. for row=13, 16, 1 do
  229. TV=row
  230. FMP=0
  231. if Slt[row]==0 then
  232. FMP=row
  233. end
  234. for column=row-4, row-12, -4 do
  235. if Slt[column]~=0 then
  236. if Slt[column]==Slt[TV] then
  237. score=score+Slt[TV]*2
  238. Slt[TV]=Slt[TV]*2
  239. Slt[column]=0
  240. movemade=true
  241. TV=column
  242. else
  243. TV=column
  244. end
  245. end
  246. if Slt[column]~=0 then
  247. if FMP~=0 then
  248. Slt[FMP]=Slt[column]
  249. Slt[column]=0
  250. TV=FMP
  251. FMP=FMP-4
  252. movemade=true
  253. end
  254. else
  255. if FMP==0 then
  256. FMP=column
  257. end
  258. end
  259. end
  260. end
  261. if kc==2 or kc==3 then
  262. kc=kc+1
  263. else
  264. kc=0
  265. end
  266. if(movemade==true) then
  267. newBlock()
  268. checkLose()
  269. end
  270. drawUI()
  271. end
  272. function newBlock()
  273. local amntavbl=0
  274. local AvblTbl={}
  275. for cuslt=1, 16, 1 do
  276. if Slt[cuslt]==0 then
  277. amntavbl=amntavbl+1
  278. AvblTbl[amntavbl]=cuslt
  279. end
  280. end
  281. if amntavbl>0 then
  282. Slt[AvblTbl[math.random(amntavbl)]]=math.random(2)*2
  283. else
  284. checkLose()
  285. end
  286. end
  287. function a()
  288. if kc==9 then
  289. kc=kc+1
  290. print("!!!!!!1!!!")
  291. else
  292. kc=0
  293. print("(debug command):1: attempt to call global 'a' (a nil value)")
  294. end
  295. end
  296. function drawUI(type)
  297. Recurses=Recurses+1
  298. if type=="first" then
  299. os.execute("clear")
  300. print("After 180 recursions, the game will give you a code.")
  301. print("After this, the game is unsafe, as it is known to crash at 200 recursions.")
  302. print("Mistyped Commands count toward this number, but are not able to be shown.")
  303. end
  304. print("Recursions: "..Recurses)
  305. print("Controls: Type 'left()', 'right()', 'up()', 'down()', or 'newGame()'")
  306. print("Enter 'saveGame()' to get a code, and enter 'loadSave(\"[code]\")' to load the code")
  307. print("Score: "..score)
  308. print("╔════════╤════════╤════════╤════════╗")
  309. print("║╔══════╗│╔══════╗│╔══════╗│╔══════╗║")
  310. print("║"..Nums[Slt[1]].."│"..Nums[Slt[2]].."│"..Nums[Slt[3]].."│"..Nums[Slt[4]].."║")
  311. print("║╚══════╝│╚══════╝│╚══════╝│╚══════╝║")
  312. print("╟────────┼────────┼────────┼────────╢")
  313. print("║╔══════╗│╔══════╗│╔══════╗│╔══════╗║")
  314. print("║"..Nums[Slt[5]].."│"..Nums[Slt[6]].."│"..Nums[Slt[7]].."│"..Nums[Slt[8]].."║")
  315. print("║╚══════╝│╚══════╝│╚══════╝│╚══════╝║")
  316. print("╟────────┼────────┼────────┼────────╢")
  317. print("║╔══════╗│╔══════╗│╔══════╗│╔══════╗║")
  318. print("║"..Nums[Slt[9]].."│"..Nums[Slt[10]].."│"..Nums[Slt[11]].."│"..Nums[Slt[12]].."║")
  319. print("║╚══════╝│╚══════╝│╚══════╝│╚══════╝║")
  320. print("╟────────┼────────┼────────┼────────╢")
  321. print("║╔══════╗│╔══════╗│╔══════╗│╔══════╗║")
  322. print("║"..Nums[Slt[13]].."│"..Nums[Slt[14]].."│"..Nums[Slt[15]].."│"..Nums[Slt[16]].."║")
  323. print("║╚══════╝│╚══════╝│╚══════╝│╚══════╝║")
  324. print("╚════════╧════════╧════════╧════════╝")
  325. if type=="WOWOWOWOW" then
  326. print("incredible \n", "konami \n", "haha wow \n good job")
  327. end
  328. winstate=false
  329. for ch2048=1, 16, 1 do
  330. if (Slt[ch2048]>=2048) then
  331. winstate=true
  332. end
  333. end
  334. if type=="load" then
  335. print("Save code loaded!")
  336. end
  337. if Recurses >= 180 then
  338. saveGame()
  339. print("Here is the save code. Copy it down.")
  340. end
  341. if failed==true then
  342. print("you lose!")
  343. end
  344. if winstate==true then
  345. print("You Won!!")
  346. end
  347. debug.debug()
  348. end
  349. function newGame()
  350. print("Are you sure?")
  351. print("yes()/no()")
  352. allowyes=true
  353. end
  354. function saveGame()
  355. 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)
  356. end
  357. function yes()
  358. if allowyes==true then
  359. Slt={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}
  360. newBlock()
  361. newBlock()
  362. score=0
  363. failed=false
  364. drawUI("first")
  365. end
  366. end
  367. function no()
  368. print("cancelled")
  369. allowyes=false
  370. end
  371. function b()
  372. if kc==8 then
  373. kc=kc+1
  374. print("??!!!??")
  375. else
  376. kc=0
  377. print("(debug command):1: attempt to call global 'b' (a nil value)")
  378. end
  379. end
  380. file=io.open("save.txt")
  381. function loadSave(code)
  382. if type(code)~="nil" then
  383. Slt={}
  384. Prev=code
  385. for get=1,17,1 do
  386. Slt[get]=tonumber(string.match(Prev, "%d+"))
  387. Prev=string.sub(Prev, string.len(string.match(Prev, "%d+"))+2)
  388. end
  389. score=Slt[17]
  390. os.execute("clear")
  391. drawUI("load")
  392. else
  393. print("no save to load")
  394. end
  395. end
  396.  
  397. newGame()
  398. yes()
  399.  
Advertisement
Add Comment
Please, Sign In to add comment