Mad House

Book: Creepy Computer Games
Author: Brendon Kavanagh, Colin Reynolds, Val Robinson, Alan Ramsey, Keith Campbell, Chris Oxlade
Translator: Marcus Medina


Story

You’re trapped in a weird house where everything moves — even the walls! If the doorways would just line up for a second, you might escape…

You’ve found a console that seems to control the movements in the house. Keys X and C change the direction of the top doorway. Keys N and M do the same for the bottom doorway. There’s no way to control the center one — it moves on its own, and time is running out!

You can hear the phantom footsteps echoing closer and closer. The counter at the top left of the screen shows how close they are. If you can’t escape before they reach you… …you’ll become just another ghost wandering the Mad House!


Pseudocode

CREATE two arrays:
- P(): position of each doorway
- S(): direction of each doorway
MAKE a row of stars as the top of the room
SET footsteps counter = 240
SET directions for doorways at start
SET random starting positions
REPEAT until escape or footsteps reach 0
CLEAR screen
DISPLAY room and doorways
PRINT footsteps counter (top left)
CHECK if all three doorways align → YOU’RE FREE
READ keyboard input:
* changes top doorway
X or C → reverse top doorway direction
N or M → reverse bottom doorway direction
EVERY 25 steps → move center doorway
UPDATE doorway positions based on direction
REDRAW the screen
DECREASE footsteps counter
END LOOP
IF counter = 0 → TOO LATE, footsteps caught you!

Flowchart

flowchart TD
    A[Start Game] --> B["Initialize arrays P() and S()"]
    B --> C[Set doorway positions randomly]
    C --> D[Display room and counter]
    D --> E[Check if all three doorways align]
    E -->|Yes| F["Print: YOU ARE FREE!!"]
    E -->|No| G[Check for keypress]
    G --> H["Change doorway direction (X,C,N,M)"]
    H --> I[Move doorways based on direction]
    I --> J[Decrease counter]
    J --> K[Check if counter = 0]
    K -->|Yes| L["Print: TOO LATE!"]
    K -->|No| D
    F --> M[End Game]
    L --> M

Code

Pages

Mad House, sida 1 — Usborne Creepy Computer Games
Mad House, sida 2 — Usborne Creepy Computer Games


ZX-81 BASIC
10 DIM P(3)
20 DIM S(3)
30 CLS
40 PRINT "MAD HOUSE"
50 LET L$=""
60 LET W=31
70 FOR I=1 TO W
80 LET L$=L$+"*"
90 NEXT I
100 LET CT=240
110 LET S(1)=1
120 LET S(3)=-1
130 FOR I=1 TO 3
140 LET P(I)=INT(RND*(W-4)+1)
150 NEXT I
160 CLS
170 FOR I=5 TO 15 STEP 5
180 PRINT AT I,0;L$
190 PRINT AT I,P(I)/5;"> <"
200 NEXT I
210 PRINT AT 0,0;CT;" "
220 IF CT<0 THEN GOTO 450
230 IF P(1)=P(2) AND P(2)=P(3) THEN GOTO 390
240 LET Z$=INKEY$
250 IF Z$="" THEN GOTO 300
260 IF Z$="X" THEN LET S(1)=-1
270 IF Z$="C" THEN LET S(1)=1
280 IF Z$="N" THEN LET S(3)=-1
290 IF Z$="M" THEN LET S(3)=1
300 IF CT/25=INT(CT/25) THEN LET P(2)=P(2)+INT(RND(1)*20)-10
310 LET CT=CT-1
320 LET P(1)=P(1)+S(1)
330 LET P(3)=P(3)+S(3)
340 FOR I=1 TO 3
350 IF P(I)<1 THEN LET P(I)=1
360 IF P(I)>(W-4) THEN LET P(I)=W-4
370 NEXT I
380 GOTO 170
390 LET P(1)=P(1)+1
400 FOR I=1 TO 15
410 PRINT AT I, L; "M"
420 NEXT I
430 PRINT "YOU ARE FREE!!"
440 STOP
450 PRINT "TOO LATE! THE FOOTSTEPS HAVE STOPPED."
460 PRINT "ARGHHHHH!!!!"
470 STOP

C#
using System;
using System.Threading;
class MadHouse
{
static void Main()
{
const int width = 31;
int[] P = new int[3];
int[] S = { 1, 0, -1 };
Random rnd = new Random();
int counter = 240;
for (int i = 0; i < 3; i++)
P[i] = rnd.Next(1, width - 4);
while (counter > 0)
{
Console.Clear();
Console.WriteLine($"Footsteps: {counter}");
for (int i = 0; i < 3; i++)
{
string line = new string('*', width);
line = line.Remove(P[i], 3).Insert(P[i], "> <");
Console.WriteLine(line);
Console.WriteLine();
}
if (P[0] == P[1] && P[1] == P[2])
{
Console.WriteLine("\nYOU ARE FREE!!");
return;
}
if (Console.KeyAvailable)
{
var key = Console.ReadKey(true).Key;
if (key == ConsoleKey.X) S[0] = -1;
if (key == ConsoleKey.C) S[0] = 1;
if (key == ConsoleKey.N) S[2] = -1;
if (key == ConsoleKey.M) S[2] = 1;
}
if (counter % 25 == 0)
P[1] += rnd.Next(-10, 11);
for (int i = 0; i < 3; i++)
{
P[i] += S[i];
if (P[i] < 1) P[i] = 1;
if (P[i] > width - 4) P[i] = width - 4;
}
Thread.Sleep(50);
counter--;
}
Console.WriteLine("\nTOO LATE! The footsteps have stopped...");
Console.WriteLine("ARGHHHHHH!!!!");
}
}

Python
import random
import os
import time
import msvcrt
def mad_house():
width = 31
positions = [random.randint(1, width - 4) for _ in range(3)]
directions = [1, 0, -1]
counter = 240
while counter > 0:
os.system("cls" if os.name == "nt" else "clear")
print(f"Footsteps: {counter}\n")
for p in positions:
line = list("*" * width)
line[p:p+3] = [">", " ", "<"]
print("".join(line))
print()
if positions[0] == positions[1] == positions[2]:
print("\nYOU ARE FREE!!")
return
if msvcrt.kbhit():
key = msvcrt.getwch().upper()
if key == "X": directions[0] = -1
if key == "C": directions[0] = 1
if key == "N": directions[2] = -1
if key == "M": directions[2] = 1
if counter % 25 == 0:
positions[1] += random.randint(-10, 10)
for i in range(3):
positions[i] += directions[i]
positions[i] = max(1, min(width - 4, positions[i]))
counter -= 1
time.sleep(0.05)
print("\nTOO LATE! The footsteps have stopped.")
print("ARGHHHHHH!!!!")
if __name__ == "__main__":
mad_house()

Java
import java.util.Random;
import java.util.Scanner;
public class MadHouse {
public static void main(String[] args) {
final int width = 31;
int[] p = new int[3];
int[] s = {1, 0, -1};
Random rnd = new Random();
Scanner scanner = new Scanner(System.in);
int counter = 240;
for (int i = 0; i < 3; i++)
p[i] = 1 + rnd.nextInt(width - 4);
while (counter > 0) {
System.out.println("Footsteps: " + counter + "\n");
for (int pos : p) {
StringBuilder line = new StringBuilder("*".repeat(width));
line.replace(pos, pos + 3, "> <");
System.out.println(line);
System.out.println();
}
if (p[0] == p[1] && p[1] == p[2]) {
System.out.println("\nYOU ARE FREE!!");
return;
}
System.out.print("Press X/C (top) or N/M (bottom), or Enter to skip: ");
if (!scanner.hasNextLine()) return;
String key = scanner.nextLine().trim().toUpperCase();
if (key.equals("X")) s[0] = -1;
else if (key.equals("C")) s[0] = 1;
else if (key.equals("N")) s[2] = -1;
else if (key.equals("M")) s[2] = 1;
if (counter % 25 == 0)
p[1] += rnd.nextInt(21) - 10;
for (int i = 0; i < 3; i++) {
p[i] += s[i];
if (p[i] < 1) p[i] = 1;
if (p[i] > width - 4) p[i] = width - 4;
}
counter--;
}
System.out.println("\nTOO LATE! The footsteps have stopped.");
System.out.println("ARGHHHHHH!!!!");
}
}

Go
package main
import (
"bufio"
"fmt"
"math/rand"
"os"
"strings"
"time"
)
func main() {
const width = 31
rand.Seed(time.Now().UnixNano())
reader := bufio.NewReader(os.Stdin)
p := make([]int, 3)
s := []int{1, 0, -1}
for i := range p {
p[i] = 1 + rand.Intn(width-4)
}
counter := 240
for counter > 0 {
fmt.Printf("Footsteps: %d\n\n", counter)
for _, pos := range p {
line := []byte(strings.Repeat("*", width))
copy(line[pos:pos+3], "> <")
fmt.Println(string(line))
fmt.Println()
}
if p[0] == p[1] && p[1] == p[2] {
fmt.Println("\nYOU ARE FREE!!")
return
}
fmt.Print("Press X/C (top) or N/M (bottom), or Enter to skip: ")
line, err := reader.ReadString('\n')
if err != nil {
return
}
key := strings.ToUpper(strings.TrimSpace(line))
switch key {
case "X":
s[0] = -1
case "C":
s[0] = 1
case "N":
s[2] = -1
case "M":
s[2] = 1
}
if counter%25 == 0 {
p[1] += rand.Intn(21) - 10
}
for i := range p {
p[i] += s[i]
if p[i] < 1 {
p[i] = 1
}
if p[i] > width-4 {
p[i] = width - 4
}
}
counter--
}
fmt.Println("\nTOO LATE! The footsteps have stopped.")
fmt.Println("ARGHHHHHH!!!!")
}

C++
#include <iostream>
#include <string>
#include <cstdlib>
#include <ctime>
#include <algorithm>
int main() {
const int width = 31;
srand(time(0));
int p[3];
int s[3] = {1, 0, -1};
for (int i = 0; i < 3; i++)
p[i] = 1 + rand() % (width - 4);
int counter = 240;
while (counter > 0) {
std::cout << "Footsteps: " << counter << "\n" << std::endl;
for (int i = 0; i < 3; i++) {
std::string line(width, '*');
line.replace(p[i], 3, "> <");
std::cout << line << std::endl << std::endl;
}
if (p[0] == p[1] && p[1] == p[2]) {
std::cout << "\nYOU ARE FREE!!" << std::endl;
return 0;
}
std::cout << "Press X/C (top) or N/M (bottom), or Enter to skip: ";
std::string key;
if (!std::getline(std::cin, key)) return 0;
std::transform(key.begin(), key.end(), key.begin(), ::toupper);
if (key == "X") s[0] = -1;
else if (key == "C") s[0] = 1;
else if (key == "N") s[2] = -1;
else if (key == "M") s[2] = 1;
if (counter % 25 == 0)
p[1] += (rand() % 21) - 10;
for (int i = 0; i < 3; i++) {
p[i] += s[i];
if (p[i] < 1) p[i] = 1;
if (p[i] > width - 4) p[i] = width - 4;
}
counter--;
}
std::cout << "\nTOO LATE! The footsteps have stopped." << std::endl;
std::cout << "ARGHHHHHH!!!!" << std::endl;
return 0;
}

Explanation

You control a bizarre console in a shifting house. Each doorway slides left and right, and you must align all three before the phantom footsteps reach you. Top doorways respond to X and C, bottom ones to N and M. When the doors line up, you dash through to freedom — but wait too long, and it’s all over…


Challenges

  1. Sound Effects – Add haunting footsteps and a scream when time runs out.
  2. Speed Mode – Make the footsteps quicken the longer you play.
  3. Mirror Madness – Randomly reverse doorway controls for extra chaos.
  4. Escape Counter – Track how many escapes you manage before failing.
  5. Phantom Door – Add a fourth, random-moving doorway for experts only.

These programs are adaptations of the original Usborne Computer Guides published in the 1980s. The books are free to download for personal or educational use from Usborne’s Computer and Coding Books. Programs and adaptations may not be used for commercial purposes.

Return to Creepy Computer Games.