628628 gameState . player . gold += goldGain ;
629629 addLogEntry ( `[系统] 你击败了${ gameState . enemy . name } ,获得了${ goldGain } 金币!` ) ;
630630
631- // 生成
631+ // 生成新敌人
632+ setTimeout ( ( ) => {
633+ const enemies = [
634+ { name : "巨型蜘蛛" , hp : 75 , attack : 14 , defense : 6 , emoji : "🕷️" } ,
635+ { name : "骷髅战士" , hp : 90 , attack : 16 , defense : 8 , emoji : "💀" } ,
636+ { name : "石像鬼" , hp : 110 , attack : 18 , defense : 12 , emoji : "🗿" } ,
637+ { name : "火焰元素" , hp : 65 , attack : 22 , defense : 5 , emoji : "🔥" }
638+ ] ;
639+
640+ gameState . enemy = enemies [ Math . floor ( Math . random ( ) * enemies . length ) ] ;
641+ addLogEntry ( `[系统] 一只${ gameState . enemy . name } 出现在你面前!` ) ;
642+ updateUI ( ) ;
643+ } , 1500 ) ;
644+ } else {
645+ const damage = Math . max ( 1 , gameState . enemy . attack - Math . floor ( gameState . player . defense / 2 ) ) ;
646+ gameState . player . hp -= damage ;
647+ addLogEntry ( `[敌人] ${ gameState . enemy . name } 对你造成了${ damage } 点伤害!` ) ;
648+
649+ if ( gameState . player . hp <= 0 ) {
650+ gameState . player . hp = 0 ;
651+ addLogEntry ( `[系统] 你被${ gameState . enemy . name } 击败了!` ) ;
652+ setTimeout ( ( ) => {
653+ document . getElementById ( 'victory-message' ) . style . display = 'block' ;
654+ } , 2000 ) ;
655+ }
656+ }
657+
658+ updateUI ( ) ;
659+ }
660+
661+ function rest ( ) {
662+ const hpRecovered = Math . min ( 30 , gameState . player . maxHp - gameState . player . hp ) ;
663+ gameState . player . hp += hpRecovered ;
664+ addLogEntry ( `[你] 休息了一会儿,恢复了${ hpRecovered } 点生命值。` ) ;
665+ updateUI ( ) ;
666+ }
667+
668+ // 初始化事件监听器
669+ document . querySelectorAll ( '.action-btn' ) . forEach ( ( btn , index ) => {
670+ btn . addEventListener ( 'click' , ( ) => {
671+ switch ( index ) {
672+ case 0 : explore ( ) ; break ;
673+ case 1 : visitShop ( ) ; break ;
674+ case 2 : startBattle ( ) ; break ;
675+ case 3 : rest ( ) ; break ;
676+ default :
677+ addLogEntry ( `[系统] 此功能尚未实现。` ) ;
678+ }
679+ } ) ;
680+ } ) ;
681+
682+ // 地图点击事件
683+ document . querySelectorAll ( '.map-cell' ) . forEach ( ( cell , index ) => {
684+ cell . addEventListener ( 'click' , ( ) => {
685+ if ( index !== gameState . currentLocationIndex ) {
686+ gameState . currentLocationIndex = index ;
687+ gameState . player . location = gameState . locations [ index ] ;
688+ addLogEntry ( `[你] 旅行到了${ gameState . player . location } ` ) ;
689+ updateUI ( ) ;
690+ }
691+ } ) ;
692+ } ) ;
693+
694+ // 胜利消息重启按钮
695+ document . querySelector ( '.restart-btn' ) . addEventListener ( 'click' , ( ) => {
696+ document . getElementById ( 'victory-message' ) . style . display = 'none' ;
697+ gameState . player . hp = gameState . player . maxHp ;
698+ gameState . enemy . hp = gameState . enemy . maxHp ;
699+ gameState . logEntries = [
700+ "[系统] 新的冒险开始了!" ,
701+ `[你] 到达了${ gameState . player . location } `
702+ ] ;
703+ updateUI ( ) ;
704+ } ) ;
705+
706+ // 初始化游戏
707+ updateUI ( ) ;
708+
709+ // 添加一些初始日志
710+ setTimeout ( ( ) => {
711+ addLogEntry ( "[系统] 提示:点击地图上的不同位置可以快速旅行。" ) ;
712+ } , 3000 ) ;
713+
714+ setTimeout ( ( ) => {
715+ addLogEntry ( "[系统] 提示:使用'休息'按钮可以恢复生命值。" ) ;
716+ } , 7000 ) ;
717+ </ script >
718+ </ body >
719+ </ html >
0 commit comments