Files
hakorune/examples/text_adventure/rooms.nyash

257 lines
6.6 KiB
Plaintext
Raw Normal View History

// Text Adventure Game - Rooms Module
// ルームシステムの実装
feat: using構文完全実装&json_native大幅進化 ## 🎉 using構文の完全実装(ChatGPT作業) - ✅ **include → using移行完了**: 全ファイルでusing構文に統一 - `local X = include` → `using "path" as X` - 約70ファイルを一括変換 - ✅ **AST/パーサー/MIR完全対応**: using専用処理実装 - ASTNode::Using追加 - MIRビルダーでの解決処理 - include互換性も維持 ## 🚀 json_native実装進化(ChatGPT追加実装) - ✅ **浮動小数点対応追加**: is_float/parse_float実装 - ✅ **配列/オブジェクトパーサー実装**: parse_array/parse_object完成 - ✅ **エスケープ処理強化**: Unicode対応、全制御文字サポート - ✅ **StringUtils大幅拡張**: 文字列操作メソッド多数追加 - contains, index_of_string, split, join等 - 大文字小文字変換(全アルファベット対応) ## 💡 MIR SIMD & ハイブリッド戦略考察 - **MIR15 SIMD命令案**: SimdLoad/SimdScan等の新命令セット - **C ABIハイブリッド**: ホットパスのみC委託で10倍速化可能 - **並行処理でyyjson超え**: 100KB以上で2-10倍速の可能性 - **3層アーキテクチャ**: Nyash層/MIR層/C ABI層の美しい分離 ## 📊 技術的成果 - using構文により名前空間管理が明確化 - json_nativeが実用レベルに接近(完成度25%→40%) - 将来的にyyjsonの70%速度達成可能と判明 ChatGPT爆速実装×Claude深い考察の完璧な協働! 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
2025-09-25 00:41:56 +09:00
using "text_adventure/items.nyash"
// 基本ルームBox
box Room {
init { name, description, items, exits, visited, locked }
Room(name, description) {
me.name = name
me.description = description
me.items = new MapBox()
me.exits = new MapBox()
me.visited = false
me.locked = false
}
// ルームの表示
look() {
result = ""
if me.visited {
result = me.name + "\n"
} else {
result = me.name + " (First time here!)\n"
me.visited = true
}
result = result + me.description + "\n"
// アイテムの表示
if me.items.size() > 0 {
result = result + "\nItems here:\n"
// MapBoxのキーを反復処理
keys = me.items.keys()
i = 0
loop(i < keys.size()) {
itemName = keys.get(i)
item = me.items.get(itemName)
itemDisplay = item.display()
result = result + "- " + itemDisplay + "\n"
i = i + 1
}
}
// 出口の表示
if me.exits.size() > 0 {
result = result + "\nExits: "
exitKeys = me.exits.keys()
i = 0
loop(i < exitKeys.size()) {
direction = exitKeys.get(i)
if i > 0 {
result = result + ", "
}
result = result + direction
i = i + 1
}
result = result + "\n"
}
return result
}
// アイテムを追加
addItem(item) {
itemName = item.name
me.items.put(itemName, item)
}
// アイテムを取得(削除)
takeItem(itemName) {
if me.items.has(itemName) {
item = me.items.get(itemName)
me.items.remove(itemName)
return item
}
return null
}
// アイテムの存在確認
hasItem(itemName) {
return me.items.has(itemName)
}
// 出口を追加
addExit(direction, targetRoom) {
me.exits.put(direction, targetRoom)
}
// 移動を試行
move(direction) {
if me.exits.has(direction) {
targetRoom = me.exits.get(direction)
isLocked = targetRoom.locked
if isLocked {
return null // 鍵がかかっている
}
return targetRoom
}
return null // 出口がない
}
// ルームをロック/アンロック
lock() {
me.locked = true
}
unlock() {
me.locked = false
}
isLocked() {
return me.locked
}
}
// 特別なルーム:宝物庫
box TreasureRoom {
init { name, description, items, exits, visited, locked, treasure }
TreasureRoom(name, description, treasureItem) {
me.name = name
me.description = description
me.items = new MapBox()
me.exits = new MapBox()
me.visited = false
me.locked = true // 宝物庫は最初ロック
me.treasure = treasureItem
// 宝物を配置
me.addItem(me.treasure)
}
// 基本Roomメソッドを再実装
look() {
result = ""
if me.visited {
result = me.name + " ✨\n"
} else {
result = me.name + " ✨ (First time here!)\n"
me.visited = true
}
result = result + me.description + "\n"
// アイテムの表示(特別演出)
if me.items.size() > 0 {
result = result + "\n💰 Treasures here:\n"
keys = me.items.keys()
i = 0
loop(i < keys.size()) {
itemName = keys.get(i)
item = me.items.get(itemName)
itemDisplay = item.display()
result = result + "- ✨ " + itemDisplay + " ✨\n"
i = i + 1
}
}
// 出口の表示
if me.exits.size() > 0 {
result = result + "\nExits: "
exitKeys = me.exits.keys()
i = 0
loop(i < exitKeys.size()) {
direction = exitKeys.get(i)
if i > 0 {
result = result + ", "
}
result = result + direction
i = i + 1
}
result = result + "\n"
}
return result
}
addItem(item) {
me.items.put(item.name, item)
}
takeItem(itemName) {
if me.items.has(itemName) {
item = me.items.get(itemName)
me.items.remove(itemName)
return item
}
return null
}
hasItem(itemName) {
return me.items.has(itemName)
}
addExit(direction, targetRoom) {
me.exits.put(direction, targetRoom)
}
move(direction) {
if me.exits.has(direction) {
targetRoom = me.exits.get(direction)
isLocked = targetRoom.locked
if isLocked {
return null
}
return targetRoom
}
return null
}
lock() {
me.locked = true
}
unlock() {
me.locked = false
}
isLocked() {
return me.locked
}
}
// ワールド作成関数
function createWorld() {
// アイテム作成
sword = createSword()
potion = createPotion()
treasureKey = createKey("treasure_room")
treasure = createTreasure()
// ルーム作成
entrance = new Room("Entrance Hall", "A grand entrance with marble columns. Light streams in from above.")
corridor = new Room("Long Corridor", "A dimly lit corridor with ancient tapestries on the walls.")
armory = new Room("Old Armory", "A dusty armory with weapon racks. Some items remain.")
treasureRoom = new TreasureRoom("Treasure Chamber", "A magnificent chamber filled with golden light.", treasure)
// アイテム配置
armory.addItem(sword)
corridor.addItem(potion)
entrance.addItem(treasureKey)
// 出口設定(双方向)
entrance.addExit("north", corridor)
corridor.addExit("south", entrance)
corridor.addExit("east", armory)
armory.addExit("west", corridor)
corridor.addExit("west", treasureRoom)
treasureRoom.addExit("east", corridor)
return entrance // スタート地点
}
feat: using構文完全実装&json_native大幅進化 ## 🎉 using構文の完全実装(ChatGPT作業) - ✅ **include → using移行完了**: 全ファイルでusing構文に統一 - `local X = include` → `using "path" as X` - 約70ファイルを一括変換 - ✅ **AST/パーサー/MIR完全対応**: using専用処理実装 - ASTNode::Using追加 - MIRビルダーでの解決処理 - include互換性も維持 ## 🚀 json_native実装進化(ChatGPT追加実装) - ✅ **浮動小数点対応追加**: is_float/parse_float実装 - ✅ **配列/オブジェクトパーサー実装**: parse_array/parse_object完成 - ✅ **エスケープ処理強化**: Unicode対応、全制御文字サポート - ✅ **StringUtils大幅拡張**: 文字列操作メソッド多数追加 - contains, index_of_string, split, join等 - 大文字小文字変換(全アルファベット対応) ## 💡 MIR SIMD & ハイブリッド戦略考察 - **MIR15 SIMD命令案**: SimdLoad/SimdScan等の新命令セット - **C ABIハイブリッド**: ホットパスのみC委託で10倍速化可能 - **並行処理でyyjson超え**: 100KB以上で2-10倍速の可能性 - **3層アーキテクチャ**: Nyash層/MIR層/C ABI層の美しい分離 ## 📊 技術的成果 - using構文により名前空間管理が明確化 - json_nativeが実用レベルに接近(完成度25%→40%) - 将来的にyyjsonの70%速度達成可能と判明 ChatGPT爆速実装×Claude深い考察の完璧な協働! 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
2025-09-25 00:41:56 +09:00
print("🏰 Rooms module loaded successfully!")