Reading a game before changing it
Key Quest is a small adventure: find the key, dodge the slimes, open the door, reach the treasure. One C# script runs it. Before you change anything, you'll learn how it's put together.
1. Play it
Press Play. Move with the arrow keys or WASD. Get the key, open the door, touch a slime on purpose. Write down the rules you can see.
2. Read it in four parts
Open Game.cs. Every game script does four jobs. Find each one and mark it with a comment:
// SETUPwhere things get names (var key = Find("Key");)// INPUTwhere the player's keys move the character// RULEStheifs that check touching the key, the door, a slime// FEEDBACKthe lines that changestatus.Text,message.Text, or play a sound
3. Map it
Take a screenshot of the room (or draw it). Draw an arrow from each object to the lines in the script that use it. If an object has no arrow, it's just scenery.
4. Add a second room
Plan first, on paper: where the new room goes, where its key is, what its door needs.
- Select the room's walls, floor, key and door in Your world, duplicate them, and drag the copies to make room two. Rename the copies:
Key2,Door2.Find("Key")only ever finds the first one. - In SETUP add
var key2 = Find("Key2");andvar door2 = Find("Door2");. - In RULES, extend the rule. Two ways:
- a second variable hasKey2 and a second door check, or
- a count: keys += 1 when any key is picked up, and doors check keys >= 1 and keys >= 2.
- Pick one, and write a comment above it saying why.
5. Write it up
Three sentences: what the rule checks, what it changes, and why you chose separate variables or a count.
Done when
- Game.cs has the four section comments in the right places.
- Both doors work and only open with their key(s).
- Your comment and write-up explain the choice.