สามารถเปิดไฟล์ pig_game.py แล้วพิมพ์ python3 pig_game.py บนเครื่องของคุณได้เลย!
# ตัวแปร (Variables)
straw = 0
wood = 0
brick = 0
cement = 0
# เมื่อเก็บของ ตัวแปรจะเพิ่มค่า
straw = straw + 1
# เงื่อนไขสร้างบ้าน (If-Then)
if level == 1:
if straw >= 1:
print("🛖 สร้างบ้านฟางสำเร็จ!")
elif level == 2:
if straw >= 1 and wood >= 1:
print("🏡 สร้างบ้านไม้สำเร็จ!")
elif level == 3:
if brick >= 3 and cement >= 1:
print("🏰 สร้างบ้านอิฐแข็งแกร่งที่สุด!")
วิธีการวางบล็อกในโปรแกรม Scratch 3.0 (อ่านเพิ่มเติมใน SCRATCH_GUIDE.md)
บล็อกเก็บของ:
when green flag clicked
forever
if <touching [Pig v] ?> then
change [straw v] by (1)
hide
end
end
บล็อกตรวจเงื่อนไขสร้างบ้าน:
when I receive [craft_house v]
if <<(brick) > (2)> and <(cement) > (0)>> then
switch costume to [brick_house v]
play sound [Win Fanfare v]
else
say [ของยังไม่พอ!] for (2) secs
end