1: 2: logic 3: { 4: int boardWidth {20} 5: int boardHeight {20} 6: 7: int TOP_SPACE {10} 8: 9: int TILE_EMPTY {0} 10: int TILE_ROBOT {2} 11: int TILE_MIN_EXPLOSION {4} 12: 13: int playerX {8} 14: int playerY {12} 15: 16: array board { 17: 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 18: 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 19: 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 20: 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 21: 0, 0, 0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 22: 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0, 0, 0, 23: 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 24: 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0, 0, 0, 0, 0, 25: 0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 26: 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 27: 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 28: 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 29: 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 30: 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 31: 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 32: 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0, 33: 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 34: 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 35: 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 36: 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 37: } 38: 39: int numRobots {8} 40: array robotX { 2, 4, 19, 15, 13, 8, 9, 17 } 41: array robotY { 8, 4, 4, 5, 7, 2, 16, 15 } 42: 43: array xMoves { -1, 0, 1, -1, 1, -1, 0, 1 } 44: array yMoves { 1, 1, 1, 0, 0, -1, -1, -1 } 45: 46: // Generate a random board 47: when 48: { 49: (1 == 1) 50: } 51: allow 52: { 53: for y (0 .. (boardHeight - 1)) 54: { 55: for x (0 .. (boardWidth - 1)) 56: { 57: board[x + (y * boardWidth)] = TILE_EMPTY; 58: } 59: } 60: for i (0..(numRobots-1)) 61: { 62: robotX[i] = random[boardWidth]; 63: robotY[i] = random[boardHeight]; 64: board[robotX[i] + (robotY[i] * boardWidth)] = board[robotX[i] + (robotY[i] * boardWidth)] + TILE_ROBOT; 65: } 66: playerX = random[boardWidth]; 67: playerY = random[boardHeight]; 68: } 69: label 70: { 71: "Reset" 72: } 73: 74: for p (0..7) 75: { 76: // Move player. 77: when 78: { 79: ((playerX + xMoves[p]) >= 0) 80: and ((playerX + xMoves[p]) < boardWidth) 81: and ((playerY + yMoves[p]) >= 0) 82: and ((playerY + yMoves[p]) < boardHeight) 83: } 84: allow 85: { 86: playerX = (playerX + xMoves[p]); 87: playerY = (playerY + yMoves[p]); 88: } 89: label 90: { 91: "Player dx=" xMoves[p] " dy=" yMoves[p] "." 92: } 93: } 94: 95: for r (0 .. (numRobots - 1)) 96: { 97: // Move each robot toward the player, killing him if he's hit. 98: when 99: { 100: (playerX > robotX[r]) 101: and (playerY > robotY[r]) 102: and (board[robotX[r] + (robotY[r] * boardWidth)] == TILE_ROBOT) 103: } 104: allow 105: { 106: board[robotX[r] + (robotY[r] * boardWidth)] = TILE_EMPTY; 107: board[robotX[r] + 1 + ((robotY[r] + 1) * boardWidth)] = board[robotX[r] + 1 + ((robotY[r] + 1) * boardWidth)] + TILE_ROBOT; 108: robotX[r] = robotX[r] + 1; 109: robotY[r] = robotY[r] + 1; 110: } 111: label 112: { 113: "Robot move" 114: } 115: when 116: { 117: (playerX > robotX[r]) 118: and (playerY == robotY[r]) 119: and (board[robotX[r] + (robotY[r] * boardWidth)] == TILE_ROBOT) 120: } 121: allow 122: { 123: board[robotX[r] + (robotY[r] * boardWidth)] = TILE_EMPTY; 124: board[robotX[r] + 1 + (robotY[r] * boardWidth)] = board[robotX[r] + 1 + (robotY[r] * boardWidth)] + TILE_ROBOT; 125: robotX[r] = robotX[r] + 1; 126: } 127: label 128: { 129: "Robot move" 130: } 131: when 132: { 133: (playerX > robotX[r]) 134: and (playerY < robotY[r]) 135: and (board[robotX[r] + (robotY[r] * boardWidth)] == TILE_ROBOT) 136: } 137: allow 138: { 139: board[robotX[r] + (robotY[r] * boardWidth)] = TILE_EMPTY; 140: board[robotX[r] + 1 + ((robotY[r] - 1) * boardWidth)] = board[robotX[r] + 1 + ((robotY[r] - 1) * boardWidth)] + TILE_ROBOT; 141: robotX[r] = robotX[r] + 1; 142: robotY[r] = robotY[r] - 1; 143: } 144: label 145: { 146: "Robot move" 147: } 148: when 149: 150: { 151: (playerX == robotX[r]) 152: and (playerY > robotY[r]) 153: and (board[robotX[r] + (robotY[r] * boardWidth)] == TILE_ROBOT) 154: } 155: allow 156: { 157: board[robotX[r] + (robotY[r] * boardWidth)] = TILE_EMPTY; 158: board[robotX[r] + ((robotY[r] + 1) * boardWidth)] = board[robotX[r] + ((robotY[r] + 1) * boardWidth)] + TILE_ROBOT; 159: robotY[r] = robotY[r] + 1; 160: } 161: label 162: { 163: "Robot move" 164: } 165: when 166: { 167: (playerX == robotX[r]) 168: and (playerY < robotY[r]) 169: and (board[robotX[r] + (robotY[r] * boardWidth)] == TILE_ROBOT) 170: 171: } 172: allow 173: { 174: board[robotX[r] + (robotY[r] * boardWidth)] = TILE_EMPTY; 175: board[robotX[r] + ((robotY[r] - 1) * boardWidth)] = board[robotX[r] + ((robotY[r] - 1) * boardWidth)] + TILE_ROBOT; 176: robotY[r] = robotY[r] - 1; 177: } 178: label 179: { 180: "Robot move" 181: } 182: when 183: { 184: (playerX < robotX[r]) 185: and (playerY > robotY[r]) 186: and (board[robotX[r] + (robotY[r] * boardWidth)] == TILE_ROBOT) 187: } 188: allow 189: { 190: board[robotX[r] + (robotY[r] * boardWidth)] = TILE_EMPTY; 191: board[robotX[r] - 1 + ((robotY[r] + 1) * boardWidth)] = board[robotX[r] - 1 + ((robotY[r] + 1) * boardWidth)] + TILE_ROBOT; 192: robotX[r] = robotX[r] - 1; 193: robotY[r] = robotY[r] + 1; 194: } 195: label 196: { 197: "Robot move" 198: } 199: when 200: { 201: (playerX < robotX[r]) 202: and (playerY == robotY[r]) 203: and (board[robotX[r] + (robotY[r] * boardWidth)] == TILE_ROBOT) 204: } 205: allow 206: { 207: board[robotX[r] + (robotY[r] * boardWidth)] = TILE_EMPTY; 208: board[robotX[r] - 1 + (robotY[r] * boardWidth)] = board[robotX[r] - 1 + (robotY[r] * boardWidth)] + TILE_ROBOT; 209: robotX[r] = robotX[r] - 1; 210: } 211: label 212: { 213: "Robot move" 214: } 215: when 216: { 217: (playerX < robotX[r]) 218: and (playerY < robotY[r]) 219: and (board[robotX[r] + (robotY[r] * boardWidth)] == TILE_ROBOT) 220: } 221: allow 222: { 223: board[robotX[r] + (robotY[r] * boardWidth)] = TILE_EMPTY; 224: board[robotX[r] - 1 + ((robotY[r] - 1) * boardWidth)] = board[robotX[r] - 1 + ((robotY[r] - 1) * boardWidth)] + TILE_ROBOT; 225: robotX[r] = robotX[r] - 1; 226: robotY[r] = robotY[r] - 1; 227: } 228: label 229: { 230: "Robot move" 231: } 232: } 233: } 234: 235: display 236: { 237: stringtable items 238: { 239: " ", "", "♗", "^", "✴", "✴", "✷", "✷", "✸", "✸", "✸", "✸", "✹", "✹", "✹", "✹", "✹", "✹", "✹" 240: } 241: 242: box 243: { 244: content { "Robots!" } 245: } 246: newline 247: sprite 248: { 249: position { absolute; left: 0em; top: (TOP_SPACE) em } 250: border { 1px solid black } 251: height { 20em } 252: width { 20em } 253: } 254: for r (0 .. (numRobots-1)) 255: { 256: sprite 257: { 258: position { absolute; left: (robotX[r]) em; top: (robotY[r] + TOP_SPACE) em } 259: width { 1em } 260: height { 1em } 261: 262: content { items[board[robotX[r] + (robotY[r] * boardWidth)]] } 263: } 264: } 265: box 266: { 267: position { absolute; left: (playerX) em; top: (playerY + TOP_SPACE) em } 268: width { 1em } 269: height { 1em } 270: content { "☺" } 271: if (board[playerX + (playerY * boardWidth)] == TILE_EMPTY) 272: { 273: bind_action{ "Robot move" } 274: } 275: if (board[playerX + (playerY * boardWidth)] != TILE_EMPTY) 276: { 277: content { "☹" } 278: } 279: } 280: newline 281: box 282: { 283: if (board[playerX + (playerY * boardWidth)] == TILE_EMPTY) 284: { 285: bind_action { "Player dx=-1 dy=-1." } 286: while_active { 287: position { absolute; left: (playerX - 1) em; top: (playerY + TOP_SPACE - 1) em } 288: width { 1em } 289: height { 1em } 290: if (board[playerX - 1 + ((playerY - 1) * boardWidth)] == TILE_EMPTY) { 291: content { "↖" } 292: } 293: } 294: bind_action { "Robot move" } 295: } 296: } 297: box 298: { 299: if (board[playerX + (playerY * boardWidth)] == TILE_EMPTY) 300: { 301: bind_action { "Player dx=0 dy=-1." } 302: while_active { 303: position { absolute; left: (playerX) em; top: (playerY + TOP_SPACE - 1) em } 304: width { 1em } 305: height { 1em } 306: if (board[playerX + ((playerY - 1) * boardWidth)] == TILE_EMPTY) { 307: content { "↑" } 308: } 309: } 310: bind_action { "Robot move" } 311: } 312: } 313: box 314: { 315: if (board[playerX + (playerY * boardWidth)] == TILE_EMPTY) 316: { 317: bind_action { "Player dx=1 dy=-1." } 318: while_active { 319: position { absolute; left: (playerX + 1) em; top: (playerY + TOP_SPACE - 1) em } 320: width { 1em } 321: height { 1em } 322: if (board[playerX + 1 + ((playerY - 1) * boardWidth)] == TILE_EMPTY) { 323: content { "↗" } 324: } 325: } 326: bind_action { "Robot move" } 327: } 328: } 329: newline 330: box 331: { 332: if (board[playerX + (playerY * boardWidth)] == TILE_EMPTY) 333: { 334: bind_action { "Player dx=-1 dy=0." } 335: while_active { 336: position { absolute; left: (playerX - 1) em; top: (playerY + TOP_SPACE) em } 337: width { 1em } 338: height { 1em } 339: if (board[playerX - 1 + (playerY * boardWidth)] == TILE_EMPTY) { 340: content { "←" } 341: } 342: } 343: bind_action { "Robot move" } 344: } 345: } 346: box 347: { 348: if (board[playerX + (playerY * boardWidth)] == TILE_EMPTY) 349: { 350: bind_action { "Player dx=1 dy=0." } 351: while_active { 352: position { absolute; left: (playerX + 1) em; top: (playerY + TOP_SPACE) em } 353: width { 1em } 354: height { 1em } 355: if (board[playerX + 1 + (playerY * boardWidth)] == TILE_EMPTY) { 356: content { "→" } 357: } 358: } 359: bind_action { "Robot move" } 360: } 361: } 362: newline 363: box 364: { 365: if (board[playerX + (playerY * boardWidth)] == TILE_EMPTY) 366: { 367: bind_action { "Player dx=-1 dy=1." } 368: while_active { 369: position { absolute; left: (playerX - 1) em; top: (playerY + TOP_SPACE + 1) em } 370: width { 1em } 371: height { 1em } 372: if (board[playerX - 1 + ((playerY + 1) * boardWidth)] == TILE_EMPTY) { 373: content { "↙" } 374: } 375: } 376: bind_action { "Robot move" } 377: } 378: } 379: box 380: { 381: if (board[playerX + (playerY * boardWidth)] == TILE_EMPTY) 382: { 383: bind_action { "Player dx=0 dy=1." } 384: while_active { 385: position { absolute; left: (playerX) em; top: (playerY + TOP_SPACE + 1) em } 386: width { 1em } 387: height { 1em } 388: if (board[playerX + ((playerY + 1) * boardWidth)] == TILE_EMPTY) { 389: content { "↓" } 390: } 391: } 392: bind_action { "Robot move" } 393: } 394: } 395: box 396: { 397: if (board[playerX + (playerY * boardWidth)] == TILE_EMPTY) 398: { 399: bind_action { "Player dx=1 dy=1." } 400: while_active { 401: position { absolute; left: (playerX + 1) em; top: (playerY + TOP_SPACE + 1) em } 402: width { 1em } 403: height { 1em } 404: if (board[playerX + 1 + ((playerY + 1) * boardWidth)] == TILE_EMPTY) { 405: content { "↘" } 406: } 407: } 408: bind_action { "Robot move" } 409: } 410: } 411: box 412: { 413: if (board[playerX + (playerY * boardWidth)] == TILE_EMPTY) 414: { 415: content { "Make your escape!" } 416: } 417: 418: if (board[playerX + (playerY * boardWidth)] != TILE_EMPTY) 419: { 420: content { "Game over!" } 421: } 422: } 423: newline 424: box 425: { 426: border { 1px solid black } 427: content { "Regenerate" } 428: bind_action { "Reset" } 429: } 430: }