Исправить код лабиринта - QBasic

Узнай цену своей работы

Формулировка задачи:

Решение задачи: «Исправить код лабиринта»

textual
Листинг программы
SCREEN 13
RANDOMIZE TIMER
LINE (5, 5)-(225, 145), 1, B
A = INT(RND(1) * 2)
IF A = 1 THEN LINE (25, 5)-(25, 25), 1
A = INT(RND(1) * 2)
IF A = 1 THEN LINE (45, 5)-(45, 25), 1
A = INT(RND(1) * 2)
IF A = 1 THEN LINE (65, 5)-(65, 25), 1
A = INT(RND(1) * 2)
IF A = 1 THEN LINE (85, 5)-(85, 25), 1
A = INT(RND(1) * 2)
IF A = 1 THEN LINE (105, 5)-(105, 25), 1
A = INT(RND(1) * 2)
IF A = 1 THEN LINE (125, 5)-(125, 25), 1
A = INT(RND(1) * 2)
IF A = 1 THEN LINE (145, 5)-(145, 25), 1
A = INT(RND(1) * 2)
IF A = 1 THEN LINE (165, 5)-(165, 25), 1
A = INT(RND(1) * 2)
IF A = 1 THEN LINE (185, 5)-(185, 25), 1
A = INT(RND(1) * 2)
IF A = 1 THEN LINE (205, 5)-(205, 25), 1
A = INT(RND(1) * 2)
IF A = 1 THEN LINE (225, 5)-(225, 25), 1
A = INT(RND(1) * 2)
IF A = 1 THEN LINE (5, 25)-(25, 25), 1
A = INT(RND(1) * 2)
IF A = 1 THEN LINE (25, 25)-(45, 25), 1
A = INT(RND(1) * 2)
IF A = 1 THEN LINE (45, 25)-(65, 25), 1
A = INT(RND(1) * 2)
IF A = 1 THEN LINE (65, 25)-(85, 25), 1
A = INT(RND(1) * 2)
IF A = 1 THEN LINE (85, 25)-(105, 25), 1
A = INT(RND(1) * 2)
IF A = 1 THEN LINE (105, 25)-(125, 25), 1
A = INT(RND(1) * 2)
IF A = 1 THEN LINE (125, 25)-(145, 25), 1
A = INT(RND(1) * 2)
IF A = 1 THEN LINE (145, 25)-(165, 25), 1
A = INT(RND(1) * 2)
IF A = 1 THEN LINE (165, 25)-(185, 25), 1
A = INT(RND(1) * 2)
IF A = 1 THEN LINE (185, 25)-(205, 25), 1
A = INT(RND(1) * 2)
IF A = 1 THEN LINE (205, 25)-(225, 25), 1
A = INT(RND(1) * 2)
IF A = 1 THEN LINE (25, 25)-(25, 45), 1
A = INT(RND(1) * 2)
IF A = 1 THEN LINE (45, 25)-(45, 45), 1
A = INT(RND(1) * 2)
IF A = 1 THEN LINE (65, 25)-(65, 45), 1
A = INT(RND(1) * 2)
IF A = 1 THEN LINE (85, 25)-(85, 45), 1
A = INT(RND(1) * 2)
IF A = 1 THEN LINE (105, 25)-(105, 45), 1
A = INT(RND(1) * 2)
IF A = 1 THEN LINE (125, 25)-(125, 45), 1
A = INT(RND(1) * 2)
IF A = 1 THEN LINE (145, 25)-(145, 45), 1
A = INT(RND(1) * 2)
IF A = 1 THEN LINE (165, 25)-(165, 45), 1
A = INT(RND(1) * 2)
IF A = 1 THEN LINE (185, 25)-(185, 45), 1
A = INT(RND(1) * 2)
IF A = 1 THEN LINE (205, 25)-(205, 45), 1
A = INT(RND(1) * 2)
IF A = 1 THEN LINE (5, 45)-(25, 45), 1
A = INT(RND(1) * 2)
IF A = 1 THEN LINE (25, 45)-(45, 45), 1
A = INT(RND(1) * 2)
IF A = 1 THEN LINE (45, 45)-(65, 45), 1
A = INT(RND(1) * 2)
IF A = 1 THEN LINE (65, 45)-(85, 45), 1
A = INT(RND(1) * 2)
IF A = 1 THEN LINE (85, 45)-(105, 45), 1
A = INT(RND(1) * 2)
IF A = 1 THEN LINE (105, 45)-(125, 45), 1
A = INT(RND(1) * 2)
IF A = 1 THEN LINE (125, 45)-(145, 45), 1
A = INT(RND(1) * 2)
IF A = 1 THEN LINE (145, 45)-(165, 45), 1
A = INT(RND(1) * 2)
IF A = 1 THEN LINE (165, 45)-(185, 45), 1
A = INT(RND(1) * 2)
IF A = 1 THEN LINE (185, 45)-(205, 45), 1
A = INT(RND(1) * 2)
IF A = 1 THEN LINE (205, 45)-(225, 45), 1
A = INT(RND(1) * 2)
IF A = 1 THEN LINE (25, 45)-(25, 65), 1
A = INT(RND(1) * 2)
IF A = 1 THEN LINE (45, 45)-(45, 65), 1
A = INT(RND(1) * 2)
IF A = 1 THEN LINE (65, 45)-(65, 65), 1
A = INT(RND(1) * 2)
IF A = 1 THEN LINE (85, 45)-(85, 65), 1
A = INT(RND(1) * 2)
IF A = 1 THEN LINE (105, 45)-(105, 65), 1
A = INT(RND(1) * 2)
IF A = 1 THEN LINE (125, 45)-(125, 65), 1
A = INT(RND(1) * 2)
IF A = 1 THEN LINE (145, 45)-(145, 65), 1
A = INT(RND(1) * 2)
IF A = 1 THEN LINE (165, 45)-(165, 65), 1
A = INT(RND(1) * 2)
IF A = 1 THEN LINE (185, 45)-(185, 65), 1
A = INT(RND(1) * 2)
IF A = 1 THEN LINE (205, 45)-(205, 65), 1
A = INT(RND(1) * 2)
IF A = 1 THEN LINE (5, 65)-(25, 65), 1
A = INT(RND(1) * 2)
IF A = 1 THEN LINE (25, 65)-(45, 65), 1
A = INT(RND(1) * 2)
IF A = 1 THEN LINE (45, 65)-(65, 65), 1
A = INT(RND(1) * 2)
IF A = 1 THEN LINE (65, 65)-(85, 65), 1
A = INT(RND(1) * 2)
IF A = 1 THEN LINE (85, 65)-(105, 65), 1
A = INT(RND(1) * 2)
IF A = 1 THEN LINE (105, 65)-(125, 65), 1
A = INT(RND(1) * 2)
IF A = 1 THEN LINE (125, 65)-(145, 65), 1
A = INT(RND(1) * 2)
IF A = 1 THEN LINE (145, 65)-(165, 65), 1
A = INT(RND(1) * 2)
IF A = 1 THEN LINE (165, 65)-(185, 65), 1
A = INT(RND(1) * 2)
IF A = 1 THEN LINE (185, 65)-(205, 65), 1
A = INT(RND(1) * 2)
IF A = 1 THEN LINE (205, 65)-(225, 65), 1
A = INT(RND(1) * 2)
IF A = 1 THEN LINE (25, 65)-(25, 85), 1
A = INT(RND(1) * 2)
IF A = 1 THEN LINE (45, 65)-(45, 85), 1
A = INT(RND(1) * 2)
IF A = 1 THEN LINE (65, 65)-(65, 85), 1
A = INT(RND(1) * 2)
IF A = 1 THEN LINE (85, 65)-(85, 85), 1
A = INT(RND(1) * 2)
IF A = 1 THEN LINE (105, 65)-(105, 85), 1
A = INT(RND(1) * 2)
IF A = 1 THEN LINE (125, 65)-(125, 85), 1
A = INT(RND(1) * 2)
IF A = 1 THEN LINE (145, 65)-(145, 85), 1
A = INT(RND(1) * 2)
IF A = 1 THEN LINE (165, 65)-(165, 85), 1
A = INT(RND(1) * 2)
IF A = 1 THEN LINE (185, 65)-(185, 85), 1
A = INT(RND(1) * 2)
IF A = 1 THEN LINE (205, 65)-(205, 85), 1
A = INT(RND(1) * 2)
IF A = 1 THEN LINE (5, 85)-(25, 85), 1
A = INT(RND(1) * 2)
IF A = 1 THEN LINE (25, 85)-(45, 85), 1
A = INT(RND(1) * 2)
IF A = 1 THEN LINE (45, 85)-(65, 85), 1
A = INT(RND(1) * 2)
IF A = 1 THEN LINE (65, 85)-(85, 85), 1
A = INT(RND(1) * 2)
IF A = 1 THEN LINE (85, 85)-(105, 85), 1
A = INT(RND(1) * 2)
IF A = 1 THEN LINE (105, 85)-(125, 85), 1
A = INT(RND(1) * 2)
IF A = 1 THEN LINE (125, 85)-(145, 85), 1
A = INT(RND(1) * 2)
IF A = 1 THEN LINE (145, 85)-(165, 85), 1
A = INT(RND(1) * 2)
IF A = 1 THEN LINE (165, 85)-(185, 85), 1
A = INT(RND(1) * 2)
IF A = 1 THEN LINE (185, 85)-(205, 85), 1
A = INT(RND(1) * 2)
IF A = 1 THEN LINE (205, 85)-(225, 85), 1
A = INT(RND(1) * 2)
IF A = 1 THEN LINE (25, 85)-(25, 105), 1
A = INT(RND(1) * 2)
IF A = 1 THEN LINE (45, 85)-(45, 105), 1
A = INT(RND(1) * 2)
IF A = 1 THEN LINE (65, 85)-(65, 105), 1
A = INT(RND(1) * 2)
IF A = 1 THEN LINE (85, 85)-(85, 105), 1
A = INT(RND(1) * 2)
IF A = 1 THEN LINE (105, 85)-(105, 105), 1
A = INT(RND(1) * 2)
IF A = 1 THEN LINE (125, 85)-(125, 105), 1
A = INT(RND(1) * 2)
IF A = 1 THEN LINE (145, 85)-(145, 105), 1
A = INT(RND(1) * 2)
IF A = 1 THEN LINE (165, 85)-(165, 105), 1
A = INT(RND(1) * 2)
IF A = 1 THEN LINE (185, 85)-(185, 105), 1
A = INT(RND(1) * 2)
IF A = 1 THEN LINE (205, 85)-(205, 105), 1
A = INT(RND(1) * 2)
IF A = 1 THEN LINE (5, 105)-(25, 105), 1
A = INT(RND(1) * 2)
IF A = 1 THEN LINE (25, 105)-(45, 105), 1
A = INT(RND(1) * 2)
IF A = 1 THEN LINE (45, 105)-(65, 105), 1
A = INT(RND(1) * 2)
IF A = 1 THEN LINE (65, 105)-(85, 105), 1
A = INT(RND(1) * 2)
IF A = 1 THEN LINE (85, 105)-(105, 105), 1
A = INT(RND(1) * 2)
IF A = 1 THEN LINE (105, 105)-(125, 105), 1
A = INT(RND(1) * 2)
IF A = 1 THEN LINE (125, 105)-(145, 105), 1
A = INT(RND(1) * 2)
IF A = 1 THEN LINE (145, 105)-(165, 105), 1
A = INT(RND(1) * 2)
IF A = 1 THEN LINE (165, 105)-(185, 105), 1
A = INT(RND(1) * 2)
IF A = 1 THEN LINE (185, 105)-(205, 105), 1
A = INT(RND(1) * 2)
IF A = 1 THEN LINE (205, 105)-(225, 105), 1
A = INT(RND(1) * 2)
IF A = 1 THEN LINE (25, 105)-(25, 125), 1
A = INT(RND(1) * 2)
IF A = 1 THEN LINE (45, 105)-(45, 125), 1
A = INT(RND(1) * 2)
IF A = 1 THEN LINE (65, 105)-(65, 125), 1
A = INT(RND(1) * 2)
IF A = 1 THEN LINE (85, 105)-(85, 125), 1
A = INT(RND(1) * 2)
IF A = 1 THEN LINE (105, 105)-(105, 125), 1
A = INT(RND(1) * 2)
IF A = 1 THEN LINE (125, 105)-(125, 125), 1
A = INT(RND(1) * 2)
IF A = 1 THEN LINE (145, 105)-(145, 125), 1
A = INT(RND(1) * 2)
IF A = 1 THEN LINE (165, 105)-(165, 125), 1
A = INT(RND(1) * 2)
IF A = 1 THEN LINE (185, 105)-(185, 125), 1
A = INT(RND(1) * 2)
IF A = 1 THEN LINE (205, 105)-(205, 125), 1
A = INT(RND(1) * 2)
IF A = 1 THEN LINE (5, 125)-(25, 125), 1
A = INT(RND(1) * 2)
IF A = 1 THEN LINE (25, 125)-(45, 125), 1
A = INT(RND(1) * 2)
IF A = 1 THEN LINE (45, 125)-(65, 125), 1
A = INT(RND(1) * 2)
IF A = 1 THEN LINE (65, 125)-(85, 125), 1
A = INT(RND(1) * 2)
IF A = 1 THEN LINE (85, 125)-(105, 125), 1
A = INT(RND(1) * 2)
IF A = 1 THEN LINE (105, 125)-(125, 125), 1
A = INT(RND(1) * 2)
IF A = 1 THEN LINE (125, 125)-(145, 125), 1
A = INT(RND(1) * 2)
IF A = 1 THEN LINE (145, 125)-(165, 125), 1
A = INT(RND(1) * 2)
IF A = 1 THEN LINE (165, 125)-(185, 125), 1
A = INT(RND(1) * 2)
IF A = 1 THEN LINE (185, 125)-(205, 125), 1
A = INT(RND(1) * 2)
IF A = 1 THEN LINE (205, 125)-(225, 125), 1
A = INT(RND(1) * 2)
IF A = 1 THEN LINE (25, 125)-(25, 145), 1
A = INT(RND(1) * 2)
IF A = 1 THEN LINE (45, 125)-(45, 145), 1
A = INT(RND(1) * 2)
IF A = 1 THEN LINE (65, 125)-(65, 145), 1
A = INT(RND(1) * 2)
IF A = 1 THEN LINE (85, 125)-(85, 145), 1
A = INT(RND(1) * 2)
IF A = 1 THEN LINE (105, 125)-(105, 145), 1
A = INT(RND(1) * 2)
IF A = 1 THEN LINE (125, 125)-(125, 145), 1
A = INT(RND(1) * 2)
IF A = 1 THEN LINE (145, 125)-(145, 145), 1
A = INT(RND(1) * 2)
IF A = 1 THEN LINE (165, 125)-(165, 145), 1
A = INT(RND(1) * 2)
IF A = 1 THEN LINE (185, 125)-(185, 145), 1
A = INT(RND(1) * 2)
IF A = 1 THEN LINE (205, 125)-(205, 145), 1

Объяснение кода листинга программы

Данный код на языке QBasic представляет собой лабиринт, в котором случайно генерируются стены. В начале каждой строки кода задается точка начала лабиринта (координаты (5, 5)), а затем с помощью функции RND() генерируется случайное число от 1 до 25, которое затем используется для определения следующей точки в лабиринте. В каждой строке кода после генерации случайного числа происходит проверка: если число равно 1, то с помощью функции LINE() рисуется линия от текущей точки до следующей точки в лабиринте. Цель игры - провести линию от начала лабиринта до его конца (точка с координатами (225, 225)). Для этого необходимо корректно пройти через все точки лабиринта и нарисовать линии между ними. Код написан таким образом, что он будет работать до тех пор, пока не будет прерван пользователем или не будет достигнут конец лабиринта.

ИИ поможет Вам:


  • решить любую задачу по программированию
  • объяснить код
  • расставить комментарии в коде
  • и т.д
Попробуйте бесплатно

Оцени полезность:

9   голосов , оценка 3.889 из 5