Russian Roulette
Priskribo de la ĉi-paĝa enhavo
Konvertado de Russian Roulette al pluri program-lingvoj.
Ĉi-tiu programo estas konvertita en 19 program-lingvojn.
Originalo
Origin of russian_rulette.bas:
Russian Roulette, by Tom Adametx, 1978.
Creative Computing's BASIC Games.
- https://www.atariarchives.org/basicgames/showpage.php?page=141
- http://vintage-basic.net/games.html
- http://vintage-basic.net/bcg/russianroulette.bas
- http://www.retroarchive.org/cpm/games/ccgames.zip
1 PRINT TAB(28);"RUSSIAN ROULETTE"
2 PRINT TAB(15);"CREATIVE COMPUTING MORRISTOWN, NEW JERSEY"
3 PRINT:PRINT:PRINT
5 PRINT "THIS IS A GAME OF >>>>>>>>>>RUSSIAN ROULETTE."
10 PRINT:PRINT "HERE IS A REVOLVER."
20 PRINT "TYPE '1' TO SPIN CHAMBER AND PULL TRIGGER."
22 PRINT "TYPE '2' TO GIVE UP."
23 PRINT "GO";
25 N=0
30 INPUT I
31 IF I<>2 THEN 35
32 PRINT " CHICKEN!!!!!"
33 GOTO 72
35 N=N+1
40 IF RND(1)>.833333 THEN 70
45 IF N>10 THEN 80
50 PRINT "- CLICK -"
60 PRINT: GOTO 30
70 PRINT " BANG!!!!! YOU'RE DEAD!"
71 PRINT "CONDOLENCES WILL BE SENT TO YOUR RELATIVES."
72 PRINT:PRINT:PRINT
75 PRINT "...NEXT VICTIM...":GOTO 20
80 PRINT "YOU WIN!!!!!"
85 PRINT "LET SOMEONE ELSE BLOW HIS BRAINS OUT."
90 GOTO 10
99 END
En Arturo
; Russian Roulette
; Original version in BASIC:
; By Tom Adametx, 1978.
; Creative Computing's BASIC Games.
; - https://www.atariarchives.org/basicgames/showpage.php?page=141
; - http://vintage-basic.net/games.html
; - http://vintage-basic.net/bcg/russianroulette.bas
; - http://www.retroarchive.org/cpm/games/ccgames.zip
; This version in Arturo:
; Copyright (c) 2023, Marcos Cruz (programandala.net)
; SPDX-License-Identifier: Fair
;
; Written in 2023-10.
;
; Last modified: 20251205T0050+0100.
pressEnterToStart: function [] [
input "Press Enter to start. "
]
printCredits: function [] [
clear
print "Russian Roulette\n"
print "Original version in BASIC:"
print " Creative Computing (Morristown, New Jersey, USA), ca. 1980.\n"
print "This version in Arturo:"
print " Copyright (c) 2023, Marcos Cruz (programandala.net)"
print " SPDX-License-Identifier: Fair\n"
pressEnterToStart
]
printInstructions: function [] [
clear
print "Here is a revolver."
print "Type 'f' to spin chamber and pull trigger."
print "Type 'g' to give up, and play again."
print "Type 'q' to quit.\n"
]
play: function [] [
while [ true ] [ ; game loop
printInstructions
times: 0
while [ true ] [ ; play loop
action: input "> "
case [ action ]
when? [ equal? "f" ] [ ; fire
if? greater? random 0 99 83 [
print "Bang! You're dead!"
print "Condolences will be sent to your relatives."
break
] else [
inc 'times
if? greater? times 10 [
print "You win!"
print "Let someone else blow his brains out."
break
] else [
print "Click."
]
]
]
when? [ equal? "g" ] [ ; give up
print "Chicken!"
break
]
when? [ equal? "q" ] [ ; quit
return
]
else [ ]
] ; play loop
pressEnterToStart
] ; game loop
]
printCredits
play
print "Bye!"
En C#
// Russian Roulette
// Original version in BASIC:
// By Tom Adametx, 1978.
// Creative Computing's BASIC Games.
// - https://www.atariarchives.org/basicgames/showpage.php?page=141
// - http://vintage-basic.net/games.html
// - http://vintage-basic.net/bcg/russianroulette.bas
// - http://www.retroarchive.org/cpm/games/ccgames.zip
// This version in C#:
// Copyright (c) 2024, Marcos Cruz (programandala.net)
// SPDX-License-Identifier: Fair
//
// Written on 2024-12-21.
//
// Last modified: 20251205T1547+0100.
using System;
class RussianRoulette
{
static void PressEnterToStart()
{
Console.Write("Press Enter to start. ");
Console.ReadKey();
}
static void PrintCredits()
{
Console.Clear();
Console.WriteLine("Russian Roulette\n");
Console.WriteLine("Original version in BASIC:");
Console.WriteLine(" Creative Computing (Morristown, New Jersey, USA), ca. 1980.\n");
Console.WriteLine("This version in C#:");
Console.WriteLine(" Copyright (c) 2024, Marcos Cruz (programandala.net)");
Console.WriteLine(" SPDX-License-Identifier: Fair\n");
PressEnterToStart();
}
static void PrintInstructions()
{
Console.Clear();
Console.WriteLine("Here is a revolver.");
Console.WriteLine("Type 'f' to spin chamber and pull trigger.");
Console.WriteLine("Type 'g' to give up, and play again.");
Console.WriteLine("Type 'q' to quit.\n");
}
static void Play()
{
Random rand = new Random();
int times;
while (true) { // game loop
PrintInstructions();
times = 0;
bool playing = true;
while (playing)
{
Console.Write("> ");
switch (Console.ReadLine())
{
case "f" : // fire
if (rand.Next(100) > 83)
{
Console.WriteLine("Bang! You're dead!");
Console.WriteLine("Condolences will be sent to your relatives.");
playing = false;
}
else
{
times += 1;
if (times > 10)
{
Console.WriteLine("You win!");
Console.WriteLine("Let someone else blow his brains out.");
playing = false;
}
else
{
Console.WriteLine("Click.");
}
}
break;
case "g" :; // give up
Console.WriteLine("Chicken!");
playing = false; // force exit
break;
case "q" :; // quit
return;
}
}; // play loop
PressEnterToStart();
}; // game loop
}
static void Main()
{
PrintCredits();
Play();
Console.WriteLine("Bye!");
}
}
En Chapel
// Russian Roulette
// Original version in BASIC:
// Creative Computing (Morristown, New Jersey, USA), ca. 1980.
// This version in Chapel:
// Copyright (c) 2025, Marcos Cruz (programandala.net)
// SPDX-License-Identifier: Fair
//
// Written on 2025-04-05.
//
// Last modified: 20250405T2249+0200.
// Terminal {{{1
// =============================================================================
import IO;
import Random;
const normalStyle = 0;
proc moveCursorHome() {
write("\x1B[H");
}
proc setStyle(style: int) {
writef("\x1B[%im", style);
}
proc resetAttributes() {
setStyle(normalStyle);
}
proc eraseScreen() {
write("\x1B[2J");
}
proc clearScreen() {
eraseScreen();
resetAttributes();
moveCursorHome();
}
// User input {{{1
// =============================================================================
proc acceptString(prompt: string): string {
write(prompt);
IO.stdout.flush();
return IO.readLine().strip();
}
proc pressEnterToStart() {
acceptString("Press Enter to start. ");
}
// Credits and instructions {{{1
// =============================================================================
proc printCredits() {
clearScreen();
writeln("Russian Roulette\n");
writeln("Original version in BASIC:");
writeln(" Creative Computing (Morristown, New Jersey, USA), ca. 1980.\n");
writeln("This version in Chapel:");
writeln(" Copyright (c) 2025, Marcos Cruz (programandala.net)");
writeln(" SPDX-License-Identifier: Fair\n");
pressEnterToStart();
}
proc printInstructions() {
clearScreen();
writeln("Here is a revolver.");
writeln("Type 'f' to spin chamber and pull trigger.");
writeln("Type 'g' to give up, and play again.");
writeln("Type 'q' to quit.\n");
}
// Main {{{1
// =============================================================================
proc play() {
var rsInt = new Random.randomStream(int);
while true { // game loop
printInstructions();
var times: int = 0;
label playLoop while true {
var command: string = acceptString("> ");
select command {
when "f" { // fire
if rsInt.next(0, 99) > 83 {
writeln("Bang! You're dead!");
writeln("Condolences will be sent to your relatives.");
break playLoop;
} else {
times += 1;
if times > 10 {
writeln("You win!");
writeln("Let someone else blow his brains out.");
break playLoop;
} else {
writeln("Click.");
}
}
}
when "g" { // give up
writeln("Chicken!");
break playLoop;
}
when "q" { // quit
return;
}
}
} // play loop
pressEnterToStart();
} // game loop
}
proc bye() {
writeln("Bye!");
}
proc main() {
printCredits();
play();
bye();
}
En Crystal
# Russian Roulette
# Original version in BASIC:
# Creative Computing (Morristown, New Jersey, USA), ca. 1980.
# This version in Crystal:
# Copyright (c) 2023, Marcos Cruz (programandala.net)
# SPDX-License-Identifier: Fair
#
# Written in 2023-09, 2023-10.
#
# Last modified: 20231104T0010+0100.
# Clears the terminal and moves the cursor to the top left position.
def clear_screen
print "\e[2J\e[H"
end
# Prompts the user to enter a command and returns it.
def command(prompt = "> ") : String
print prompt
gets.not_nil!
end
def press_enter_to_start
command("Press Enter to start. ")
end
def print_credits
clear_screen
puts "Russian Roulette\n"
puts "Original version in BASIC:"
puts " Creative Computing (Morristown, New Jersey, USA), ca. 1980.\n"
puts "This version in Crystal:"
puts " Copyright (c) 2023, Marcos Cruz (programandala.net)"
puts " SPDX-License-Identifier: Fair\n"
press_enter_to_start
end
def print_instructions
clear_screen
puts "Here is a revolver."
puts "Type 'f' to spin chamber and pull trigger."
puts "Type 'g' to give up, and play again."
puts "Type 'q' to quit.\n"
end
def play? : Bool
while true # game loop
print_instructions
times = 0
while true # play loop
case command
when "f" # fire
if rand(100) > 83
puts "Bang! You're dead!"
puts "Condolences will be sent to your relatives."
break
else
times += 1
if times > 10
puts "You win!"
puts "Let someone else blow his brains out."
break
else
puts "Click."
end
end
when "g" # give up
puts "Chicken!"
break
when "q" # quit
return false
end # case
end # play loop
press_enter_to_start
end # game loop
true # play again, do not quit
end
print_credits
while play?
end
puts "Bye!"
En D
// Russian Roulette
// Original version in BASIC:
// Creative Computing (Morristown, New Jersey, USA), ca. 1980.
// This version in D:
// Copyright (c) 2025, Marcos Cruz (programandala.net)
// SPDX-License-Identifier: Fair
//
// Written on 2025-03-22.
//
// Last modified: 20251220T0625+0100.
module russian_roulette;
// Terminal {{{1
// =============================================================================
enum normalStyle = 0;
void moveCursorHome()
{
import std.stdio : write;
write("\x1B[H");
}
void setStyle(int style)
{
import std.stdio : writef;
writef("\x1B[%dm", style);
}
void resetAttributes()
{
setStyle(normalStyle);
}
void eraseScreen()
{
import std.stdio : write;
write("\x1B[2J");
}
void clearScreen()
{
eraseScreen();
resetAttributes();
moveCursorHome();
}
// User input {{{1
// =============================================================================
string acceptString(string prompt)
{
import std.stdio : readln;
import std.stdio : write;
import std.string : strip;
write(prompt);
return strip(readln());
}
void pressEnterToStart()
{
acceptString("Press Enter to start. ");
}
// Credits and instructions {{{1
// =============================================================================
void printCredits()
{
import std.stdio : writeln;
clearScreen();
writeln("Russian Roulette\n");
writeln("Original version in BASIC:");
writeln(" Creative Computing (Morristown, New Jersey, USA), ca. 1980.\n");
writeln("This version in D:");
writeln(" Copyright (c) 2025, Marcos Cruz (programandala.net)");
writeln(" SPDX-License-Identifier: Fair\n");
pressEnterToStart();
}
void printInstructions()
{
import std.stdio : writeln;
clearScreen();
writeln("Here is a revolver.");
writeln("Type 'f' to spin chamber and pull trigger.");
writeln("Type 'g' to give up, and play again.");
writeln("Type 'q' to quit.\n");
}
// Main {{{1
// =============================================================================
void play()
{
import std.random : uniform;
import std.stdio : writeln;
int times = 0;
while (true) // game loop
{
printInstructions();
times = 0;
playLoop: while (true)
{
string command = acceptString("> ");
switch (command)
{
case "f": // fire
if (uniform(0, 100) > 83)
{
writeln("Bang! You're dead!");
writeln("Condolences will be sent to your relatives.");
break playLoop;
}
else
{
times += 1;
if (times > 10)
{
writeln("You win!");
writeln("Let someone else blow his brains out.");
break playLoop;
}
else
{
writeln("Click.");
}
}
break;
case "g": // give up
writeln("Chicken!");
break playLoop;
case "q": // quit
return;
default:
continue;
}
} // play loop
pressEnterToStart();
} // game loop
}
void bye()
{
import std.stdio : writeln;
writeln("Bye!");
}
void main()
{
printCredits();
play();
bye();
}
En FreeBASIC
/'
Russian Roulette
Original version in BASIC:
Creative Computing (Morristown, New Jersey, USA), ca. 1980.
This version in FreeBASIC:
Copyright (c) 2024, Marcos Cruz (programandala.net)
SPDX-License-Identifier: Fair
Written in 2024-11-20/21.
Last modified: 20250505T2350+0200.
'/
sub press_enter_to_start()
dim void as string
input "Press Enter to start. ", void
end sub
sub print_credits()
print !"Russian Roulette\n"
print "Original version in BASIC:"
print !" Creative Computing (Morristown, New Jersey, USA), ca. 1980\n"
print "This version in FreeBASIC:"
print " Copyright (c) 2024, Marcos Cruz (programandala.net)"
print !" SPDX-License-Identifier: Fair\n"
press_enter_to_start()
end sub
sub print_instructions()
print "Here is a revolver."
print "Type 'f' to spin chamber and pull trigger."
print "Type 'g' to give up, and play again."
print !"Type 'q' to quit.\n"
end sub
function play() as boolean
dim times as integer
dim order as string
do while TRUE ' game loop
cls
print_instructions()
times = 0
do while TRUE ' play loop
input "> ", order
if order = "f" then ' fire
if 100 * rnd > 83 then
print "Bang! You're dead!"
print "Condolences will be sent to your relatives."
exit do
else
times += 1
if times = 10 then
print "You win!"
print "Let someone else blow his brains out."
exit do
else
print "Click."
end if
end if
elseif order = "g" then ' give up
print "Chicken!"
exit do
elseif order = "q" then ' quit
return FALSE
end if
loop ' play
press_enter_to_start()
loop ' game
return TRUE ' play again, do not quit
end function
cls
print_credits()
do while play()
loop
print "Bye!"
' vim: filetype=freebasic
En Go
/*
Russian Roulette
Original version in BASIC:
Creative Computing (Morristown, New Jersey, USA), ca. 1980.
This version in Go:
Copyright (c) 2024, Marcos Cruz (programandala.net)
SPDX-License-Identifier: Fair
Written on 2024-12-29.
Last modified: 20250105T1153+0100.
*/
package main
import "fmt"
import "math/rand"
func clearScreen() {
fmt.Print("\x1B[0;0H\x1B[2J")
}
func input(prompt string) string {
fmt.Print(prompt)
var s = ""
fmt.Scanf("%s", &s)
return s
}
func pressEnterToStart() {
input("Press Enter to start. ")
}
func printCredits() {
clearScreen()
fmt.Println("Russian Roulette\n")
fmt.Println("Original version in BASIC:")
fmt.Println(" Creative Computing (Morristown, New Jersey, USA), ca. 1980.\n")
fmt.Println("This version in Go:")
fmt.Println(" Copyright (c) 2024, Marcos Cruz (programandala.net)")
fmt.Println(" SPDX-License-Identifier: Fair\n")
pressEnterToStart()
}
func printInstructions() {
clearScreen()
fmt.Println("Here is a revolver.")
fmt.Println("Type 'f' to spin chamber and pull trigger.")
fmt.Println("Type 'g' to give up, and play again.")
fmt.Println("Type 'q' to quit.\n")
}
func play() {
var times = 0
for { // game loop
printInstructions()
times = 0
playLoop:
for {
switch input("> ") {
case "f": // fire
if rand.Intn(100) > 83 {
fmt.Println("Bang! You're dead!")
fmt.Println("Condolences will be sent to your relatives.")
break playLoop
} else {
times += 1
if times > 10 {
fmt.Println("You win!")
fmt.Println("Let someone else blow his brains out.")
break playLoop
} else {
fmt.Println("Click.")
}
}
case "g": // give up
fmt.Println("Chicken!")
break playLoop
case "q": // quit
return
}
} // play loop
pressEnterToStart()
} // game loop
}
func main() {
printCredits()
play()
fmt.Println("Bye!")
}
En Hare
// Russian Roulette
//
// Original version in BASIC:
// Creative Computing (Morristown, New Jersey, USA), ca. 1980.
//
// This version in Hare:
// Copyright (c) 2025, Marcos Cruz (programandala.net)
// SPDX-License-Identifier: Fair
//
// Written on 2025-02-13, 2025-02-15.
//
// Last modified: 20260213T1645+0100.
// Modules {{{1
// =============================================================================
use bufio;
use fmt;
use math::random;
use os;
use strings;
use time;
// Terminal {{{1
// =============================================================================
def NORMAL_STYLE = 0;
fn move_cursor_home() void = {
fmt::print("\x1B[H")!;
};
fn set_style(style: int) void = {
fmt::printf("\x1B[{}m", style)!;
};
fn reset_attributes() void = {
set_style(NORMAL_STYLE);
};
fn erase_screen() void = {
fmt::print("\x1B[2J")!;
};
fn clear_screen() void = {
erase_screen();
reset_attributes();
move_cursor_home();
};
// User input {{{1
// =============================================================================
fn print_prompt(prompt: str = "") void = {
fmt::print(prompt)!;
bufio::flush(os::stdout)!;
};
fn accept_string(prompt: str = "") str = {
print_prompt(prompt);
const buffer = match (bufio::read_line(os::stdin)!) {
case let buffer: []u8 =>
yield buffer;
case =>
return "";
};
defer free(buffer);
return strings::dup(strings::fromutf8(buffer)!)!;
};
fn press_enter(prompt: str = "") void = {
free(accept_string(prompt));
};
fn press_enter_to_start() void = {
press_enter("Press Enter to start. ");
};
// Credits and instructions {{{1
// =============================================================================
fn print_credits() void = {
clear_screen();
fmt::println("Russian Roulette\n")!;
fmt::println("Original version in BASIC:")!;
fmt::println(" Creative Computing (Morristown, New Jersey, USA), ca. 1980.\n")!;
fmt::println("This version in Hare:")!;
fmt::println(" Copyright (c) 2025, Marcos Cruz (programandala.net)")!;
fmt::println(" SPDX-License-Identifier: Fair\n")!;
press_enter_to_start();
};
fn print_instructions() void = {
clear_screen();
fmt::println("Here is a revolver.")!;
fmt::println("Type 'f' to spin chamber and pull trigger.")!;
fmt::println("Type 'g' to give up, and play again.")!;
fmt::println("Type 'q' to quit.\n")!;
};
// Main {{{1
// =============================================================================
fn play() void = {
let times = 0;
for (true) { // game loop
print_instructions();
times = 0;
for :play_loop (true) {
let command = accept_string("> ");
defer free(command);
switch (command) {
case "f" => // fire
if (random::u32n(&rand, 100) > 83) {
fmt::println("Bang! You're dead!")!;
fmt::println("Condolences will be sent to your relatives.")!;
break :play_loop;
} else {
times += 1;
if (times > 10) {
fmt::println("You win!")!;
fmt::println("Let someone else blow his brains out.")!;
break :play_loop;
} else {
fmt::println("Click.")!;
};
};
case "g" => // give up
fmt::println("Chicken!")!;
break :play_loop;
case "q" => // quit
return;
case =>
continue;
};
}; // play loop
press_enter_to_start();
}; // game loop
};
let rand: random::random = 0;
fn randomize() void = {
rand = random::init(time::now(time::clock::MONOTONIC).sec: u64);
};
fn init() void = {
randomize();
};
fn bye() void = {
fmt::println("Bye!")!;
};
export fn main() void = {
init();
print_credits();
play();
bye();
};
En Janet
# Russion Roulette
# Original version in BASIC:
# By Tom Adametx, 1978.
# Creative Computing's BASIC Games.
# - https://www.atariarchives.org/basicgames/showpage.php?page=141
# - http://vintage-basic.net/games.html
# - http://vintage-basic.net/bcg/russianroulette.bas
# - http://www.retroarchive.org/cpm/games/ccgames.zip
# This version in Janet:
# Copyright (c) 2025, Marcos Cruz (programandala.net)
# SPDX-License-Identifier: Fair
#
# Written on 2025-12-24.
#
# Last modified 20251225T1331+0100.
(def normal-style 0)
(defn move-cursor-home []
(prin "\x1B[H"))
(defn set-style [style]
(prin (string/format "\x1B[%dm" style)))
(defn reset-attributes []
(set-style normal-style))
(defn erase-screen []
(prin "\x1B[2J"))
(defn clear-screen []
(erase-screen)
(reset-attributes)
(move-cursor-home))
(defn accept-string [&opt prompt-text]
(default prompt-text "> ")
(prin prompt-text)
(string/trim (getline)))
(defn press-enter-to-start []
(accept-string "Press Enter to start. "))
(defn print-credits []
(clear-screen)
(print "Russian Roulette\n")
(print "Original version in BASIC:")
(print " By Tom Adametx, 1978.\n")
(print " Creative Computing's BASIC Games.")
(print "This version in Janet:")
(print " Copyright (c) 2025, Marcos Cruz (programandala.net)")
(print " SPDX-License-Identifier: Fair\n")
(press-enter-to-start))
(defn print-instructions []
(clear-screen)
(print "Here is a revolver.")
(print "Type 'f' to spin chamber and pull trigger.")
(print "Type 'g' to give up, and play again.")
(print "Type 'q' to quit.\n"))
(defn deadly []
(> (math/random) 0.83))
(var times 0)
(defn last-shoot []
(if (deadly)
(do
(print "Bang! You're dead!")
(print "Condolences will be sent to your relatives.")
true)
(do
(+= times 1)
(def max-times 10)
(if (> times max-times)
(do
(print "You win!")
(print "Let someone else blow his brains out.")
true)
(do
(print "Click.")
false)))))
(defn play []
(set times 0)
(var more true)
(forever
(case (accept-string)
"f"
(do
(if (last-shoot)
(break)))
"g"
(do
(print "Chicken!")
(break))
"q"
(do
(set more false)
(break))))
more)
(defn play-game []
(forever
(print-instructions)
(if (not (play))
(break))
(press-enter-to-start)))
(defn main [& args]
(print-credits)
(play-game)
(print "Bye!"))
En Julia
# Russian Roulette
# Original version in BASIC:
# Creative Computing (Morristown, New Jersey, USA), ca. 1980.
# This version in Julia:
# Copyright (c) 2024, Marcos Cruz (programandala.net)
# SPDX-License-Identifier: Fair
#
# Written on 2024-06-28.
#
# Last modified: 20241029T1850+0100.
# Clear the terminal and move the cursor to the top left position.
function clear_screen()
print("\e[2J\e[H")
end
# Prompt the user to enter a command and return it.
function get_command(prompt = "> ")::String
print(prompt)
return readline()
end
function press_enter_to_start()
_ = get_command("Press Enter to start. ")
end
function print_credits()
clear_screen()
println("Russian Roulette\n")
println("Original version in BASIC:")
println(" Creative Computing (Morristown, New Jersey, USA), ca. 1980.\n")
println("This version in Julia:")
println(" Copyright (c) 2024, Marcos Cruz (programandala.net)")
println(" SPDX-License-Identifier: Fair\n")
press_enter_to_start()
end
function print_instructions()
clear_screen()
println("Here is a revolver.")
println("Type 'f' to spin chamber and pull trigger.")
println("Type 'g' to give up, and play again.")
println("Type 'q' to quit.\n")
end
function play()::Bool
while true # game loop
print_instructions()
times = 0
while true # play loop
command = get_command()
if command == "f" # fire
if Int(floor(100 * rand())) > 83
println("Bang! You're dead!")
println("Condolences will be sent to your relatives.")
break
else
times += 1
if times == 10
println("You win!")
println("Let someone else blow his brains out.")
break
else
println("Click.")
end
end
elseif command == "g" # give up
println("Chicken!")
break
elseif command == "q" # quit
return false
end # case
end # play loop
press_enter_to_start()
end # game loop
return true # play again, do not quit
end
print_credits
while play()
end
println("Bye!")
En Kotlin
/*
Russian Roulette
Original version in BASIC:
Creative Computing (Morristown, New Jersey, USA), ca. 1980.
This version in Kotlin:
Copyright (c) 2023, Marcos Cruz (programandala.net)
SPDX-License-Identifier: Fair
Written in 2023-10.
Last modified: 20250420T0003+0200.
*/
// Move the cursor to the top left position of the terminal.
fun home() {
print("\u001B[H")
}
// Clear the terminal and move the cursor to the top left position.
fun clear() {
print("\u001B[2J")
home()
}
// Prompt the user to enter a command and return it.
fun command(prompt: String = "> "): String {
print(prompt)
return readln()
}
fun pressEnterToStart() {
print("Press Enter to start. ")
readln()
}
fun printCredits() {
clear()
println("Russian Roulette\n")
println("Original version in BASIC:")
println(" Creative Computing (Morristown, New Jersey, USA), ca. 1980.\n")
println("This version in Kotlin:")
println(" Copyright (c) 2023, Marcos Cruz (programandala.net)")
println(" SPDX-License-Identifier: Fair\n")
pressEnterToStart()
}
fun printInstructions() {
clear()
println("Here is a revolver.")
println("Type 'f' to spin chamber and pull trigger.")
println("Type 'g' to give up, and play again.")
println("Type 'q' to quit.\n")
}
fun play() {
gameLoop@ while (true) {
printInstructions()
var times = 0
playLoop@ while (true) {
when (command()) {
"f" -> // fire
if ((0..100).random() > 83) {
println("Bang! You're dead!")
println("Condolences will be sent to your relatives.")
break@playLoop
} else {
times += 1
if (times > 10) {
println("You win!")
println("Let someone else blow his brains out.")
break@playLoop
} else {
println("Click.")
}
}
"g" -> // give up
{
println("Chicken!")
break@playLoop
}
"q" -> // quit
{
break@gameLoop
}
}
} // play loop
pressEnterToStart()
} // game loop
}
fun main() {
printCredits()
play()
println("Bye!")
}
En Nim
# Russian Roulette
#
# Original version in BASIC:
# Creative Computing (Morristown, New Jersey, USA), ca. 1980.
#
# This version in Nim:
# Copyright (c) 2023, Marcos Cruz (programandala.net)
# SPDX-License-Identifier: Fair
#
# Written in 2023-09-14/17.
#
# Last modified: 20250405T0304+0200.
import std/random
import std/terminal
proc cursorHome() =
setCursorPos 0, 0
proc clearScreen() =
eraseScreen()
cursorHome()
# Prompt the user to enter a command and return it.
proc command(prompt: string = "> "): char =
write stdout, prompt
return getch()
proc pressAnyKeyToStart() =
write stdout, "Press any key to start. "
discard getch()
proc printCredits =
echo "Russian Roulette\n"
echo "Original version in BASIC:"
echo " Creative Computing (Morristown, New Jersey, USA), ca. 1980.\n"
echo "This version in Nim:"
echo " Copyright (c) 2023, Marcos Cruz (programandala.net)"
echo " SPDX-License-Identifier: Fair\n"
pressAnyKeyToStart()
proc printInstructions =
echo "Here is a revolver."
echo "Press 'f' to spin chamber and pull trigger."
echo "Press 'g' to give up, and play again."
echo "Press 'q' to quit.\n"
proc play: bool =
random.randomize()
while true: # game loop
clearScreen()
printInstructions()
var times = 0
while true: # play loop
case command():
of 'f': # fire
if random.rand(100) > 83:
echo "Bang! You're dead!"
echo "Condolences will be sent to your relatives."
break # next game
else:
times += 1
if times > 10:
echo "You win!"
echo "Let someone else blow his brains out."
break # next game
else:
echo "Click."
of 'g': # give up
echo "Chicken!"
break # next game
of 'q': # quit
return false
else:
echo "Invalid key."
printInstructions()
continue
pressAnyKeyToStart()
clearScreen()
printCredits()
discard play()
echo "Bye!"
En Odin
/*
Russian Roulette
Original version in BASIC:
Creative Computing (Morristown, New Jersey, USA), ca. 1980.
This version in Odin:
Copyright (c) 2023, 2025, Marcos Cruz (programandala.net)
SPDX-License-Identifier: Fair
Written in 2023-02/03, 2023-08/0, 2023-12, 2025-02.
Last modified: 20250407T1920+0200.
*/
package russian_roulette
import "../lib/anodino/src/read"
import "../lib/anodino/src/term"
import "core:fmt"
import "core:math/rand"
press_enter_to_start :: proc() {
s, _ := read.a_prompted_string("Press Enter to start. ")
delete(s)
}
print_credits :: proc() {
term.clear_screen()
fmt.println("Russian Roulette\n")
fmt.println("Original version in BASIC:")
fmt.println(" Creative Computing (Morristown, New Jersey, USA), ca. 1980.\n")
fmt.println("This version in Odin:")
fmt.println(" Copyright (c) 2023, Marcos Cruz (programandala.net)")
fmt.println(" SPDX-License-Identifier: Fair\n")
press_enter_to_start()
}
print_instructions :: proc() {
term.clear_screen()
fmt.println("Here is a revolver.")
fmt.println("Type 'f' to spin chamber and pull trigger.")
fmt.println("Type 'g' to give up, and play again.")
fmt.println("Type 'q' to quit.\n")
}
play :: proc() {
times := 0
for { // game loop
print_instructions()
times = 0
play_loop: for {
command := read.a_prompted_string("> ") or_else ""
defer delete(command)
switch command {
case "f" : // fire
if rand.int31_max(100) > 83 {
fmt.println("Bang! You're dead!")
fmt.println("Condolences will be sent to your relatives.")
break play_loop
} else {
times += 1
if times > 10 {
fmt.println("You win!")
fmt.println("Let someone else blow his brains out.")
break play_loop
} else {
fmt.println("Click.")
}
}
case "g" : // give up
fmt.println("Chicken!")
break play_loop
case "q" : // quit
return
}
} // play loop
press_enter_to_start()
} // game loop
}
main :: proc() {
print_credits()
play()
fmt.println("Bye!")
}
En Pike
#! /usr/bin/env pike
// Russian Roulette
// Original version in BASIC:
// Creative Computing (Morristown, New Jersey, USA), ca. 1980.
// This version in Pike:
// Copyright (c) 2025, Marcos Cruz (programandala.net)
// SPDX-License-Identifier: Fair
//
// Written on 2025-03-10.
//
// Last modified: 20250310T0310+0100.
// Terminal {{{1
// =============================================================================
constant NORMAL_STYLE = 0;
void move_cursor_home() {
write("\x1B[H");
}
void set_style(int style) {
write("\x1B[%dm", style);
}
void reset_attributes() {
set_style(NORMAL_STYLE);
}
void erase_screen() {
write("\x1B[2J");
}
void clear_screen() {
erase_screen();
reset_attributes();
move_cursor_home();
}
// User input {{{1
// =============================================================================
string accept_string(string prompt) {
write(prompt);
return Stdio.stdin->gets();
}
void press_enter_to_start() {
accept_string("Press Enter to start. ");
}
// Credits and instructions {{{1
// =============================================================================
void print_credits() {
clear_screen();
write("Russian Roulette\n\n");
write("Original version in BASIC:\n");
write(" Creative Computing (Morristown, New Jersey, USA), ca. 1980.\n\n");
write("This version in Pike:\n");
write(" Copyright (c) 2025, Marcos Cruz (programandala.net)\n");
write(" SPDX-License-Identifier: Fair\n\n");
press_enter_to_start();
}
void print_instructions() {
clear_screen();
write("Here is a revolver.\n");
write("Type 'f' to spin chamber and pull trigger.\n");
write("Type 'g' to give up, and play again.\n");
write("Type 'q' to quit.\n\n");
}
// Main {{{1
// =============================================================================
void play() {
int times = 0;
while (true) { // game loop
print_instructions();
times = 0;
play_loop: while (true) {
string command = accept_string("> ");
switch (command) {
case "f": // fire
if (random(100) > 83) {
write("Bang! You're dead!\n");
write("Condolences will be sent to your relatives.\n");
break play_loop;
} else {
times += 1;
if (times > 10) {
write("You win!\n");
write("Let someone else blow his brains out.\n");
break play_loop;
} else {
write("Click.\n");
}
}
break;
case "g": // give up
write("Chicken!\n");
break play_loop;
case "q": // quit
return;
default:
continue;
}
} // play loop
press_enter_to_start();
} // game loop
}
void bye() {
write("Bye!\n");
}
void main() {
print_credits();
play();
bye();
}
En Python
# Russian Roulette
# Original version in BASIC:
# Creative Computing (Morristown, New Jersey, USA), ca. 1980.
# This version in Python:
# Copyright (c) 2024, Marcos Cruz (programandala.net)
# SPDX-License-Identifier: Fair
#
# Written on 2024-10-29.
#
# Last modified: 20241029T1937+0100.
import math
import os
from random import random
# Clear the terminal and move the cursor to the top left position.
def clear_screen():
if os.name == 'nt':
_ = os.system('cls')
else:
# on mac and linux, `os.name` is 'posix'
_ = os.system('clear')
# Prompt the user to enter a command and return it.
def get_command(prompt = "> "):
print(prompt, end = "")
return input()
def press_enter_to_start():
_ = get_command("Press Enter to start. ")
def print_credits():
clear_screen()
print("Russian Roulette\n")
print("Original version in BASIC:")
print(" Creative Computing (Morristown, New Jersey, USA), ca. 1980.\n")
print("This version in Python:")
print(" Copyright (c) 2024, Marcos Cruz (programandala.net)")
print(" SPDX-License-Identifier: Fair\n")
press_enter_to_start()
def print_instructions():
clear_screen()
print("Here is a revolver.")
print("Type 'f' to spin chamber and pull trigger.")
print("Type 'g' to give up, and play again.")
print("Type 'q' to quit.\n")
def play():
while True: # game loop
print_instructions()
times = 0
while True: # play loop
command = get_command()
if command == "f": # fire
if int(math.floor(100 * random())) > 83:
print("Bang! You're dead!")
print("Condolences will be sent to your relatives.")
break
else:
times += 1
if times == 10:
print("You win!")
print("Let someone else blow his brains out.")
break
else:
print("Click.")
elif command == "g": # give up
print("Chicken!")
break
elif command == "q": # quit
return False
# end of case
# end of play loop
press_enter_to_start()
# end of game loop
return True # play again, do not quit
print_credits()
playing = True
while playing:
playing = play()
print("Bye!")
En Raku
# Russian Roulette
#
# Original version in BASIC:
# Creative Computing (Morristown, New Jersey, USA), ca. 1980.
#
# This version in Raku:
# Copyright (c) 2024, Marcos Cruz (programandala.net)
# SPDX-License-Identifier: Fair
#
# Written in 2024-12.
#
# Last modified: 20241210T1323+0100.
sub clear_screen {
print "\e[0;0H\e[2J";
}
sub press_enter_to_start {
prompt 'Press Enter to start. ';
}
sub print_credits {
clear_screen;
put "Russian Roulette\n";
put 'Original version in BASIC:';
put " Creative Computing (Morristown, New Jersey, USA), ca. 1980.\n";
put 'This version in Raku:';
put ' Copyright (c) 2024, Marcos Cruz (programandala.net)';
put " SPDX-License-Identifier: Fair\n";
press_enter_to_start;
}
sub print_instructions {
clear_screen;
put 'Here is a revolver.';
put "Type 'f' to spin chamber and pull trigger.";
put "Type 'g' to give up, and play again.";
put "Type 'q' to quit.\n";
}
sub play {
clear_screen;
my $times = 0;
loop { # game loop
print_instructions;
$times = 0;
PLAY_LOOP: loop {
given (prompt '> ').lc {
when 'f' { # fire
if (0 .. 99).pick > 83 {
put "Bang! You're dead!";
put 'Condolences will be sent to your relatives.';
last PLAY_LOOP;
} else {
$times += 1;
if $times > 10 {
put 'You win!';
put 'Let someone else blow his brains out.';
last PLAY_LOOP;
} else {
put 'Click.';
}
}
}
when 'g' { # give up
put 'Chicken!';
last PLAY_LOOP;
}
when 'q' { # quit
return;
}
}
} # play loop
press_enter_to_start;
} # game loop
}
print_credits;
play;
put 'Bye!';
En Ring
# Russian Roulette
# Original version in BASIC:
# Creative Computing (Morristown, New Jersey, USA), ca. 1980.
# This version in Ring:
# Copyright (c) 2024, Marcos Cruz (programandala.net)
# SPDX-License-Identifier: Fair
#
# Written on 2024-04-05.
#
# Last modified: 20240405T1441+0200.
# Clears the terminal and moves the cursor to the top left position.
def clear_screen
system("clear")
end
# Prompts the user to enter a command and returns it.
def command(prompt)
if prompt = null
prompt = "> "
end
print(prompt)
return getString()
end
def press_enter_to_start
command("Press Enter to start. ")
end
def print_credits
clear_screen()
print("Russian Roulette\n\n")
print("Original version in BASIC:\n")
print(" Creative Computing (Morristown, New Jersey, USA), ca. 1980.\n\n")
print("This version in Ring:\n")
print(" Copyright (c) 2024, Marcos Cruz (programandala.net)\n")
print(" SPDX-License-Identifier: Fair\n\n")
press_enter_to_start()
end
def print_instructions
clear_screen()
print("Here is a revolver.\n")
print("Type 'f' to spin chamber and pull trigger.\n")
print("Type 'g' to give up, and play again.\n")
print("Type 'q' to quit.\n\n")
end
def playing
while true # game loop
print_instructions()
times = 0
while true # play loop
switch command("")
case "f" # fire
if random(100) > 83
print("Bang! You're dead!\n")
print("Condolences will be sent to your relatives.\n")
break
else
times += 1
if times > 10
print("You win!\n")
print("Let someone else blow his brains out.\n")
break
else
print("Click.\n")
end
end
case "g" # give up
print("Chicken!\n")
break
case "q" # quit
return false
end # switch
end # play loop
press_enter_to_start()
end # game loop
return true # play again, do not quit
end
def main
print_credits()
while playing()
end
print("Bye!\n")
end
En Scala
/*
Russian Roulette
Original version in BASIC:
Creative Computing (Morristown, New Jersey, USA), ca. 1980.
This version in Scala:
Copyright (c) 2023, Marcos Cruz (programandala.net)
SPDX-License-Identifier: Fair
Written in 2023-09.
Last modified: 20231103T2352+0100.
*/
// Move the cursor to the top left position of the terminal.
def home() =
print("\u001B[H")
// Clear the terminal and move the cursor to the top left position.
def clear() =
print("\u001B[2J")
home()
// Prompts the user to enter a command and returns it trimmed.
def command(prompt : String = "> ") : String =
io.StdIn.readLine(prompt).trim
// Prints the given prompt and waits until the user enters an empty string.
def pressEnter(prompt : String) =
var ok = false
while !ok do
ok = io.StdIn.readLine(prompt) == ""
def pressEnterToStart() =
pressEnter("Press Enter to start. ")
def printCredits() =
clear()
println("Russian Roulette\n")
println("Original version in BASIC:")
println(" Creative Computing (Morristown, New Jersey, USA), ca. 1980.\n")
println("This version in Scala:")
println(" Copyright (c) 2023, Marcos Cruz (programandala.net)")
println(" SPDX-License-Identifier: Fair\n")
pressEnterToStart()
def printCommands() =
println("Type 'f' to spin chamber and pull trigger.")
println("Type 'g' to give up, and play again.")
println("Type 'q' to quit.")
def printInstructions() =
clear()
println("Here is a revolver.")
printCommands()
println()
def play() =
var gameOver = false
while !gameOver do // game loop
printInstructions()
var times = 0
var playing = true
while playing do // play loop
command() match
case "f" => // fire
if util.Random.nextInt(100) > 83 then
println("Bang! You're dead!")
println("Condolences will be sent to your relatives.")
playing = false
else
times += 1
if times > 10 then
println("You win!")
println("Let someone else blow his brains out.")
playing = false
else
println("Click.")
case "g" => // give up
println("Chicken!")
playing = false
case "q" => // quit
playing = false
gameOver = true
case _ =>
println("Wrong action.")
printCommands()
end while // play loop
pressEnterToStart()
end while // game loop
@main def main() =
printCredits()
play()
println("Bye!")
En V
/*
Russian Roulette
Original version in BASIC:
Creative Computing (Morristown, New Jersey, USA), ca. 1980.
This version in V:
Copyright (c) 2023, Marcos Cruz (programandala.net)
SPDX-License-Identifier: Fair
Last modified 20231103T2127+0100.
*/
import rand
import readline
import term
fn any_key_to_start() {
println('\nPress any key to start.')
term.utf8_getchar() or { ` ` }
}
fn credits() {
term.clear()
println('Russian Roulette\n')
println('Original version in BASIC:')
println(' Creative computing (Morristown, New Jersey, USA), ca. 1980.\n')
println('This version in V:')
println(' Copyright (c) 2023, Marcos Cruz (programandala.net)')
println(' SPDX-License-Identifier: Fair\n')
any_key_to_start()
}
fn instructions() {
term.clear()
println('Here is a revolver.')
println("Press 'f' to spin chamber and pull trigger.")
println("Press 'g' to give up, and play again.")
println("Press 'q' to quit.\n")
}
fn play() bool {
mut times := 0
for {
instructions()
times = 0
for {
match term.utf8_getchar() or { ` ` } {
`f` {
// fire
if (rand.intn(100) or { 0 }) > 83 {
println("Bang! You're dead!")
println('Condolences will be sent to your relatives.')
break
} else {
times += 1
if times > 10 {
println('You win!')
println('Let someone else blow his brains out.')
break
} else {
println('Click.')
}
}
}
`g` {
// give up
println('Chicken!')
break
}
`q` {
// quit
return false
}
else {} // any other option: do nothing
} // match options
} // turn loop
any_key_to_start()
} // game loop
return true // play again, do not quit
}
fn main() {
mut rl := readline.Readline{}
rl.enable_raw_mode_nosig()
credits()
for play() {}
println('Bye!')
rl.disable_raw_mode()
}
