hedy
hedy copied to clipboard
📜 New tic tac toe adventure
This is the draft for the new Tic Tac Toe adventure. I haven't had a change to test it myself yet, as my local host stopped working for some unknown reason, so I'll test it next week.
The level 16 content should work fine. For the level 17 content I came across I problem I didn't understand. @Felienne I've sent you this problem on discord. Do you know what's wrong? This is the code that I think should work, but doesn't.
field = ['.', '.', '.', '.', '.', '.', '.', '.', '.']
game_over = 'no'
sign = 'x'
define print_field:
clear
print 'TIC TAC TOE'
print field[1] field[2] field[3]
print field [4] field[5] field[6]
print field[7] field[8] field[9]
define detect_winner with field, game_over, sign:
if field[1] == field[2] and field[2] == field[3] and field[1] != '.':
game_over = 'yes'
print 'Player ' sign 'wins!'
call print_field
#The game
while game_over == 'no':
choice = ask 'Player ' sign ' what spot do you choose?'
if field[choice] = '.':
field[choice] = sign
call print_field
game_over = call detect_winner with field, game_over, sign
if sign == 'x':
sign = 'o'
else:
sign = 'x'
This extremely simplified version does work, so I think the problem lies with me:
a = 1
b = 2
c = 1
define function with a, b, c:
if a == b and b == c and a !=2:
print 'yes'
else:
print 'no'
call function with a, b, c
EDIT: did another test and changed field[1], field[2] and field[3] to a, b and c. This also works. Still don't quite know why. But this might be helpful.
field = ['.', '.', '.', '.', '.', '.', '.', '.', '.']
game_over = 'no'
sign = 'x'
a = 1
b = 1
c = 1
define print_field:
clear
print 'TIC TAC TOE'
print field[1] field[2] field[3]
print field [4] field[5] field[6]
print field[7] field[8] field[9]
define detect_winner with a, b, c, game_over, sign:
if a == b and b == c and a != 3:
game_over = 'yes'
print 'Player ' sign 'wins!'
call print_field
#The game
while game_over == 'no':
choice = ask 'Player ' sign ' what spot do you choose?'
if field[choice] = '.':
field[choice] = sign
call print_field
game_over = call detect_winner with a, b, c, game_over, sign
if sign == 'x':
sign = 'o'
else:
sign = 'x'
If we can get it to work, I'll test it next week and I'll add it to the other languages and translate it to Dutch.
PS. The tests will definitely be mad, because I removed some levels from the old toc tac toe adventure in english, but they are still there in the other languages. So that's no problem.
The content is done! But it can't be merged before #5398 is fixed.
I've also tried making a start with adding the drawing function, like the example from kjansen, which is really cool, but also quite hard. I'm giving up for now, but might contiue later. This is how far I got:
define start_position:
color white
turn -90
forward 100
turn 90
forward 200
define draw_field:
color black
turn 180
forward 300
color white
turn -90
forward 100
turn -90
color black
forward 300
color white
turn 90
forward 100
turn 90
forward 100
color black
turn 90
forward 300
color white
turn -90
forward 100
turn -90
color black
forward 300
define return_to_start:
color white
turn -90
forward 200
turn -90
forward 300
turn -90
call start_position
call draw_field
call return_to_start
define draw_sign with sign:
if sign == 'x':
right_color = 'blue'
else:
right_color = 'red'
turn -45
color right_color
forward 63
color white
turn -135
forward 45
turn -135
color right_color
forward 63
turn -45
color white
forward -45
sign = 'o'
call draw_sign with sign
This is kjansens example:
beurt = rood
openplekken = 1,2,3,4,5,6,7,8,9
aantal = 0
color white
forward 130
turn -90
forward 200
color black
turn 180
repeat 3 times
repeat 3 times
repeat 4 times
forward 90
turn 90
forward 90
forward -270
turn 90
forward 90
turn -90
turn 90
forward -270
turn -90
repeat 20 times
if aantal = 9
vakje = 0
else
vakje = ask 'In welk vakje een ' beurt ' kruis?'
if vakje in openplekken
remove vakje from openplekken
aantal = aantal + 1
t1 = vakje - 1
t1 = t1 / 3
f1 = t1 * 90
if t1 = 2
t1 = 1
t1 = t1 * 90
t2 = -1 * t1
f2 = 0
if vakje = 2
f2 = 90
if vakje = 3
f2 = 180
if vakje = 5
f2 = 90
if vakje = 6
f2 = 180
if vakje = 8
f2 = 90
if vakje = 9
f2 = 180
turn t1
forward f1
turn t2
forward f2
if beurt = rood
color red
if beurt = blauw
color blue
turn 45
forward 127
turn 135
forward 90
turn 135
forward 127
turn 45
forward -90
color black
t1 = -1 * t1
f1 = -1 * f1
t2 = -1 * t2
f2 = -1 * f2
forward f2
turn t2
forward f1
turn t1
winnaar is ask 'Heb je gewonnen? (type ja als je gewonnen hebt)'
if winnaar = 'ja'
print 'De winnaar is ' beurt '. Goed gedaan!'
aantal = 9
else
if beurt = rood
beurt = blauw
else
beurt = rood
else
if vakje = 0
vakje = 0
else
print 'Dat vakje is al bezet.'
if winnaar = 'ja'
print 'We hebben een winnaar! En het is ' beurt
else
print 'Niemand heeft gewonnen.'
forward 270
turn 90
forward 270
turn 90
forward 270
turn 90
forward 270
turn 90
Hi @MarleenGilsing!
The issue should be fixed now, can you check?
Also for the complicated adventure, you/we can also consider to add it as a public adventure? Then people can use if but it won't show up on the tabs right away? (thinking about it, we can move a few more there?)
@Felienne
The error is gone, so it worked :)
Yes, good idea, i like that for the drawing adventure, because it's too complicated to add as a normal adventure. I'll turn that into a seperate issue. So this can be closed.
Thank you for contributing! Your pull request is now going on the merge train (choo choo! Do not click update from main anymore, and be sure to allow changes to be pushed to your fork).