Skip to content

Commit ea2e7be

Browse files
Merge pull request #926 from marquesrs/bunny-rust-implementation
Rust implementation for the game Bunny
2 parents 795dac5 + 96afc1c commit ea2e7be

File tree

2 files changed

+120
-0
lines changed

2 files changed

+120
-0
lines changed

19_Bunny/rust/Cargo.toml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
[package]
2+
name = "rust"
3+
version = "0.1.0"
4+
edition = "2021"
5+
6+
[dependencies]

19_Bunny/rust/src/main.rs

Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
/** BUNNY GAME
2+
* https://github.com/coding-horror/basic-computer-games/tree/main/19_Bunny
3+
* Direct conversion from BASIC to Rust by Pablo Marques (marquesrs).
4+
* No additional features or improvements were added. As a faithful translation,
5+
* many of the code here are done in an unrecommended way by today's standards.
6+
* 17/02/25
7+
*/
8+
9+
//290 DATA 2,21,14,14,25
10+
//300 DATA 1,2,-1,0,2,45,50,-1,0,5,43,52,-1,0,7,41,52,-1
11+
//310 DATA 1,9,37,50,-1,2,11,36,50,-1,3,13,34,49,-1,4,14,32,48,-1
12+
//320 DATA 5,15,31,47,-1,6,16,30,45,-1,7,17,29,44,-1,8,19,28,43,-1
13+
//330 DATA 9,20,27,41,-1,10,21,26,40,-1,11,22,25,38,-1,12,22,24,36,-1
14+
//340 DATA 13,34,-1,14,33,-1,15,31,-1,17,29,-1,18,27,-1
15+
//350 DATA 19,26,-1,16,28,-1,13,30,-1,11,31,-1,10,32,-1
16+
//360 DATA 8,33,-1,7,34,-1,6,13,16,34,-1,5,12,16,35,-1
17+
//370 DATA 4,12,16,35,-1,3,12,15,35,-1,2,35,-1,1,35,-1
18+
//380 DATA 2,34,-1,3,34,-1,4,33,-1,6,33,-1,10,32,34,34,-1
19+
//390 DATA 14,17,19,25,28,31,35,35,-1,15,19,23,30,36,36,-1
20+
//400 DATA 14,18,21,21,24,30,37,37,-1,13,18,23,29,33,38,-1
21+
//410 DATA 12,29,31,33,-1,11,13,17,17,19,19,22,22,24,31,-1
22+
//420 DATA 10,11,17,18,22,22,24,24,29,29,-1
23+
//430 DATA 22,23,26,29,-1,27,29,-1,28,29,-1,4096
24+
25+
// 4096 is the end of file
26+
// -1 is the end of line
27+
const DATA: [i32;233] = [
28+
2,21,14,14,25,
29+
1,2,-1,0,2,45,50,-1,0,5,43,52,-1,0,7,41,52,-1,
30+
1,9,37,50,-1,2,11,36,50,-1,3,13,34,49,-1,4,14,32,48,-1,
31+
5,15,31,47,-1,6,16,30,45,-1,7,17,29,44,-1,8,19,28,43,-1,
32+
9,20,27,41,-1,10,21,26,40,-1,11,22,25,38,-1,12,22,24,36,-1,
33+
13,34,-1,14,33,-1,15,31,-1,17,29,-1,18,27,-1,
34+
19,26,-1,16,28,-1,13,30,-1,11,31,-1,10,32,-1,
35+
8,33,-1,7,34,-1,6,13,16,34,-1,5,12,16,35,-1,
36+
4,12,16,35,-1,3,12,15,35,-1,2,35,-1,1,35,-1,
37+
2,34,-1,3,34,-1,4,33,-1,6,33,-1,10,32,34,34,-1,
38+
14,17,19,25,28,31,35,35,-1,15,19,23,30,36,36,-1,
39+
14,18,21,21,24,30,37,37,-1,13,18,23,29,33,38,-1,
40+
12,29,31,33,-1,11,13,17,17,19,19,22,22,24,31,-1,
41+
10,11,17,18,22,22,24,24,29,29,-1,
42+
22,23,26,29,-1,27,29,-1,28,29,-1,4096,
43+
];
44+
45+
fn main() {
46+
let mut col = 0;
47+
48+
//10 PRINT TAB(33);"BUNNY"
49+
//20 PRINT TAB(15);"CREATIVE COMPUTING MORRISTOWN, NEW JERSEY"
50+
//30 PRINT: PRINT: PRINT
51+
//100 REM "BUNNY" FROM DAVID AHL'S 'BASIC COMPUTER GAMES'
52+
print!("{}{}\n{}{}\n",
53+
" ".repeat(33),
54+
"BUNNY",
55+
" ".repeat(15),
56+
"CREATIVE COMPUTING MORRISTOWN, NEW JERSEY"
57+
);
58+
59+
//120 FOR I=0 TO 4: READ B(I): NEXT I
60+
let mut b = [0;5];
61+
for i in 0..=4 {
62+
b[i] = DATA[col];
63+
col = col + 1;
64+
}
65+
66+
//130 GOSUB 260
67+
//260 FOR I=1 TO 6: PRINT CHR$(10);: NEXT I
68+
for _ in 1..=6 {
69+
println!();
70+
}
71+
//270 RETURN
72+
73+
//140 L=64: REM ASCII LETTER CODE...
74+
let l = 64;
75+
let mut prev = 0;
76+
loop {
77+
//170 READ X: IF X<0 THEN 160
78+
let x = DATA[col];
79+
col = col + 1;
80+
if x < 0 {
81+
//160 PRINT
82+
println!();
83+
prev = 0;
84+
continue;
85+
}
86+
//175 IF X>128 THEN 240
87+
else if x > 128 {
88+
//240 GOSUB 260: GOTO 450
89+
for _ in 1..=6 {
90+
println!();
91+
}
92+
break;
93+
}
94+
else {
95+
//180 PRINT TAB(X);: READ Y
96+
print!("{}", " ".repeat((x - prev) as usize)); // verificar
97+
prev = x;
98+
let y = DATA[col];
99+
col = col + 1;
100+
//190 FOR I=X TO Y: J=I-5*INT(I/5)
101+
for i in x..=y {
102+
let j = i - 5 * (i / 5);
103+
//200 PRINT CHR$(L+B(J));
104+
print!("{}", (l + b[j as usize]) as u8 as char);
105+
prev = prev + 1;
106+
//210 NEXT I
107+
108+
}
109+
//220 GOTO 170
110+
}
111+
}
112+
//450 END
113+
}
114+

0 commit comments

Comments
 (0)