Files
hakorune/examples/text_adventure/ultra_simple_adventure.nyash
Moe Charm 0bed0c0271 🎉 initial commit: Nyash Programming Language完成版
🚀 主要機能:
• Everything is Box哲学による革新的アーキテクチャ
• WebAssemblyブラウザー対応プレイグラウンド
• アーティスト協同制作デモ - 複数Boxインスタンス実証
• 視覚的デバッグシステム - DebugBox完全統合
• static box Mainパターン - メモリ安全設計

 言語機能:
• NOT/AND/OR/除算演算子完全実装
• ジェネリクス/テンプレートシステム
• 非同期処理(nowait/await)
• try/catchエラーハンドリング
• Canvas統合グラフィックス

🎨 ブラウザー体験:
• 9種類のインタラクティブデモ
• リアルタイムコード実行
• WebCanvas/WebConsole/WebDisplay
• モバイル対応完了

🤖 Built with Claude Code collaboration
Ready for public release!
2025-08-09 15:14:44 +09:00

156 lines
3.4 KiB
Plaintext

// Ultra Simple Text Adventure Game
// Creates all objects directly at the top level to avoid the bug
// Simple Room
box SimpleRoom {
init { name, description, hasPotion, hasSword }
SimpleRoom(name, desc) {
me.name = name
me.description = desc
me.hasPotion = true
me.hasSword = true
}
look() {
print("=== " + me.name + " ===")
print(me.description)
print("")
if me.hasPotion {
print("You see a Health Potion here.")
}
if me.hasSword {
print("You see an Iron Sword here.")
}
}
takePotion() {
if me.hasPotion {
me.hasPotion = false
return true
}
return false
}
takeSword() {
if me.hasSword {
me.hasSword = false
return true
}
return false
}
}
// Simple Player
box SimplePlayer {
init { name, health, hasPotion, hasSword }
SimplePlayer(name) {
me.name = name
me.health = 100
me.hasPotion = false
me.hasSword = false
}
status() {
print("=== " + me.name + " ===")
print("Health: " + me.health)
inv = "Inventory: "
if me.hasPotion {
inv = inv + "Health Potion "
}
if me.hasSword {
inv = inv + "Iron Sword "
}
if me.hasPotion == false && me.hasSword == false {
inv = inv + "Empty"
}
print(inv)
}
heal() {
if me.hasPotion {
me.health = 100
me.hasPotion = false
print("You use the Health Potion and restore your health to 100!")
} else {
print("You don't have a potion.")
}
}
attack() {
if me.hasSword {
print("You swing your sword! *SWOOSH*")
} else {
print("You have no weapon to attack with.")
}
}
takeDamage(amount) {
me.health = me.health - amount
print("Ouch! You take " + amount + " damage.")
if me.health <= 0 {
print("💀 You have died! Game Over.")
}
}
}
// Create game objects directly (not in functions!)
print("🎮 Ultra Simple Adventure Game")
print("==============================")
print("")
// Direct creation works!
room = new SimpleRoom("Entrance Hall", "A dusty room with stone walls.")
player = new SimplePlayer("Hero")
print("Game initialized!")
print("")
// Test the game
print("--- Look around ---")
room.look()
print("")
print("--- Check status ---")
player.status()
print("")
print("--- Take items ---")
if room.takePotion() {
player.hasPotion = true
print("You take the Health Potion.")
}
if room.takeSword() {
player.hasSword = true
print("You take the Iron Sword.")
}
print("")
print("--- Status after taking items ---")
player.status()
print("")
print("--- Take damage ---")
player.takeDamage(50)
player.status()
print("")
print("--- Heal ---")
player.heal()
player.status()
print("")
print("--- Attack ---")
player.attack()
print("")
print("✅ Game test completed!")
print("")
print("This ultra-simple version works because all instances are created")
print("directly at the top level, not inside functions.")
print("")
print("⚠️ CRITICAL BUG: Instances created inside functions or returned")
print("from functions lose their field access capability!")