mirror of
https://github.com/coding-horror/basic-computer-games.git
synced 2026-01-09 03:43:01 -08:00
Removed spaces from top-level directory names.
Spaces tend to cause annoyances in a Unix-style shell environment. This change fixes that.
This commit is contained in:
7
66_Number/README.md
Normal file
7
66_Number/README.md
Normal file
@@ -0,0 +1,7 @@
|
||||
### Number
|
||||
|
||||
As published in Basic Computer Games (1978)
|
||||
https://www.atariarchives.org/basicgames/showpage.php?page=121
|
||||
|
||||
Downloaded from Vintage Basic at
|
||||
http://www.vintage-basic.net/games.html
|
||||
3
66_Number/csharp/README.md
Normal file
3
66_Number/csharp/README.md
Normal file
@@ -0,0 +1,3 @@
|
||||
Original source downloaded [from Vintage Basic](http://www.vintage-basic.net/games.html)
|
||||
|
||||
Conversion to [Microsoft C#](https://docs.microsoft.com/en-us/dotnet/csharp/)
|
||||
62
66_Number/java/Number.java
Normal file
62
66_Number/java/Number.java
Normal file
@@ -0,0 +1,62 @@
|
||||
import java.util.Scanner;
|
||||
|
||||
public class Number {
|
||||
|
||||
public static void main(String[] args) {
|
||||
printIntro();
|
||||
int points = 100; //start with 100 points for the user
|
||||
|
||||
Scanner scan = new Scanner(System.in);
|
||||
boolean done = false;
|
||||
while (!done) {
|
||||
System.out.print("GUESS A NUMBER FROM 1 TO 5? ");
|
||||
int g = scan.nextInt();
|
||||
|
||||
//Initialize 5 random numbers between 1-5
|
||||
var r = randomNumber(1);
|
||||
var s = randomNumber(1);
|
||||
var t = randomNumber(1);
|
||||
var u = randomNumber(1);
|
||||
var v = randomNumber(1);
|
||||
|
||||
if (r == g) {
|
||||
points -= 5;
|
||||
} else if (s == g) {
|
||||
points += 5;
|
||||
} else if (t == g) {
|
||||
points += points;
|
||||
} else if (u == g) {
|
||||
points += 1;
|
||||
} else if (v == g) {
|
||||
points -= points * 0.5;
|
||||
} else {
|
||||
continue; //Doesn't match any of our random numbers, so just ask for another guess
|
||||
}
|
||||
|
||||
if (points > 500) {
|
||||
done = true;
|
||||
} else {
|
||||
System.out.println("YOU HAVE " + points + " POINTS.");
|
||||
}
|
||||
}
|
||||
|
||||
System.out.println("!!!!YOU WIN!!!! WITH " + points + " POINTS.\n");
|
||||
}
|
||||
|
||||
private static int randomNumber(int x) {
|
||||
//Note: 'x' is totally ignored as was in the original basic listing
|
||||
return (int) (5 * Math.random() + 1);
|
||||
}
|
||||
|
||||
private static void printIntro() {
|
||||
System.out.println(" NUMBER");
|
||||
System.out.println(" CREATIVE COMPUTING MORRISTOWN, NEW JERSEY");
|
||||
System.out.println("\n\n\n");
|
||||
System.out.println("YOU HAVE 100 POINTS. BY GUESSING NUMBERS FROM 1 TO 5, YOU");
|
||||
System.out.println("CAN GAIN OR LOSE POINTS DEPENDING UPON HOW CLOSE YOU GET TO");
|
||||
System.out.println("A RANDOM NUMBER SELECTED BY THE COMPUTER.");
|
||||
System.out.println("\n");
|
||||
System.out.println("YOU OCCASIONALLY WILL GET A JACKPOT WHICH WILL DOUBLE(!)");
|
||||
System.out.println("YOUR POINT COUNT. YOU WIN WHEN YOU GET 500 POINTS.");
|
||||
}
|
||||
}
|
||||
3
66_Number/java/README.md
Normal file
3
66_Number/java/README.md
Normal file
@@ -0,0 +1,3 @@
|
||||
Original source downloaded [from Vintage Basic](http://www.vintage-basic.net/games.html)
|
||||
|
||||
Conversion to [Oracle Java](https://openjdk.java.net/)
|
||||
69
66_Number/java/main.class
Normal file
69
66_Number/java/main.class
Normal file
@@ -0,0 +1,69 @@
|
||||
|
||||
import java.time.temporal.ValueRange;
|
||||
import java.util.Arrays;
|
||||
import java.util.Random;
|
||||
import java.util.Scanner;
|
||||
|
||||
public class Number {
|
||||
|
||||
public static int points = 0;
|
||||
|
||||
public static void printempty() { System.out.println(" "); }
|
||||
|
||||
public static void print(String toprint) { System.out.println(toprint); }
|
||||
|
||||
public static void main(String[] args) {
|
||||
print("YOU HAVE 100 POINTS. BY GUESSING NUMBERS FROM 1 TO 5, YOU");
|
||||
print("CAN GAIN OR LOSE POINTS DEPENDING UPON HOW CLOSE YOU GET TO");
|
||||
print("A RANDOM NUMBER SELECTED BY THE COMPUTER.");
|
||||
printempty();
|
||||
print("YOU OCCASIONALLY WILL GET A JACKPOT WHICH WILL DOUBLE(!)");
|
||||
print("YOUR POINT COUNT. YOU WIN WHEN YOU GET 500 POINTS.");
|
||||
printempty();
|
||||
|
||||
try {
|
||||
while (true) {
|
||||
print("GUESS A NUMBER FROM 1 TO 5");
|
||||
|
||||
|
||||
Scanner numbersc = new Scanner(System.in);
|
||||
String numberstring = numbersc.nextLine();
|
||||
|
||||
int number = Integer.parseInt(numberstring);
|
||||
|
||||
if (!(number < 1| number > 5)) {
|
||||
|
||||
Random rand = new Random();
|
||||
|
||||
int randomNum = rand.nextInt((5 - 1) + 1) + 1;
|
||||
|
||||
if (randomNum == number) {
|
||||
print("YOU HIT THE JACKPOT!!!");
|
||||
points = points * 2;
|
||||
} else if(ValueRange.of(randomNum, randomNum + 1).isValidIntValue(number)) {
|
||||
print("+5");
|
||||
points = points + 5;
|
||||
} else if(ValueRange.of(randomNum - 1, randomNum + 2).isValidIntValue(number)) {
|
||||
print("+1");
|
||||
points = points + 1;
|
||||
} else if(ValueRange.of(randomNum - 3, randomNum + 1).isValidIntValue(number)) {
|
||||
print("-1");
|
||||
points = points - 1;
|
||||
} else {
|
||||
print("-half");
|
||||
points = (int) (points * 0.5);
|
||||
}
|
||||
|
||||
print("YOU HAVE " + points + " POINTS.");
|
||||
}
|
||||
|
||||
if (points >= 500) {
|
||||
print("!!!!YOU WIN!!!! WITH " + points + " POINTS.");
|
||||
return;
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
3
66_Number/javascript/README.md
Normal file
3
66_Number/javascript/README.md
Normal file
@@ -0,0 +1,3 @@
|
||||
Original source downloaded [from Vintage Basic](http://www.vintage-basic.net/games.html)
|
||||
|
||||
Conversion to [JavaScript](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Shells)
|
||||
9
66_Number/javascript/number.html
Normal file
9
66_Number/javascript/number.html
Normal file
@@ -0,0 +1,9 @@
|
||||
<html>
|
||||
<head>
|
||||
<title>NUMBER</title>
|
||||
</head>
|
||||
<body>
|
||||
<pre id="output" style="font-size: 12pt;"></pre>
|
||||
<script src="number.js"></script>
|
||||
</body>
|
||||
</html>
|
||||
93
66_Number/javascript/number.js
Normal file
93
66_Number/javascript/number.js
Normal file
@@ -0,0 +1,93 @@
|
||||
// NUMBER
|
||||
//
|
||||
// Converted from BASIC to Javascript by Oscar Toledo G. (nanochess)
|
||||
//
|
||||
|
||||
function print(str)
|
||||
{
|
||||
document.getElementById("output").appendChild(document.createTextNode(str));
|
||||
}
|
||||
|
||||
function input()
|
||||
{
|
||||
var input_element;
|
||||
var input_str;
|
||||
|
||||
return new Promise(function (resolve) {
|
||||
input_element = document.createElement("INPUT");
|
||||
|
||||
print("? ");
|
||||
input_element.setAttribute("type", "text");
|
||||
input_element.setAttribute("length", "50");
|
||||
document.getElementById("output").appendChild(input_element);
|
||||
input_element.focus();
|
||||
input_str = undefined;
|
||||
input_element.addEventListener("keydown", function (event) {
|
||||
if (event.keyCode == 13) {
|
||||
input_str = input_element.value;
|
||||
document.getElementById("output").removeChild(input_element);
|
||||
print(input_str);
|
||||
print("\n");
|
||||
resolve(input_str);
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
function tab(space)
|
||||
{
|
||||
var str = "";
|
||||
while (space-- > 0)
|
||||
str += " ";
|
||||
return str;
|
||||
}
|
||||
|
||||
// Main program
|
||||
async function main()
|
||||
{
|
||||
print(tab(33) + "NUMBER\n");
|
||||
print(tab(15) + "CREATIVE COMPUTING MORRISTOWN, NEW JERSEY\n");
|
||||
print("\n");
|
||||
print("\n");
|
||||
print("\n");
|
||||
print("YOU HAVE 100 POINTS. BY GUESSING NUMBERS FROM 1 TO 5, YOU\n");
|
||||
print("CAN GAIN OR LOSE POINTS DEPENDING UPON HOW CLOSE YOU GET TO\n");
|
||||
print("A RANDOM NUMBER SELECTED BY THE COMPUTER.\n");
|
||||
print("\n");
|
||||
print("YOU OCCASIONALLY WILL GET A JACKPOT WHICH WILL DOUBLE(!)\n");
|
||||
print("YOUR POINT COUNT. YOU WIN WHEN YOU GET 500 POINTS.\n");
|
||||
print("\n");
|
||||
p = 0;
|
||||
while (1) {
|
||||
do {
|
||||
print("GUESS A NUMBER FROM 1 TO 5");
|
||||
g = parseInt(await input());
|
||||
} while (g < 1 || g > 5) ;
|
||||
r = Math.floor(5 * Math.random() + 1);
|
||||
s = Math.floor(5 * Math.random() + 1);
|
||||
t = Math.floor(5 * Math.random() + 1);
|
||||
u = Math.floor(5 * Math.random() + 1);
|
||||
v = Math.floor(5 * Math.random() + 1);
|
||||
if (g == r) {
|
||||
p -= 5;
|
||||
} else if (g == s) {
|
||||
p += 5;
|
||||
} else if (g == t) {
|
||||
p += p;
|
||||
print("YOU HIT THE JACKPOT!!!\n");
|
||||
} else if (g == u) {
|
||||
p += 1;
|
||||
} else if (g == v) {
|
||||
p -= p * 0.5;
|
||||
}
|
||||
if (p <= 500) {
|
||||
print("YOU HAVE " + p + " POINTS.\n");
|
||||
print("\n");
|
||||
} else {
|
||||
print("!!!!YOU WIN!!!! WITH " + p + " POINTS.\n");
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
main();
|
||||
37
66_Number/number.bas
Normal file
37
66_Number/number.bas
Normal file
@@ -0,0 +1,37 @@
|
||||
1 PRINT TAB(33);"NUMBER"
|
||||
2 PRINT TAB(15);"CREATIVE COMPUTING MORRISTOWN, NEW JERSEY"
|
||||
3 PRINT:PRINT:PRINT
|
||||
4 PRINT "YOU HAVE 100 POINTS. BY GUESSING NUMBERS FROM 1 TO 5, YOU"
|
||||
5 PRINT "CAN GAIN OR LOSE POINTS DEPENDING UPON HOW CLOSE YOU GET TO"
|
||||
6 PRINT "A RANDOM NUMBER SELECTED BY THE COMPUTER.": PRINT
|
||||
7 PRINT "YOU OCCASIONALLY WILL GET A JACKPOT WHICH WILL DOUBLE(!)"
|
||||
8 PRINT "YOUR POINT COUNT. YOU WIN WHEN YOU GET 500 POINTS."
|
||||
9 PRINT: P=100
|
||||
10 DEF FNR(X)=INT(5*RND(1)+1)
|
||||
12 INPUT "GUESS A NUMBER FROM 1 TO 5";G
|
||||
15 R=FNR(1)
|
||||
16 S=FNR(1)
|
||||
17 T=FNR(1)
|
||||
18 U=FNR(1)
|
||||
19 V=FNR(1)
|
||||
20 IF G=R THEN 30
|
||||
21 IF G=S THEN 40
|
||||
22 IF G=T THEN 50
|
||||
23 IF G=U THEN 60
|
||||
24 IF G=V THEN 70
|
||||
25 IF G>5 THEN 12
|
||||
30 P=P-5
|
||||
35 GOTO 80
|
||||
40 P=P+5
|
||||
45 GOTO 80
|
||||
50 P=P+P
|
||||
53 PRINT "YOU HIT THE JACKPOT!!!"
|
||||
55 GOTO 80
|
||||
60 P=P+1
|
||||
65 GOTO 80
|
||||
70 P=P-(P*.5)
|
||||
80 IF P>500 THEN 90
|
||||
82 PRINT "YOU HAVE";P;"POINTS.":PRINT
|
||||
85 GOTO 12
|
||||
90 PRINT "!!!!YOU WIN!!!! WITH ";P;"POINTS."
|
||||
99 END
|
||||
3
66_Number/pascal/README.md
Normal file
3
66_Number/pascal/README.md
Normal file
@@ -0,0 +1,3 @@
|
||||
Original source downloaded [from Vintage Basic](http://www.vintage-basic.net/games.html)
|
||||
|
||||
Conversion to [Pascal](https://en.wikipedia.org/wiki/Pascal_(programming_language))
|
||||
3
66_Number/perl/README.md
Normal file
3
66_Number/perl/README.md
Normal file
@@ -0,0 +1,3 @@
|
||||
Original source downloaded [from Vintage Basic](http://www.vintage-basic.net/games.html)
|
||||
|
||||
Conversion to [Perl](https://www.perl.org/)
|
||||
39
66_Number/perl/number.pl
Executable file
39
66_Number/perl/number.pl
Executable file
@@ -0,0 +1,39 @@
|
||||
#!/usr/bin/perl
|
||||
use strict;
|
||||
|
||||
print ' 'x 33 . "NUMBER\n";
|
||||
print ' 'x 15 . "CREATIVE COMPUTING MORRISTOWN, NEW JERSEY\n";
|
||||
print "\n\n\n";
|
||||
print "YOU HAVE 100 POINTS. BY GUESSING NUMBERS FROM 1 TO 5, YOU\n";
|
||||
print "CAN GAIN OR LOSE POINTS DEPENDING UPON HOW CLOSE YOU GET TO\n";
|
||||
print "A RANDOM NUMBER SELECTED BY THE COMPUTER.\n"; print "\n";
|
||||
print "YOU OCCASIONALLY WILL GET A JACKPOT WHICH WILL DOUBLE(!)\n";
|
||||
print "YOUR POINT COUNT. YOU WIN WHEN YOU GET 500 POINTS.\n";
|
||||
print "\n"; my $P=100;
|
||||
|
||||
Line12:
|
||||
while ($P<500) {
|
||||
print "GUESS A NUMBER FROM 1 TO 5? "; chomp(my $G = <STDIN>);
|
||||
my $R= &FNR(1);
|
||||
my $S= &FNR(1);
|
||||
my $T= &FNR(1);
|
||||
my $U= &FNR(1);
|
||||
my $V= &FNR(1);
|
||||
if ($G eq $R) { $P=$P-5; }
|
||||
if ($G eq $S) { $P=$P+5; }
|
||||
if ($G eq $T) { $P=$P+$P; print "YOU HIT THE JACKPOT!!!\n"; }
|
||||
if ($G eq $U) { $P=$P+1; }
|
||||
if ($G eq $V) { $P=$P-($P*.5); }
|
||||
if ($G<1 || $G>5) { redo; }
|
||||
print "YOU HAVE $P POINTS.\n"; print "\n";
|
||||
}
|
||||
print "!!!!YOU WIN!!!! WITH $P POINTS.\n";
|
||||
exit;
|
||||
|
||||
|
||||
sub FNR {
|
||||
my ($X)= @_; #Useless...
|
||||
return int(5*rand(1)+1);
|
||||
}
|
||||
|
||||
|
||||
3
66_Number/python/README.md
Normal file
3
66_Number/python/README.md
Normal file
@@ -0,0 +1,3 @@
|
||||
Original source downloaded [from Vintage Basic](http://www.vintage-basic.net/games.html)
|
||||
|
||||
Conversion to [Python](https://www.python.org/about/)
|
||||
82
66_Number/python/number.py
Normal file
82
66_Number/python/number.py
Normal file
@@ -0,0 +1,82 @@
|
||||
"""
|
||||
NUMBER
|
||||
|
||||
A number guessing (gambling) game.
|
||||
|
||||
Ported by Dave LeCompte
|
||||
"""
|
||||
|
||||
import random
|
||||
|
||||
|
||||
def print_with_tab(num_spaces, msg):
|
||||
if num_spaces > 0:
|
||||
spaces = " " * num_spaces
|
||||
else:
|
||||
spaces = ""
|
||||
|
||||
print(spaces + msg)
|
||||
|
||||
|
||||
def print_instructions():
|
||||
print("YOU HAVE 100 POINTS. BY GUESSING NUMBERS FROM 1 TO 5, YOU")
|
||||
print("CAN GAIN OR LOSE POINTS DEPENDING UPON HOW CLOSE YOU GET TO")
|
||||
print("A RANDOM NUMBER SELECTED BY THE COMPUTER.")
|
||||
print()
|
||||
print("YOU OCCASIONALLY WILL GET A JACKPOT WHICH WILL DOUBLE(!)")
|
||||
print("YOUR POINT COUNT. YOU WIN WHEN YOU GET 500 POINTS.")
|
||||
print()
|
||||
|
||||
|
||||
def fnr():
|
||||
return random.randint(1, 5)
|
||||
|
||||
|
||||
def main():
|
||||
print_with_tab(33, "NUMBER")
|
||||
print_with_tab(15, "CREATIVE COMPUTING MORRISTOWN, NEW JERSEY")
|
||||
print()
|
||||
print()
|
||||
print()
|
||||
|
||||
print_instructions()
|
||||
|
||||
points = 100
|
||||
|
||||
while points <= 500:
|
||||
print("GUESS A NUMBER FROM 1 TO 5")
|
||||
guess = int(input())
|
||||
|
||||
if (guess < 1) or (guess > 5):
|
||||
continue
|
||||
|
||||
r = fnr()
|
||||
s = fnr()
|
||||
t = fnr()
|
||||
u = fnr()
|
||||
v = fnr()
|
||||
|
||||
if guess == r:
|
||||
# lose 5
|
||||
points -= 5
|
||||
elif guess == s:
|
||||
# gain 5
|
||||
points += 5
|
||||
elif guess == t:
|
||||
# double!
|
||||
points += points
|
||||
print("YOU HIT THE JACKPOT!!!")
|
||||
elif guess == u:
|
||||
# gain 1
|
||||
points += 1
|
||||
elif guess == v:
|
||||
# lose half
|
||||
points = points - (points * 0.5)
|
||||
|
||||
print(f"YOU HAVE {points} POINTS.")
|
||||
print()
|
||||
print(f"!!!!YOU WIN!!!! WITH {points} POINTS.")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
3
66_Number/ruby/README.md
Normal file
3
66_Number/ruby/README.md
Normal file
@@ -0,0 +1,3 @@
|
||||
Original source downloaded [from Vintage Basic](http://www.vintage-basic.net/games.html)
|
||||
|
||||
Conversion to [Ruby](https://www.ruby-lang.org/en/)
|
||||
3
66_Number/vbnet/README.md
Normal file
3
66_Number/vbnet/README.md
Normal file
@@ -0,0 +1,3 @@
|
||||
Original BASIC source [downloaded from Vintage Basic](http://www.vintage-basic.net/games.html)
|
||||
|
||||
Conversion to [Visual Basic .NET](https://en.wikipedia.org/wiki/Visual_Basic_.NET)
|
||||
Reference in New Issue
Block a user