Death Valley
Book: Computer Spacegames
Author: Usborne Publishing
Translator: Marcus Medina
Story
In this game, you must steer your spaceship, the “Speed Dart,” through a treacherous narrow passage known as “Death Valley.” The player controls the ship by pressing Q to move left and P to move right. The width of the valley is determined at the start of the game. The goal is to make it through the valley without crashing into the walls.
Pseudocode
STARTPRINT "Death Valley"SET S = 0 // Number of steps takenSET M = 200 // Maximum allowed stepsPRINT "Width?"INPUT W // Get width of valleySET L = W / 2 // Left boundarySET Y = WSET R = W
WHILE S < M SET D = RANDOM(-1, 1) IF L + D < 0 OR L + D > 20 THEN CONTINUE SET L = L + D SET Y = Y - D SET R = R + D
PRINT SPACES L THEN PRINT "I" PRINT SPACES Y THEN PRINT "*" PRINT SPACES R THEN PRINT "I"
GET INPUT I IF I == "Q" THEN Y = Y - 1; R = R + 1 IF I == "P" THEN Y = Y + 1; R = R - 1
IF Y < 1 OR R < 1 THEN GOTO END_FAILURE
INCREMENT SEND_WHILE
END_SUCCESSPRINT "Well done! You made it through Death Valley."EXIT
END_FAILUREPRINT "You crashed into the wall and disintegrated."EXIT
ENDFlowchart
graph TD
A[Start] --> B[Print 'Death Valley']
B --> C[Set initial values S=0, M=200, W=input width]
C --> D[Calculate boundaries L, Y, R]
D --> E[While S < M]
E --> F[Random value D between -1 and 1]
F --> G{Check boundaries L+D, Y-D, R+D}
G -->|Valid| H[Adjust L, Y, R]
G -->|Invalid| F
H --> I[Draw valley and spaceship]
I --> J[Get user input]
J --> K{Input 'Q' or 'P'?}
K -->|Q| L[Move left]
K -->|P| M[Move right]
L --> N[Check for collision]
M --> N
N -->|Collision| O[End: You crashed]
N -->|No collision| P[Increment S]
P --> E
O --> Q[End game: Failure]
E --> R[End game: Success]
Code
Pages


ZX-81 BASIC
10 PRINT "DEATH VALLEY"20 LET S=030 LET M=20040 PRINT "WIDTH?"50 INPUT W60 LET L=INT(W/2)70 LET L=1080 LET Y=W90 LET R=W100 LET D=INT(RND*3-1)110 IF L+D<0 OR L+D>20 THEN GOTO 100120 LET L=L+D130 LET R=R+D140 LET Y=Y-D145 SCROLL150 LET N=L160 GOSUB 1000170 PRINT "I"180 LET N=Y190 GOSUB 1000200 PRINT "I"210 LET N=R220 GOSUB 1000230 PRINT "I"240 LET I$=INKEY$250 IF I$="Q" THEN GOTO 280260 IF I$="P" THEN GOTO 310270 LET Y=Y-1280 LET R=R+1290 LET Y=Y+1300 LET R=R-1310 IF Y<1 OR R<1 THEN GOTO 370320 LET S=S+1330 IF S<M THEN GOTO 100340 PRINT "WELL DONE-YOU MADE IT"350 PRINT "THROUGH DEATH VALLEY"360 STOP370 PRINT "YOU CRASHED INTO THE WALL"380 PRINT "AND DISINTEGRATED"390 STOP
1000 FOR N=1 TO N1010 PRINT " ";1020 NEXT I1030 RETURNC#
using System;
class Program{ static void Main() { Console.WriteLine("Death Valley"); int steps = 0; const int maxSteps = 200;
int width; do { Console.Write("Width? "); } while (!int.TryParse(Console.ReadLine(), out width) || width <= 0); int left = width / 2; int middle = width; int right = width;
Random random = new Random();
while (steps < maxSteps) { int change = random.Next(-1, 2); if (left + change < 0 || right + change > 20) continue;
left += change; middle -= change; right += change;
Console.WriteLine(new string(' ', left) + "I"); Console.WriteLine(new string(' ', middle) + "*"); Console.WriteLine(new string(' ', right) + "I");
ConsoleKeyInfo key = Console.ReadKey(true); if (key.Key == ConsoleKey.Q) { middle--; right++; } else if (key.Key == ConsoleKey.P) { middle++; right--; }
if (middle < 1 || right < 1) { Console.WriteLine("You crashed into the wall and disintegrated."); return; }
steps++; }
Console.WriteLine("Well done! You made it through Death Valley."); }}Python
import random
def main(): print("Death Valley") steps = 0 max_steps = 200
width = int(input("Width? ")) left = width // 2 middle = width right = width
while steps < max_steps: change = random.randint(-1, 1) if left + change < 0 or right + change > 20: continue
left += change middle -= change right += change
print(" " * left + "I") print(" " * middle + "*") print(" " * right + "I")
move = input("Move (Q/P): ").strip().upper() if move == "Q": middle -= 1 right += 1 elif move == "P": middle += 1 right -= 1
if middle < 1 or right < 1: print("You crashed into the wall and disintegrated.") return
steps += 1
print("Well done! You made it through Death Valley.")
if __name__ == "__main__": main()Java
import java.util.Scanner;import java.util.Random;
public class DeathValley { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); Random random = new Random();
System.out.println("Death Valley"); int steps = 0; final int maxSteps = 200;
System.out.print("Width? "); int width = scanner.nextInt(); int left = width / 2; int middle = width; int right = width;
while (steps < maxSteps) { int change = random.nextInt(3) - 1; if (left + change < 0 || right + change > 20) { continue; }
left += change; middle -= change; right += change;
System.out.println(" ".repeat(left) + "I"); System.out.println(" ".repeat(middle) + "*"); System.out.println(" ".repeat(right) + "I");
System.out.print("Move (Q/P): "); String move = scanner.next().toUpperCase(); if (move.equals("Q")) { middle--; right++; } else if (move.equals("P")) { middle++; right--; }
if (middle < 1 || right < 1) { System.out.println("You crashed into the wall and disintegrated."); scanner.close(); return; }
steps++; }
System.out.println("Well done! You made it through Death Valley."); scanner.close(); }}Go
package main
import ( "fmt" "math/rand" "time")
func main() { rand.Seed(time.Now().UnixNano()) fmt.Println("Death Valley") var steps int const maxSteps = 200
var width int fmt.Print("Width? ") fmt.Scan(&width)
left := width / 2 middle := width right := width
for steps < maxSteps { change := rand.Intn(3) - 1 if left+change < 0 || right+change > 20 { continue }
left += change middle -= change right += change
fmt.Printf("%sI\n", spaces(left)) fmt.Printf("%s*\n", spaces(middle)) fmt.Printf("%sI\n", spaces(right))
var move string fmt.Print("Move (Q/P): ") fmt.Scan(&move)
if move == "Q" { middle-- right++ } else if move == "P" { middle++ right-- }
if middle < 1 || right < 1 { fmt.Println("You crashed into the wall and disintegrated.") return }
steps++ }
fmt.Println("Well done! You made it through Death Valley.")}
func spaces(n int) string { return fmt.Sprintf("%*s", n, "")}C++
#include <iostream>#include <cstdlib>#include <ctime>#include <string>using namespace std;
string spaces(int n) { return string(n, ' ');}
int main() { srand(time(0)); cout << "Death Valley" << endl; int steps = 0; const int maxSteps = 200;
cout << "Width? "; int width; cin >> width;
int left = width / 2; int middle = width; int right = width;
while (steps < maxSteps) { int change = rand() % 3 - 1; if (left + change < 0 || right + change > 20) continue;
left += change; middle -= change; right += change;
cout << spaces(left) << "I" << endl; cout << spaces(middle) << "*" << endl; cout << spaces(right) << "I" << endl;
cout << "Move (Q/P): "; char move; cin >> move; move = toupper(move);
if (move == 'Q') { middle--; right++; } else if (move == 'P') { middle++; right--; }
if (middle < 1 || right < 1) { cout << "You crashed into the wall and disintegrated." << endl; return 0; }
steps++; }
cout << "Well done! You made it through Death Valley." << endl; return 0;}Explanation
This game challenges the player to navigate a spaceship through a narrow, shifting valley. Each turn, the valley’s boundaries shift slightly. The player uses the Q and P keys to move left and right, avoiding collisions with the walls. If the spaceship touches the wall, the game ends in failure. Successfully surviving all turns results in victory.
Challenges
- Increase Difficulty: Reduce the valley’s width dynamically as the game progresses.
- Add Obstacles: Introduce obstacles within the valley that the player must avoid.
- Variable Speeds: Make the valley’s scrolling speed increase over time.
Copyright
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 Computer Spacegames.