-
Notifications
You must be signed in to change notification settings - Fork 279
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' of github.com:Felienne/hedy
- Loading branch information
Showing
11 changed files
with
315 additions
and
71 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
In level 4 blijven de regels hetzelfde voor ask en print. Je moet dus nog steeds aanhalingstekens gebruiken als je iets wilt printen. | ||
Er komt nu wel een nieuwe code bij, de if. if is Engels voor als. | ||
|
||
Hier vind je weer een aantal opdrachten om mee aan de slag te gaan. | ||
|
||
# Niet voor je kleine zusje of broertje! | ||
Toen ik zelf leerde programmeren, wat het eerste programma dat ik maakte een programma om te kijken of mijn zusje niet stiekem op de computer zat. | ||
Dat kun jij nu ook maken, het gaat zo: | ||
|
||
* `naam is ask Hoe heet jij?` | ||
* `if naam is Felienne print 'ok jij mag computeren' else print 'verboden toegang voor jou'` | ||
|
||
Deze code bekijkt of de naam die wordt ingetypt precies "Felienne" is. Zo kan, dan print Hedy de eerste code, anders de tweede. | ||
Let op, Hedy kijkt letterlijk naar de naam, dus het moet precies kloppen, ook met hoofdletter. | ||
|
||
# Steen, schaar, papier | ||
In Level 4 kunnen we ook weer steen schaar papier programmeren, maar nu kun je ook echt tegen de computer spelen, en bekijken wie de winnaar is. | ||
Hier is het begin van het programma, maak jij de regels zelf af? | ||
|
||
* `jouwkeuze is ask wat kies jij?` | ||
* `keuzes is steen, schaar, papier` | ||
* `computerkeuze is keuzes at random` | ||
* `if computerkeuze is schaar and jouw_keuze is papier print 'de computer wint'` | ||
* `if computerkeuze is schaar and jouw_keuze is steen print 'jij wint'` | ||
|
||
Herinnering: random (je zegt ren-dom) is het Engelse woord voor willekeurig, and is het Engelse woord voor en. | ||
|
||
# Maak dobbelsteen na | ||
Je kunt ook in Level 4 weer een dobbelsteen maken en daarbij een if gebruiken. Bijv zo: | ||
|
||
* `keuzes is 1, 2, 3, 4, 5, regenworm` | ||
* `worp is keuzes at random` | ||
* `print 'je hebt worp gegooid'` | ||
* `if worp is regenworm print 'Je mag stoppen met gooien.' else print 'Je moet nog een keer hoor!` | ||
|
||
Maar misschien wil jij wel een dobbelsteen uit een heel ander spel namaken. | ||
|
||
# Wie doet de afwas? | ||
Ook je afwasprogramma kun je nu leuker maken met een if. Bijvoorbeeld zo: | ||
|
||
Dat doe je zo: | ||
|
||
* `mensen is mama, papa, Emma, Sophie` | ||
* `afwasser is mensen at random` | ||
* `if afwasser is Sophie print 'chips ik moet de afwas doen' else print 'gelukkig geen afwas want ' afwasser ' doet het'` | ||
|
||
# Een beter verhaal | ||
Wat je ook kunt doet is je verhaal weer leuker maken, want nu kun je verschillende eindes programmeren. | ||
|
||
###Voorbeeld | ||
Maak een verhaal met twee eindes, bijvoorbeeld zo: | ||
|
||
* De prinses loopt door het bos | ||
* Ze komt een monster tegen | ||
|
||
Goed einde: | ||
* Ze pakt haar zwaard en het monster rent snel weg | ||
|
||
Slecht einde | ||
* Het monster eet de prinses op | ||
|
||
|
||
### Opdracht | ||
|
||
Nu jij! | ||
|
||
1. Schrijf een verhaal met twee eindes | ||
|
||
### Voorbeeld Hedy code | ||
* `print 'De prinses loopt door het bos'` | ||
* `print 'Ze komt een monster tegen'` | ||
* `einde is ask Wil je een goed of slecht einde?` | ||
* `if einde is goed print 'Ze pakt haar zwaard en het monster rent snel weg' else print 'Het monster eet de prinses op'` | ||
|
||
### Een interactief verhaal | ||
Je kunt ook zorgen dat er weer een naam ingevoerd kan worden. Dat werkt net zoals in level 3. Dat kun je dus ook combineren met een if, en dan heb je al een heel programma gemaakt! | ||
|
||
### Herhaling in je verhaal of spel | ||
Helaas kun je nu steeds maar 1 dobbelsteen gooien, of 1 keer bepalen wie de afwas doet. Regenwormen moet eigenlijk met 8 dobbelstenen, en | ||
misschien wil jij wel een afwasrooster maken voor de hele week! Some is het handig als je codes een paar keer kan herhalen. | ||
Dat kun je leren in Level 5. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,48 +1,35 @@ | ||
start: _EOL* statement+ | ||
start: program | ||
program: command ("\n" command)* | ||
command: "print " (quoted_text | list_access | var) (" " (quoted_text | list_access | var))* -> print | ||
| "if " equality_check " " command " else " command -> ifelse | ||
| "if " equality_check " " command -> ifs //if cannot be used in Python, hence ifs | ||
| text " is ask " textwithspaces punctuation* -> ask | ||
| text " is " text ((", "|",") text)+ -> assign_list | ||
| text " is " text -> assign //placing it here means print is will print 'is' and print is Felienne will print 'is Felienne' | ||
| text " is " var " at " (index | random) -> list_access_var | ||
| text " " textwithspaces -> invalid | ||
|
||
//TODO: I don't like the " " and "print " in the commands | ||
//would rather have them here but I am unsure how to stop hem from appearing in the tree that way | ||
//leaving as such for now | ||
|
||
equality_check: text " is " text (" and " equality_check)* -> equality_check | ||
var: LETTER+ -> var //TODO: should be used in assign too? | ||
list_access : var " at " (index | random) -> list_access | ||
|
||
index : DIGIT+ | ||
random : "random" | ||
punctuation : PUNCTUATION -> punctuation | ||
textwithspaces: (LETTER | DIGIT | WS_INLINE)+ -> text | ||
quoted_text: QUOTE (LETTER | DIGIT | PUNCTUATION | WS_INLINE)+ QUOTE -> text | ||
QUOTE : "'" | ||
text: (LETTER | DIGIT)+ -> text | ||
PUNCTUATION: "!" | "?" | "." //uppercase places tokens in tree | ||
|
||
%import common.LETTER // imports from terminal library | ||
%import common.DIGIT // imports from terminal library | ||
%import common.WS_INLINE // imports from terminal library | ||
%import common.NEWLINE // imports from terminal library | ||
|
||
statement: function_call | ||
| assignment _EOL+ | ||
| expression _EOL+ | ||
|
||
function_call: NAME expression _EOL+ | ||
|
||
assignment: NAME "is" expression | ||
|
||
?expression: sum | ||
| expression "=" sum -> eq | ||
| expression "!=" sum -> ne | ||
| expression "<=" sum -> le | ||
| expression ">=" sum -> ge | ||
| expression "<" sum -> lt | ||
| expression ">" sum -> gt | ||
|
||
?sum: product | ||
| sum "+" product -> addition | ||
| sum "-" product -> substraction | ||
|
||
?product: atom | ||
| product "*" atom -> multiplication | ||
| product "/" atom -> division | ||
| product "%" atom -> modulo | ||
|
||
?atom: NAME | ||
| INTEGER | ||
| FLOAT | ||
| STRING | ||
| "[" (expression? | (expression ",")+ expression) "]" -> list | ||
| "(" expression? ")" | ||
| NAME "at" expression -> list_access // TODO: shift reduce errors | ||
|
||
|
||
_EOL: /(\r?\n[\t ]*)+/ | ||
|
||
%import common.WS_INLINE | ||
%import common.SIGNED_INT -> INTEGER | ||
%import common.FLOAT -> FLOAT | ||
%import common.CNAME -> NAME | ||
%import common._STRING_ESC_INNER | ||
%import common.ESCAPED_STRING -> STRING // TODO: support single quoted strings | ||
|
||
%declare INDENT DEDENT | ||
|
||
%ignore WS_INLINE |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
start: _EOL* statement+ | ||
|
||
statement: function_call | ||
| assignment _EOL+ | ||
| expression _EOL+ | ||
|
||
function_call: NAME expression _EOL+ | ||
|
||
assignment: NAME "is" expression | ||
|
||
?expression: sum | ||
| expression "=" sum -> eq | ||
| expression "!=" sum -> ne | ||
| expression "<=" sum -> le | ||
| expression ">=" sum -> ge | ||
| expression "<" sum -> lt | ||
| expression ">" sum -> gt | ||
|
||
?sum: product | ||
| sum "+" product -> addition | ||
| sum "-" product -> substraction | ||
|
||
?product: atom | ||
| product "*" atom -> multiplication | ||
| product "/" atom -> division | ||
| product "%" atom -> modulo | ||
|
||
?atom: NAME | ||
| INTEGER | ||
| FLOAT | ||
| STRING | ||
| "[" (expression? | (expression ",")+ expression) "]" -> list | ||
| "(" expression? ")" | ||
| NAME "at" expression -> list_access // TODO: shift reduce errors | ||
|
||
|
||
_EOL: /(\r?\n[\t ]*)+/ | ||
|
||
%import common.WS_INLINE | ||
%import common.SIGNED_INT -> INTEGER | ||
%import common.FLOAT -> FLOAT | ||
%import common.CNAME -> NAME | ||
%import common._STRING_ESC_INNER | ||
%import common.ESCAPED_STRING -> STRING // TODO: support single quoted strings | ||
|
||
%declare INDENT DEDENT | ||
|
||
%ignore WS_INLINE |
Oops, something went wrong.