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, 5, 5, 5, 5, 5, 5, 5, 5, 85: 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 86: 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 87: 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 88: 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 89: 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 90: 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 91: 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5 92: } 93: const int maxboardwidth { 11 } 94: const int maxboardheight { 11 } 95: 96: array pieces 97: { 98: 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 99: } 100: const int maxpieces { 13 } 101: 102: const array nextboard { 0, 3, 4, 2, 1, 5, 6, 6 } 103: const array nextstate { 2, 2, 2, 2, 2, 4, 3, 2 } 104: local int selected { -1 } 105: local int scratch { 0 } 106: 107: int boardsize { 0 } 108: int boardwidth { 0 } 109: int numpieces { 0 } 110: array nextdirection { 0, -1, 1, 0, 0, 0, 0, 0 } 111: 112: int gamestate { 0 } 113: int direction { 0 } 114: int location { 0 } 115: 116: for i ( 0 .. (numpuzzles - 1) ) 117: { 118: when 119: { 120: gamestate == 0 121: } 122: allow 123: { 124: scratch = 0; 125: for j ( 0 .. (i-1) ) 126: { 127: scratch = scratch + 3 + puzzles[scratch] + puzzles[scratch+2]; 128: } 129: boardsize = puzzles[scratch]; 130: boardwidth = puzzles[scratch+1]; 131: numpieces = puzzles[scratch+2]; 132: scratch += 3; 133: for j ( 0 .. (numpieces-1) ) 134: { 135: pieces[j] = puzzles[scratch+j]; 136: } 137: scratch += numpieces; 138: location = boardwidth + 1; 139: for j ( 0 .. (boardsize-1) ) 140: { 141: board[j] = puzzles[scratch+j]; 142: if( board[j] & 8 ) 143: { 144: location = j; 145: } 146: } 147: nextdirection[3] = 0 - boardwidth; 148: nextdirection[4] = boardwidth; 149: direction = 0; 150: selected = -1; 151: gamestate = 1; 152: } 153: label { "puzzle " i } 154: } 155: 156: when 157: { 158: ( gamestate == 1 ) and ( (board[location]&7) != 0 ) 159: } 160: allow 161: { 162: selected = -1; 163: gamestate = 2; 164: direction = nextdirection[(board[location]&7)]; 165: } 166: label { "act" } 167: 168: when 169: { 170: ( gamestate == 5 ) and ( (board[location]&7) < 5 ) 171: } 172: allow 173: { 174: selected = -1; 175: gamestate = 2; 176: direction = nextdirection[(board[location]&7)]; 177: } 178: label { "playtest" } 179: 180: for i ( 0 .. (boardsize-1) ) 181: { 182: when 183: { 184: ( gamestate == 1 ) and (selected > -1) and ( (board[i]&7) == 0 ) 185: } 186: allow 187: { 188: board[i] += pieces[selected]; 189: pieces[selected] = 0; 190: selected = -1; 191: } 192: label 193: { 194: "place " i 195: } 196: 197: when 198: { 199: ( gamestate == 5 ) and (selected > -1) 200: } 201: allow 202: { 203: if( pieces[selected] == 8 ) 204: { 205: board[location] = board[location] & 7; 206: board[i] = (board[i] ^ 8); 207: location = i; 208: } 209: if( pieces[selected] != 8 ) 210: { 211: board[i] = pieces[selected] | ( board[i] & 8 ); 212: } 213: } 214: label 215: { 216: "place " i 217: } 218: } 219: 220: for i ( 0 .. (numpieces-1) ) 221: { 222: when 223: { 224: (( gamestate == 1 ) or ( gamestate == 5 )) 225: } 226: allow 227: { 228: scratch = -1; 229: if( selected != i ) 230: { 231: scratch = i; 232: } 233: selected = scratch; 234: } 235: label { "select " i } 236: } 237: 238: when 239: { 240: gamestate == 2 241: 242: } 243: allow 244: { 245: board[location] = nextboard[(board[location] & 7)]; 246: location += direction; 247: if( nextdirection[board[location]] != 0 ) 248: { 249: direction = nextdirection[board[location]]; 250: } 251: gamestate = nextstate[board[location]]; 252: board[location] += 8; 253: } 254: label { "act" } 255: 256: 257: when 258: { 259: gamestate == 0 260: } 261: allow 262: { 263: boardsize = maxboardwidth*maxboardheight; 264: boardwidth = maxboardwidth; 265: numpieces = 9; 266: for i ( 0..(boardsize-1) ) 267: { 268: board[i] = 5; 269: } 270: for i ( 0..(numpieces-1) ) 271: { 272: pieces[i] = i; 273: } 274: location = 0; 275: nextdirection[3] = 0 - boardwidth; 276: nextdirection[4] = boardwidth; 277: direction = 0; 278: selected = -1; 279: gamestate = 5; 280: } 281: label { "playtest mode" } 282: 283: when 284: { 285: gamestate > 2 286: } 287: allow 288: { 289: boardsize = 0; 290: boardwidth = 0; 291: numpieces = 0; 292: location = 0; 293: nextdirection[3] = 0; 294: nextdirection[4] = 0; 295: direction = 0; 296: selected = -1; 297: gamestate = 0; 298: } 299: label { "act" } 300: } 301: 302: 303: display 304: { 305: stringtable griditems 306: { 307: " ", "←", "→", "↑", "↓", "#", "X", "*", "player start location" 308: } 309: 310: stringtable statenames 311: { 312: "Please choose a puzzle", 313: "Place arrows - click here when done", 314: "Square is moving! Click here for next step", 315: "You've won! Click here to play again.", 316: "You're dead. Click here to play again." 317: "Playtest mode. Click here to quit." 318: } 319: 320: stringtable labels 321: { 322: "Test puzzle", 323: "AC's first", 324: "Left, Right, Left, Right", 325: "Loopdeloop", 326: "Failed Combination Lock", 327: "Back and Forth", 328: "Misdirection" 329: } 330: 331: for y ( 0 .. (maxboardheight-1) ) 332: { 333: for x ( 0 .. (maxboardwidth-1) ) 334: { 335: box 336: { 337: if( (x < boardwidth) and (y < (boardsize / boardwidth) ) ) 338: { 339: width { 2em } 340: height { 2em } 341: border { 1px solid black } 342: content { griditems[ board[x+boardwidth*y] & 7 ] } 343: if( board[x+boardwidth*y] & 8 ) 344: { 345: background { red } 346: } 347: bind_action { "place " x+boardwidth*y } 348: } 349: } 350: } 351: newline 352: } 353: 354: newline 355: 356: for j ( 0 .. (maxpieces-1) ) 357: { 358: box 359: { 360: if( ( ( gamestate == 1 ) or ( gamestate == 5) ) and ( j < numpieces ) ) 361: { 362: width { 2em } 363: height { 2em } 364: border { 1px solid black } 365: if( selected == j ) 366: { 367: background { yellow } 368: } 369: content { griditems[ pieces[j] ] } 370: bind_action { "select " j } 371: } 372: } 373: } 374: 375: newline 376: newline 377: 378: box 379: { 380: border { 1px solid black } 381: content { statenames[gamestate] } 382: bind_action { "act" } 383: } 384: box 385: { 386: bind_action { "playtest" } 387: while_active 388: { 389: border { 1px solid black } 390: content { "Playtest (NB. destructive right now - copy the link)" } 391: } 392: } 393: 394: 395: newline 396: 397: for j ( 0 .. (numpuzzles-1) ) 398: { 399: newline 400: box 401: { 402: if( gamestate == 0 ) 403: { 404: border { 1px solid black } 405: if( j < numlabels ) 406: { 407: content { "puzzle " j ": " labels[j] } 408: } 409: if( j >= numlabels ) 410: { 411: content { "puzzle " j } 412: } 413: bind_action { "puzzle " j } 414: } 415: } 416: } 417: newline 418: newline 419: box 420: { 421: if( gamestate == 0 ) 422: { 423: border { 1px solid black } 424: content { "Edit/playtest mode" } 425: bind_action { "playtest mode" } 426: } 427: } 428: 429: }