Skip to content

Commit f4ea084

Browse files
committed
x
1 parent 8bdabf9 commit f4ea084

37 files changed

+697
-105
lines changed

Diff for: computercraft/simple/chohan.lua

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
print('Cho-Han')
2+
3+
dice1 = math.random(1, 6)
4+
dice2 = math.random(1, 6)
5+
6+
print('The dealer swirls the cup and you hear')
7+
print('rattle of dice. The dealer slams the cup')
8+
print('on the floor, still covering the dice')
9+
print('and asks for your bet.')
10+
print()
11+
print(' CHO (even) or HAN (odd)?')
12+
13+
bet = string.upper(read())
14+
15+
print('The dealer lifts the cup to reveal:')
16+
print(' ' .. dice1 .. ' - ' .. dice2)
17+
18+
rollIsEven = (dice1 + dice2) % 2 == 0
19+
correctBet = ''
20+
if rollIsEven then
21+
correctBet = 'CHO'
22+
else
23+
correctBet = 'HAN'
24+
end
25+
26+
if bet == correctBet then
27+
print('You won!')
28+
else
29+
print('You lost!')
30+
end
31+
32+
33+

Diff for: computercraft/simple/countdown.lua

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
timeLeft = 10
2+
3+
while timeLeft > 0 do
4+
print(timeLeft)
5+
os.sleep(1)
6+
timeLeft = timeLeft - 1
7+
end
8+
print('BLAST OFF')
9+

Diff for: computercraft/simple/deepcave.lua

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
WIDTH = 40
2+
3+
leftWidth = 20
4+
5+
while true do
6+
local rightWidth = WIDTH - gapWidth - leftWidth
7+
io.write(string.rep('#', leftWidth))
8+
io.write(string.rep(' ', 10))
9+
io.write(string.rep('#', rightWidth))
10+
io.write('\n')
11+
12+
os.sleep(0.05)
13+
14+
local diceRoll = math.random(1, 6)
15+
if diceRoll == 1 and leftWidth > 1 then
16+
leftWidth = leftWidth - 1
17+
elseif diceRoll == 2 and leftWidth + gapWidth < WIDTH - 1 then
18+
leftWidth = leftWidth + 1
19+
end
20+
end

Diff for: computercraft/simple/guess.lua

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
secretNumber = math.random(1, 100)
2+
print('I am thinking of a number between 1 and 100.')
3+
4+
for i = 0, 9 do -- Give the player 10 guesses.
5+
print('You have ' .. (10 - i) .. ' guesses left.')
6+
print('Take a guess.')
7+
8+
guess = read()
9+
if guess == secretNumber then
10+
break
11+
end
12+
13+
if guess < secretNumber then
14+
print('Your guess is too low.')
15+
end
16+
if guess > secretNumber then
17+
print('Your guess is too high.')
18+
end
19+
end
20+
21+
if guess == secretNumber then
22+
print('Yay! You guessed my number!')
23+
else
24+
print('Game over. The number was ' .. secretNumber)
25+
end

Diff for: computercraft/simple/hexgrid.lua

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
for y = 1, 10 do
2+
for x = 1, 12 do
3+
io.write('/ \\_')
4+
end
5+
print()
6+
7+
for x = 1, 12 do
8+
io.write('\\_/ ')
9+
end
10+
print()
11+
end
12+

Diff for: computercraft/simple/river.lua

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
WIDTH = 40
2+
3+
leftWidth = 20
4+
5+
while true do
6+
io.write(string.rep(' ', leftWidth))
7+
io.write(string.rep('~', 10))
8+
io.write('\n')
9+
10+
os.sleep(0.05)
11+
12+
diceRoll = math.random(1, 6)
13+
if diceRoll == 1 and leftWidth > 1 then
14+
leftWidth = leftWidth - 1
15+
elseif diceRoll == 2 and leftWidth < WIDTH - 1 then
16+
leftWidth = leftWidth + 1
17+
end
18+
end

Diff for: computercraft/simple/rockpaperscissors.lua

+65
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
--[[Rock, Paper, Scissors
2+
By Al Sweigart [email protected]
3+
The classic hand game of luck.
4+
]]
5+
6+
print('Rock, Paper, Scissors by Al Sweigart')
7+
print()
8+
print('- Rock beats scissors.')
9+
print('- Paper beats rocks.')
10+
print('- Scissors beats paper.')
11+
12+
print('Enter your move.')
13+
print('(R)ock (P)aper (S)cissors (Q)uit')
14+
playerMove = string.upper(read())
15+
if playerMove == 'Q' then
16+
print('Thanks for playing!')
17+
error()
18+
end
19+
20+
-- Display what the player chose:
21+
if playerMove == 'R' then
22+
print('ROCK versus...')
23+
playerMove = 'ROCK'
24+
elseif playerMove == 'P' then
25+
print('PAPER versus...')
26+
playerMove = 'PAPER'
27+
elseif playerMove == 'S' then
28+
print('SCISSORS versus...')
29+
playerMove = 'SCISSORS'
30+
end
31+
32+
-- Count to three with dramatic pauses:
33+
os.sleep(0.5)
34+
print('1...')
35+
os.sleep(0.25)
36+
print('2...')
37+
os.sleep(0.25)
38+
print('3...')
39+
os.sleep(0.25)
40+
41+
-- Display what the computer chose:
42+
randomNumber = math.random(1, 3)
43+
if randomNumber == 1 then
44+
computerMove = 'ROCK'
45+
elseif randomNumber == 2 then
46+
computerMove = 'PAPER'
47+
elseif randomNumber == 3 then
48+
computerMove = 'SCISSORS'
49+
end
50+
print(computerMove)
51+
os.sleep(0.5)
52+
53+
-- Display and record the win/loss/tie:
54+
if playerMove == computerMove then
55+
print('It\'s a tie!')
56+
elseif playerMove == 'ROCK' and computerMove == 'SCISSORS' then
57+
print('You win!')
58+
elseif playerMove == 'PAPER' and computerMove == 'ROCK' then
59+
print('You win!')
60+
elseif playerMove == 'SCISSORS' and computerMove == 'PAPER' then
61+
print('You win!')
62+
else
63+
print('You lose!')
64+
end
65+

Diff for: computercraft/simple/rockpaperscissorswin.lua

+68
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
--[[Rock, Paper, Scissors
2+
By Al Sweigart [email protected]
3+
The classic hand game of luck, except you always
4+
win.
5+
]]
6+
7+
print('Rock, Paper, Scissors by Al Sweigart')
8+
print()
9+
print('- Rock beats scissors.')
10+
print('- Paper beats rocks.')
11+
print('- Scissors beats paper.')
12+
13+
-- These variables keep track of the number of
14+
-- wins, losses, and ties:
15+
local wins = 0
16+
17+
while true do -- main game loop
18+
local playerMove
19+
local computerMove
20+
while true do -- Ask player for their move
21+
print(wins .. ' Wins, 0 Losses, 0 Ties')
22+
print('Enter your move.')
23+
print('(R)ock (P)aper (S)cissors (Q)uit')
24+
playerMove = string.upper(read())
25+
if playerMove == 'Q' then
26+
print('Thanks for playing!')
27+
error()
28+
end
29+
30+
if playerMove == 'R' or playerMove == 'P' or playerMove == 'S' then
31+
break
32+
else
33+
print('Type one of R, P, S, or Q.')
34+
end
35+
end
36+
37+
-- Display what the player chose:
38+
if playerMove == 'R' then
39+
print('ROCK versus...')
40+
elseif playerMove == 'P' then
41+
print('PAPER versus...')
42+
elseif playerMove == 'S' then
43+
print('SCISSORS versus...')
44+
end
45+
46+
-- Count to three with dramatic pauses:
47+
os.sleep(0.5)
48+
print('1...')
49+
os.sleep(0.25)
50+
print('2...')
51+
os.sleep(0.25)
52+
print('3...')
53+
os.sleep(0.25)
54+
55+
-- Display what the computer chose:
56+
if playerMove == 'R' then
57+
computerMove = 'SCISSORS'
58+
elseif playerMove == 'P' then
59+
computerMove = 'ROCK'
60+
elseif playerMove == 'S' then
61+
computerMove = 'PAPER'
62+
end
63+
print(computerMove)
64+
os.sleep(0.5)
65+
66+
print('You win!')
67+
wins = wins + 1
68+
end

Diff for: computercraft/simple/shiningcarpet.lua

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
for i = 1, 3 do
2+
print(string.rep('_ \\ \\ \\_/ __', 4))
3+
print(string.rep(' \\ \\ \\___/ _', 4))
4+
print(string.rep('\\ \\ \\_____/ ', 4))
5+
print(string.rep('/ / / ___ \\_', 4))
6+
print(string.rep('_/ / / _ \\__', 4))
7+
print(string.rep('__/ / / \\___', 4))
8+
end
9+

Diff for: computercraft/simple/studyguide.txt

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
lua> 2
2+
lua> 2 + 2
3+
lua> 2 x 2 -- This causes an error.
4+
lua> 2 * 3
5+
lua> 21 / 7
6+
lua> 10 - 5
7+
lua> 5 - 10
8+
lua> 5 - -10
9+
lua> (2 + 2) * 3
10+
lua> 2 + (2 * 3)
11+
lua> 'hello' .. 'world'
12+
lua> 'hello ' .. 'world'
13+
lua> '2' .. '2'
14+
lua> 'hello' + world' -- This causes an error.
15+
lua> 2 .. 2 -- This causes an error.
16+
17+
18+
Variables
19+
lua> foo = 2
20+
lua> foo + 2
21+
lua> foo = 3
22+
lua> foo + 2
23+
lua> foo + foo + foo
24+
lua> 5 * foo
25+
26+
lua> biz = 'hello'
27+
lua> biz .. 'world'
28+
29+
Boolean Logic
30+
31+
32+
lua> math.random(1, 3)
33+
34+
lua> math.random(1, 3) + 1
35+
36+
Comparison Operators

Diff for: computercraft/simple/wave1.lua

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
size = 1
2+
inc = 1
3+
while true do
4+
for i = 1, size do
5+
io.write('#')
6+
end
7+
io.write('\n')
8+
os.sleep(0.1)
9+
10+
size = size + inc
11+
12+
if size == 10 then
13+
inc = -1
14+
elseif size == 0 then
15+
inc = 1
16+
end
17+
end

Diff for: computercraft/simple/wave2.lua

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
size = 1
2+
inc = 1
3+
while true do
4+
for i = 1, size do
5+
io.write(' ')
6+
end
7+
io.write('#\n')
8+
os.sleep(0.1)
9+
10+
size = size + inc
11+
12+
if size == 10 then
13+
inc = -1
14+
elseif size == 0 then
15+
inc = 1
16+
end
17+
end

Diff for: inprogress/tsuromapmaker.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -65,11 +65,11 @@
6565
'36020214232022260512031263']
6666

6767
# This code uses checksums to make sure the above TILES were typed correctly.
68-
for tile in enumerate(TILES):
69-
assert len(tile) == 26, 'Tile %r has an incorrect length.' % (tile,)
68+
for i, tile in enumerate(TILES):
69+
assert len(tile) == 26, 'Tile %r has an incorrect length %s.' % (tile, len(tile))
7070
total = 0
71-
for i in range(25):
72-
total += int(tile[i])
71+
for j in range(26):
72+
total += int(tile[j])
7373
assert total % 10 == 0, 'Tile %r is wrong.' % (tile,)
7474
TILES[i] = TILES[i][:25] # Cut off the checksum digit.
7575

Diff for: pyproject.toml

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[tool.ruff]
2+
line-length = 120
3+
ignore = ["E712", "E711", "E401"]

0 commit comments

Comments
 (0)