查看: 4403|回复: 12

[原创发布] 【2016.09.23】扫雷 1.0

[复制链接]
梦石
0
星屑
1232
在线时间
1017 小时
注册时间
2011-4-30
回帖
1464
发表于 2016-9-23 23:25:11 | 显示全部楼层 |阅读模式

加入我们,或者,欢迎回来。

您需要 登录 才可以下载或查看,没有账号?注册会员

×
本帖最后由 汪汪 于 2016-9-23 23:31 编辑

扫雷
[pre lang="javascript" file="SaoLei.js"]
//=============================================================================
// SaoLei.js
//=============================================================================
/*:
* @plugindesc 扫雷
* @author wangwang
*
* @param ver
* @desc 版本
* @default 1.0
*
* @help
*
* ===================================================
* 初始化
*
* $gameVariables._data[1] = new SaoLei(2,5,5,6)
* 基础事件 2号事件(之后不要有事件)
* 宽 5
* 高 5
* 雷数 6
*
* ===================================================
* 更新
*
* 当结束时返回 true
*
* $gameVariables._data[1].update()
*
* 键盘输入时
*   
* 按 ok 键 翻开雷区
* 按 shift + ok 插拔旗
*
* 触摸输入时
*
* 单击 插拔旗
* 长按 翻开雷区
*
* 插旗只能插指定地雷数的旗
* 当 翻开地雷 或者 除插旗外都翻开时 结束
*
* ===================================================
* 结果
*
* var z = $gameVariables._data[1].gameEval()
* "未标的地雷数" , z[0]
* "标错的旗子数" , z[1]
* "正确的旗子数" , z[2]
*
* ===================================================
* 刷新
*
* 雷区重置
* $gameVariables._data[1].refresh()
*
* ===================================================
*
*  
*/


function SaoLei() {
    this.initialize.apply(this, arguments);

}

//设置创造者
SaoLei.prototype.constructor = SaoLei;

SaoLei.prototype.initialize = function (id, x, y, z) {
    this._x = x
    this._y = y
    this._z = z
    this.make()
    this.setup(id)
    console.log(this.makeSprite2())
};

SaoLei.prototype.gameEval = function () {
    var r = [0, 0, 0]
    for (var i = 0; i < this._leiqu.length; i++) {
        var z0 = (this._leiqu == 9)
        var z1 = (this._xianshi == 2)
        if (z0) {
            if (!z1) {
                //未插旗的地雷
                r[0]++
            } else {
                //正确的旗子
                r[2]++
            }
        } else {
            if (z1) {
                //错误的旗子
                r[1]++
            }
        }
    }
    return r
}


SaoLei.prototype.update = function () {
    if( this.isend() ){
        return  true
    }
    var shift = Input.isPressed('shift')
    var ok = Input.isTriggered('ok')
    if (ok) {
    } else {
        ok = this.updateTouchInput()
        if (ok) {
            shift = true
            if (TouchInput.isLongPressed()) {
                this.updateInput(true, true)
                shift = false
            }
        }
    }
    this.updateInput(ok, shift)
    return  false
}


SaoLei.prototype.updateTouchInput = function () {
    if (TouchInput.isRepeated()) {
        var x = $gameMap.canvasToMapX(TouchInput.x);
        var y = $gameMap.canvasToMapY(TouchInput.y);
        var x0 = x - this._eventx
        var y0 = y - this._eventy
        if (x0 >= 0 && x0 < this._x && y0 >= 0 && y0 <= this._y) {
            $gamePlayer.locate(x, y)
            return true
        }
    }
    return false
}


SaoLei.prototype.updateInput = function (ok, shift) {
    if (ok) {
        var x = $gamePlayer._x
        var y = $gamePlayer._y
        var x0 = x - this._eventx
        var y0 = y - this._eventy
        if (x0 >= 0 && x0 < this._x && y0 >= 0 && y0 <= this._y) {
            var id = y0 * this._x + x0
            if (shift) {
                this.dianji2(id)
            } else {
                this.dianji(id)
            }
        }
    }
}

SaoLei.prototype.refresh = function () {
    this.make()
    var all = this._x * this._y
    for (var i = 0; i < all; i++) {
        this.showleiqu(i, 11)
    }
}

SaoLei.prototype.setup = function (id) {
    this.getevent(id)
    this.makeEvent()
}

SaoLei.prototype.setLeiQu = function (id, num) {
    this._leiqu[id] = num
}
SaoLei.prototype.getLeiQu = function (id) {
    return this._leiqu[id]
}


SaoLei.prototype.setQi = function (id, num) {
    if (num == 0) {
        if (this._xianshi[id]) {
            this._xsshu--
        }
    } else {
        if (!this._xianshi[id]) {
            this._xsshu++
        }
    }
    if (num == 2) {
        if (!this._xianshi[id]) {
            this._qishu++
        }
    } else {
        if (this._xianshi[id] == 2) {
            this._qishu--
        }
    }
    this._xianshi[id] = num
}
SaoLei.prototype.getQu = function (id) {
    return this._xianshi[id]
}


//制作扫雷区
SaoLei.prototype.make = function (x, y, z) {
    var all = this._x * this._y
    var lei = []

    this._qishu = 0
    this._xsshu = 0
    this._leiqu = []
    this._xianshi = []

    for (var i = 0; i < all; i++) {
        this.setLeiQu(i, 0)
        this._xianshi = 0
        lei = i
    }
    for (var i = 0; i < this._z; i++) {
        var lid = Math.floor(lei.length * Math.random())
        var id = lei[lid]
        this._leiqu[id] = 9
        lei.splice(lid, 1)
    }
    for (var i = 0; i < all; i++) {
        this.makenum(i)
    }
};


//安装
SaoLei.prototype.showleiqu = function (id, z) {
    var e = $gameMap.event(id + this._eventId)
    if (e) {
        if (z == 0) {
            var d = 4
            var p = 0

        } else if (z == 1) {
            var d = 4
            var p = 1

        } else if (z == 2) {
            var d = 4
            var p = 2

        } else if (z == 3) {
            var d = 6
            var p = 0

        } else if (z == 4) {
            var d = 6
            var p = 1

        } else if (z == 5) {
            var d = 6
            var p = 2

        } else if (z == 6) {
            var d = 8
            var p = 0

        } else if (z == 7) {
            var d = 8
            var p = 1

        } else if (z == 8) {
            var d = 8
            var p = 2
        } else if (z == 9) {
            var d = 2
            var p = 2
        } else if (z == 10) {
            var d = 2
            var p = 1
        } else if (z == 11) {
            var d = 2
            var p = 0
        }
        e._direction = d
        e._originalPattern = p
    }
};



SaoLei.prototype.getevent = function (id) {
    this._eventId = id
    this._eventx = $gameMap.event(this._eventId)._x
    this._eventy = $gameMap.event(this._eventId)._y
};
//棋子id x
SaoLei.prototype._idx = function (id) {
    return id % this._x
}
//棋子id y
SaoLei.prototype._idy = function (id) {
    return (id - id % this._x) / this._y
}

SaoLei.prototype.makeEvent = function () {
    for (var i = 1; i < this._leiqu.length; i++) {
        var x = this._idx(i)
        var y = this._idy(i)
        SaoLei.copyEvent(this._eventId, i, this._eventx + x, this._eventy + y)
    }
};


SaoLei.prototype.makeSprite = function () {
    var t = ""
    for (var yi = 0; yi < this._y; yi++) {
        t += "\n"
        for (var xi = 0; xi < this._x; xi++) {
            var id = xi + yi * this._x
            t += this._leiqu[id]
        }
    }
    return t
};

SaoLei.prototype.makeSprite2 = function () {
    var t = ""
    for (var yi = 0; yi < this._y; yi++) {
        t += "\n"
        for (var xi = 0; xi < this._x; xi++) {
            var id = xi + yi * this._x
            if (this._xianshi[id] == 1 ) {
                t += this._leiqu[id]
            } else if(this._xianshi[id] == 2 ){
                t += "F"
            }else{
                t += "H"
            }
        }
    }
    return t
};


SaoLei.prototype.makenum = function (id) {
    if (this.getLeiQu(id) === 9) {
        return
    }
    var num = 0
    for (var d = 1; d < 10; d++) {
        var id2 = this.idd(id, d)
        if (this.getLeiQu(id2) === 9) {
            num++
        }
    }
    this.setLeiQu(id, num)
};


SaoLei.prototype.isend = function () {
    return this._xianshi.length == this._xsshu
};

SaoLei.prototype.idd = function (id, d) {
    var x = id % this._x
    var y = (id - x) / this._x
    var dn = [0, [-1, 1], [0, 1], [1, 1], [-1, 0], 0, [1, 0], [-1, -1], [0, -1], [1, -1]]
    var xyd = dn[d] || [0, 0]
    var x2 = x + xyd[0]
    var y2 = y + xyd[1]
    if (x2 < 0 || y2 < 0 || x2 >= this._x || y2 >= this._y) {
        return -1
    }
    return y2 * this._x + x2
};

SaoLei.prototype.dianji2 = function (id) {
    if (!this._xianshi[id]) {
        if (this._qishu < this._z) {
            this.setQi(id, 2)
            this.showleiqu(id, 10)
            console.log(this.makeSprite2())            
        }
    } else if (this._xianshi[id] == 2) {
        this.setQi(id, 0)
        this.showleiqu(id, 11)
        console.log(this.makeSprite2())
    }
};

SaoLei.prototype.dianji = function (id) {
    if (!this._xianshi[id]) {
        if (this.getLeiQu(id) == 9) {
            this.showall(id)
            this.dead(id)
        } else {
            this.show(id)
        }
        console.log(this.makeSprite2())
    }
};

SaoLei.prototype.dead = function (id) {
    var e = $gameMap.event(id + this._eventId)
    e.requestAnimation(1)
};

SaoLei.prototype.showall = function (id) {
    var all = this._x * this._y
    for (var i = 0; i < all; i++) {
        var z = this._xianshi
        this.setQi(i, z || 1)
        var num = this.getLeiQu(i)
        if(num == 9 && z == 2){
            num = 10
        }
        this.showleiqu(i, num)
    }
}

SaoLei.prototype.show = function (id) {
    this.setQi(id, 1)
    var num = this.getLeiQu(id)
    this.showleiqu(id, num)
    if (num == 0) {
        for (var d = 1; d < 10; d++) {
            var id2 = this.idd(id, d)
            if (id2 >= 0 && d != 5 && !this._xianshi[id2]) {
                this.show(id2)
                console.log(id2)
            }
        }
    }
};

//复制fid事件到tid x ,y
SaoLei.copyEvent = function (fid, id, x, y) {
    if (fid > 0 && id > 0) {
        var fid = fid
        var tid = fid + id
        if (DataManager.isMapLoaded()) {
            var event = SaoLei.loadDataEvent(tid)
            if (event) {
                var event = SaoLei.loadGameEvent(tid)
            } else {
                var event = SaoLei._changeNowMapEvent(fid, tid)
            }
            event.locate(x, y)
        }
    }
}

//改变当前地图id事件为 event (csh 是否重设位置)
SaoLei._changeNowMapEvent = function (fid, tid) {
    return SaoLei._addNowMapEvent(fid, tid)
}

//添加当前地图事件
SaoLei._addNowMapEvent = function (fid, tid) {
    $gameMap._events[tid] = new Game_Event($gameMap.mapId(), fid)
    if (SceneManager && SceneManager._scene && SceneManager._scene.constructor == Scene_Map) {
        if (SceneManager._scene._spriteset && SceneManager._scene._spriteset._characterSprites) {
            var spriteset = SceneManager._scene._spriteset
            var characterSprites = SceneManager._scene._spriteset._characterSprites
            var c = new Sprite_Character($gameMap._events[tid])
            characterSprites.push(c)
            spriteset._tilemap.addChild(c);
        }
    }
    return $gameMap._events[tid]
}

//读取当前地图id事件
SaoLei.loadDataEvent = function (id) {
    var event;
    var mapdata = $dataMap
    if (mapdata) {
        var events = mapdata.events
        if (events) {
            var event = events[id]
        }
    }
    return event;
}
SaoLei.loadGameEvent = function (id) {
    var event;
    var mapdata = $gameMap
    if (mapdata) {
        var events = mapdata._events
        if (events) {
            var event = events[id]
        }
    }
    return event;
}[/pre]









Project7.zip (30.25 KB, 下载次数: 157)

不要吐槽人物去哪了....我用的空白
BaiduShurufa_2016-9-23_22-59-39.png

评分

参与人数 1星屑 +58 收起 理由
邪月长啸 + 58 塞糖

查看全部评分

梦石
0
星屑
79
在线时间
112 小时
注册时间
2010-6-16
回帖
70
发表于 2016-9-24 00:21:02 | 显示全部楼层
{:2_258:}{:2_258:}
回复

使用道具 举报

梦石
0
星屑
225
在线时间
162 小时
注册时间
2015-11-23
回帖
90
发表于 2016-9-24 10:49:44 | 显示全部楼层
汪神实力新作,当顶
自天地未辟混沌未开时就已经开始装逼的神奇人物
MV的魔塔模板::托管在github上的游戏,可以直接运行
基于RPGMakerMV的JavaScript基础
回复

使用道具 举报

梦石
0
星屑
22879
在线时间
8598 小时
注册时间
2011-12-31
回帖
3270
发表于 2016-9-24 11:03:27 | 显示全部楼层
本帖最后由 tseyik 于 2016-9-24 13:55 编辑

tomoaky
也有這個
TMPlugin - マインスウィーパ
http://hikimoki.sakura.ne.jp/plugin/plugin_neta.html
2016/08/12
Ver1.0.0 公開
・効果音が未使用ファイル削除ツールに対応していなかった不具合の修正
 これにともない、プラグインパラメータが変更されています。
2016/03/04
Ver0.11b 公開
・ツクールMV1.1.0の未使用ファイル削除ツールに対応
2016/02/05
Ver0.1b 公開

MineSweeper.png
MineSweeper.png
点击展开/收起[pre lang="javascript"]//=============================================================================
// TMPlugin - マインスウィーパ
// バージョン: 1.0.0
// 最終更新日: 2016/08/12
// 配布元    : http://hikimoki.sakura.ne.jp/
//-----------------------------------------------------------------------------
// Copyright (c) 2016 tomoaky
// Released under the MIT license.
// http://opensource.org/licenses/mit-license.php
//=============================================================================

/*:
* @plugindesc 有名な地雷撤去ゲームっぽいものを追加します。
*
* @author tomoaky (http://hikimoki.sakura.ne.jp/)
*
* @param command
* @desc 『選択肢の表示』コマンドで使用するマインスウィーパ起動文字列。
* 初期値: [マインスウィーパ]
* @default [マインスウィーパ]
*
* @param iconImage
* @desc 地雷アイコンとして利用する画像ファイル名。
* 初期値: MineSweeper
* @default MineSweeper
* @require 1
* @dir img/system/
* @type file
*
* @param bombSe
* @desc 地雷爆発時に鳴らす効果音のファイル名。
* 初期値: Explosion2
* @default Explosion2
* @require 1
* @dir audio/se/
* @type file

* @param bombSeParameters
* @desc 地雷爆発時に鳴らす効果音の音量、ピッチ、パン。
* 初期値: 90 100 0
* @default 90 100 0
*
* @param clearSe
* @desc 地雷撤去完了時に鳴らす効果音のファイル名。
* 初期値: Applause1
* @default Applause1
* @require 1
* @dir audio/se/
* @type file

* @param clearSeParameters
* @desc 地雷撤去完了時に鳴らす効果音の音量、ピッチ、パン。
* 初期値: 90 100 0
* @default 90 100 0
*
* @help
* 準備:
*
*   プラグインと一緒に配布しているマインスウィーパのアイコン画像を
*   img/system フォルダに保存してください。
*   ファイル名は MineSweeper.png となっています。
*   ファイル名を変更しなければならない場合はプラグインパラメータの
*   iconImage も一緒に変更してください。
*
*
* 使い方:
*
*   イベントコマンド『選択肢の表示』の選択肢 1 番に [マインスウィーパ] と
*   入力することでマインスウィーパが起動します。(括弧は半角です)
*   選択肢 2 番には以下の 5 つの数値を半角スペースで区切って入力します。
*   ・横に並ぶマスの数
*   ・縦に並ぶマスの数
*   ・マス 1 つの幅(ドット数)
*   ・マス 1 つの高さ(ドット数)
*   ・地雷の数
*   例)14 8 32 32 20
*   この例では 1 つが32*32ドットのマスを横に 14、縦に 8、計 112 個並べ、
*   そのうち 20 個のマスに地雷が隠されている状態でスタートします。
*
*   地雷の埋まっていないマスをすべて調査すれば選択肢 1 番の処理が実行され、
*   途中で地雷のあるマスを調査してしまった場合は 2 番が実行されます。
*
*   選択肢 3 番に半角数字で制限時間を設定することができます。
*   入力した秒数が経過するとマインスウィーパが強制終了し、
*   選択肢 3 番の処理が実行されます。
*
*   このプラグインは RPGツクールMV Version 1.3.0 で動作確認をしています。
*
*
* プラグインコマンド:
*
*   mineTime 1
*     直前のマインスウィーパの所要時間をゲーム変数 1 番に代入します。
*
*     mineTime コマンドで得られる値の単位はミリ秒になっていますので、
*     秒に変換したい場合はイベントコマンド『変数の操作』を使い、この値を
*     1000 で割ってください。
*
*     mineTime で得られる結果は直前に実行されたマインスウィーパのものです。
*     また、マインスウィーパとプラグインコマンド実行までの間に
*     セーブ&ロードをはさむと結果が取得できなくなります。
*
*
* 注意事項:
*
*   『文章の表示』コマンドの直後にマインスウィーパを起動した場合、
*   メッセージウィンドウが閉じずにそのままマインスウィーパが起動します。
*   メッセージウィンドウを閉じてからマインスウィーパを起動したい場合は
*   『文章の表示』と『選択肢の表示』の間に『ウェイト』を 1 フレーム以上
*   入れてください。
*
*   また、マインスウィーパウィンドウの上下位置はメッセージウィンドウの
*   上下位置に影響を受けるので、背景が透明で内容が空のメッセージウィンドウを
*   使えばマインスウィーパウィンドウの上下位置を変更することができます。
*/

var Imported = Imported || {};
Imported.TMMineSweeper = true;

var TMPlugin = TMPlugin || {};
TMPlugin.MineSweeper = {};
TMPlugin.MineSweeper.Parameters = PluginManager.parameters('TMMineSweeper');
TMPlugin.MineSweeper.Command = TMPlugin.MineSweeper.Parameters['command'] || '[マインスウィーパ]';
TMPlugin.MineSweeper.IconImage = TMPlugin.MineSweeper.Parameters['iconImage'];
var arr = TMPlugin.MineSweeper.Parameters['bombSeParameters'].split(' ');
TMPlugin.MineSweeper.BombSe = { name: TMPlugin.MineSweeper.Parameters['bombSe'],
                                volume: arr[0], pitch: arr[1], pan: arr[2] };
var arr = TMPlugin.MineSweeper.Parameters['clearSeParameters'].split(' ');
TMPlugin.MineSweeper.ClearSe = { name: TMPlugin.MineSweeper.Parameters['clearSe'],
                                volume: arr[0], pitch: arr[1], pan: arr[2] };

(function() {

  //-----------------------------------------------------------------------------
  // Game_Temp
  //

  var _Game_Temp_initialize = Game_Temp.prototype.initialize;
  Game_Temp.prototype.initialize = function() {
    _Game_Temp_initialize.call(this);
    this._mineTime = 0;
  };

  Game_Temp.prototype.setMineScore = function(time) {
    this._mineTime = time;
  };
  
  Game_Temp.prototype.mineTime = function() {
    return this._mineTime;
  };
  
  //-----------------------------------------------------------------------------
  // Game_Message
  //

  var _Game_Message_clear = Game_Message.prototype.clear;
  Game_Message.prototype.clear = function() {
    _Game_Message_clear.call(this);
    this._mineWidth      = 0;
    this._mineHeight     = 0;
    this._mineCellWidth  = 0;
    this._mineCellHeight = 0;
    this._mineTimeLimit  = 0;
    this._mineNumber     = 0;
  };

  Game_Message.prototype.mineWidth = function() {
    return this._mineWidth;
  };

  Game_Message.prototype.mineHeight = function() {
    return this._mineHeight;
  };

  Game_Message.prototype.mineCellWidth = function() {
    return this._mineCellWidth;
  };

  Game_Message.prototype.mineCellHeight = function() {
    return this._mineCellHeight;
  };

  Game_Message.prototype.mineNumber = function() {
    return this._mineNumber;
  };

  Game_Message.prototype.setMine = function(choices, cancelType) {
    var arr = choices[1].split(' ');
    this._mineWidth      = +arr[0];
    this._mineHeight     = +arr[1];
    this._mineCellWidth  = +arr[2];
    this._mineCellHeight = +arr[3];
    this._mineNumber     = +arr[4];
    this._mineTimeLimit  = choices[2] ? +choices[2] * 1000 : 0;
    this._choiceCancelType = cancelType;
  };

  Game_Message.prototype.isMineSweeper = function() {
    return this._mineWidth > 0;
  };

  var _Game_Message_isBusy = Game_Message.prototype.isBusy;
  Game_Message.prototype.isBusy = function() {
    return _Game_Message_isBusy.call(this) || this.isMineSweeper();
  };

  //-----------------------------------------------------------------------------
  // Game_Interpreter
  //

  var _Game_Interpreter_setupChoices = Game_Interpreter.prototype.setupChoices;
  Game_Interpreter.prototype.setupChoices = function(params) {
    var choices = params[0].clone();
    if (choices[0] === TMPlugin.MineSweeper.Command) {
      var cancelType = params[1];
      var defaultType = params.length > 2 ? params[2] : 0;
      var positionType = params.length > 3 ? params[3] : 2;
      var background = params.length > 4 ? params[4] : 0;
      if (cancelType >= choices.length) cancelType = -2;
      $gameMessage.setMine(choices, cancelType);
      $gameMessage.setChoiceBackground(background);
      $gameMessage.setChoicePositionType(positionType);
      $gameMessage.setChoiceCallback(function(n) {
        this._branch[this._indent] = n;
      }.bind(this));
    } else {
      _Game_Interpreter_setupChoices.call(this, params);
    }
  };

  var _Game_Interpreter_pluginCommand = Game_Interpreter.prototype.pluginCommand;
  Game_Interpreter.prototype.pluginCommand = function(command, args) {
    _Game_Interpreter_pluginCommand.call(this, command, args);
    if (command === 'mineTime') {
      $gameVariables.setValue(+args[0], $gameTemp.mineTime());
    }
  };
  
  //-----------------------------------------------------------------------------
  // Window_MineSweeper
  //

  function Window_MineSweeper() {
      this.initialize.apply(this, arguments);
  }

  Window_MineSweeper.prototype = Object.create(Window_Selectable.prototype);
  Window_MineSweeper.prototype.constructor = Window_MineSweeper;

  Window_MineSweeper.prototype.initialize = function(messageWindow) {
    this._messageWindow = messageWindow;
    Window_Selectable.prototype.initialize.call(this, 0, 0, 0, 0);
    this.openness = 0;
    this.deactivate();
  };
  
  Window_MineSweeper.prototype.maxCols = function() {
    return this._mineWidth || 1;
  };

  Window_MineSweeper.prototype.maxItems = function() {
    return this._mineCellNumber || 0;
  };

  Window_MineSweeper.prototype.spacing = function() {
    return 0;
  };

  Window_MineSweeper.prototype.isCursorMovable = function() {
    return Window_Selectable.prototype.isCursorMovable &&
           this._mineState === -1;
  };

  Window_MineSweeper.prototype.start = function() {
    this._mineWidth      = $gameMessage.mineWidth();
    this._mineHeight     = $gameMessage.mineHeight();
    this._mineCellWidth  = $gameMessage.mineCellWidth();
    this._mineCellHeight = $gameMessage.mineCellHeight();
    this._mineNumber     = $gameMessage.mineNumber();
    this._mineCellNumber = this._mineWidth * this._mineHeight;
    this.clearMine();
    this._mineState = -1;
    this._mineStartTime = new Date();
    this._lastRefreshTime = this._mineStartTime;
    this._sweepCount = 0;
    this.updatePlacement();
    this.updateBackground();
    this.select(0);
    this.refresh();
    this.open();
    this.activate();
  };

  Window_MineSweeper.prototype.clearMine = function() {
    this._mineMap = [];
    for (var i = 0; i < this._mineCellNumber; i++) {
      this._mineMap = { value: 0, mine: 0, flag: false, sweeped: false };
    }
  };
  
  Window_MineSweeper.prototype.setupMine = function() {
    var a = [];
    for (var i = 0; i < this._mineCellNumber; i++) {
      a = i;
    }
    for (var i = -1; i < 2; i++) {
      if ((i >= 0 || this.index() % this._mineWidth > 0) &&
          (i < 1 || this.index() % this._mineWidth < this._mineWidth - 1)) {
        for (var j = -1; j < 2; j++) {
          var index = this.index() + i + this._mineWidth * j;
          if (this.isIndexValid(index)) a.splice(a.indexOf(index), 1);
        }
      }
    }
    for (var i = 0; i < this._mineNumber; i++) {
      var index = a.splice(Math.randomInt(a.length), 1)[0];
      this._mineMap[index].mine = 1;
      for (var j = -1; j < 2; j++) {
        this.increaseMineCount(index + this._mineWidth * j);
        if (index % this._mineWidth > 0) {
          this.increaseMineCount(index - 1 + this._mineWidth * j);
        }
        if (index % this._mineWidth < this._mineWidth - 1) {
          this.increaseMineCount(index + 1 + this._mineWidth * j);
        }
      }
    }
  };
  
  Window_MineSweeper.prototype.increaseMineCount = function(index) {
    if (this.isIndexValid(index)) this._mineMap[index].value++;
  };
  
  Window_MineSweeper.prototype.isIndexValid = function(index) {
    return index >= 0 && index < this._mineCellNumber;
  };
  
  Window_MineSweeper.prototype.updatePlacement = function() {
    var positionType = $gameMessage.choicePositionType();
    var messageY = this._messageWindow.y;
    this.width = this.windowWidth();
    this.height = this.windowHeight();
    if (positionType === 0) {
      this.x = 0;
    } else if (positionType === 1) {
      this.x = (Graphics.boxWidth - this.width) / 2;
    } else {
      this.x = Graphics.boxWidth - this.width;
    }
    if (messageY >= Graphics.boxHeight / 2) {
      this.y = messageY - this.height;
    } else {
      this.y = messageY + this._messageWindow.height;
    }
  };

  Window_MineSweeper.prototype.updateBackground = function() {
    this._background = $gameMessage.choiceBackground();
    this.setBackgroundType(this._background);
  };

  Window_MineSweeper.prototype.windowWidth = function() {
    var width = $gameMessage.mineWidth() * $gameMessage.mineCellWidth() +
                this.padding * 2;
    return Math.min(width, Graphics.boxWidth);
  };

  Window_MineSweeper.prototype.windowHeight = function() {
    return this.fittingHeight($gameMessage.mineHeight()) + 36;
  };

  Window_MineSweeper.prototype.update = function() {
    var lastIndex = this.index();
    Window_Selectable.prototype.update.call(this);
    if (this.active) {
      if (this._mineState === -1) {
        this.updateTime();
      } else if (Input.isTriggered('ok') || (TouchInput.isTriggered())) {
        $gameMessage.onChoice(this._mineState);
        this.endMineSweeper();
        SoundManager.playOk();
      } else if (Input.isTriggered('escape') || (TouchInput.isCancelled())) {
        $gameMessage.onChoice(this._mineState);
        this.endMineSweeper();
        SoundManager.playCancel();
      }
      if (lastIndex !== this.index()) {
        this.redrawItem(lastIndex);
        this.redrawItem(this.index());
      }
    }
  };
  
  Window_MineSweeper.prototype.updateTime = function() {
    var currentTime = new Date();
    if (currentTime - this._lastRefreshTime > 1000) {
      this.refreshTime();
      this._lastRefreshTime = currentTime;
    }
  };
  
  Window_MineSweeper.prototype.gameOver = function(state) {
    this._mineState = state;
    var time = new Date();
    $gameTemp.setMineScore(time - this._mineStartTime);
    if (this._mineState >= 1) {
      for (var i = 0; i < this._mineCellNumber; i++) {
        var data = this._mineMap;
        if (data.mine && !data.sweeped) {
          this._mineMap.sweeped = true;
          this.redrawItem(i);
        }
      }
      AudioManager.playSe(TMPlugin.MineSweeper.BombSe);
    } else {
      AudioManager.playSe(TMPlugin.MineSweeper.ClearSe);
    }
  };
  
  Window_MineSweeper.prototype.endMineSweeper = function() {
    this._messageWindow.terminateMessage();
    this.deactivate();
    this.close();
  };
  
  Window_MineSweeper.prototype.drawItem = function(index) {
    var rect = this.itemRect(index);
    var bitmap = ImageManager.loadSystem('MineSweeper');
    var data = this._mineMap[index];
    var sx = 12;
    if (data.sweeped) {
      sx = data.mine ? 8 + data.mine : data.value;
    }
    this.contents.blt(bitmap, sx * 32, 0, 32, 32, rect.x, rect.y,
                      rect.width, rect.height);
    if (data.flag) {
      this.contents.blt(bitmap, 416, 0, 32, 32, rect.x, rect.y,
                        rect.width, rect.height);
    }
    if (index === this.index()) {
      this.contents.blt(bitmap, 448, 0, 32, 32, rect.x, rect.y,
                        rect.width, rect.height);
    }
  };

  Window_MineSweeper.prototype.refresh = function() {
    this.createContents();
    this.drawAllItems();
    this.refreshTime();
  };

  Window_MineSweeper.prototype.refreshTime = function() {
    var time = new Date();
    time -= this._mineStartTime;
    if ($gameMessage._mineTimeLimit) {
      time = $gameMessage._mineTimeLimit - time;
      if (time < 0) {
        time = 0;
        this.gameOver(2);
      }
    }
    var width = this.contents.width - this.textPadding();
    var height = 36;
    var y = this.contents.height - height;
    this.contents.clearRect(0, y, width, height);
    this.drawText(Math.floor(time / 1000) + ' 秒', 0, y, width, 'right');
  };
  
  Window_MineSweeper.prototype.isCurrentItemEnabled = function() {
    return this.index() >= 0 && !this._mineMap[this.index()].sweeped;
  };

  Window_MineSweeper.prototype.isOkEnabled = function() {
    return true;
  };

  Window_MineSweeper.prototype.isCancelEnabled = function() {
    return true;
  };

  Window_MineSweeper.prototype.processOk = function() {
    if (this._mineState === -1) {
      Window_Selectable.prototype.processOk.call(this);
    }
  };

  Window_MineSweeper.prototype.callOkHandler = function() {
    if (this._sweepCount === 0) this.setupMine();
    this._mineSweepTargets = [this.index()];
    while (this._mineSweepTargets.length > 0) {
      this.sweep(this._mineSweepTargets.pop());
    }
    if (this._mineState === -1) this.checkGameComplete();
    this.activate();
  };

  Window_MineSweeper.prototype.sweep = function(index) {
    var data = this._mineMap[index];
    if (data.mine) {
      this.gameOver(1);
      this._mineMap[index].mine = 2;
    }
    this._mineMap[index].sweeped = true;
    this._mineMap[index].flag = false;
    this._sweepCount++;
    this.redrawItem(index);
    if (data.value > 0) return;
    this.addSweepTarget(index - this._mineWidth);
    this.addSweepTarget(index + this._mineWidth);
    for (var i = -1; i < 2; i++) {
      if (index % this._mineWidth > 0) {
        this.addSweepTarget(index - 1 + this._mineWidth * i);
      }
      if (index % this._mineWidth < this._mineWidth - 1) {
        this.addSweepTarget(index + 1 + this._mineWidth * i);
      }
    }
  };
  
  Window_MineSweeper.prototype.addSweepTarget = function(index) {
    if (index >= 0 && index < this._mineCellNumber &&
        this._mineSweepTargets.indexOf(index) === -1 &&
        !this._mineMap[index].sweeped) {
      this._mineSweepTargets.push(index);
    }
  };
  
  Window_MineSweeper.prototype.checkGameComplete = function(index) {
    if (this._sweepCount === this._mineCellNumber - this._mineNumber) {
      this.gameOver(0);
    }
  };
  
  Window_MineSweeper.prototype.processCancel = function() {
    if (this._mineState === -1) {
      Window_Selectable.prototype.processCancel.call(this);
    }
  };

  Window_MineSweeper.prototype.callCancelHandler = function() {
    if (this.index() >= 0 && !this._mineMap[this.index()].sweeped) {
      this._mineMap[this.index()].flag = !this._mineMap[this.index()].flag;
      this.redrawItem(this.index());
    } else {
      SoundManager.playBuzzer();
    }
    this.activate();
  };
  //-----------------------------------------------------------------------------
  // Window_Message
  //

  var _Window_Message_subWindows = Window_Message.prototype.subWindows;
  Window_Message.prototype.subWindows = function() {
    return _Window_Message_subWindows.call(this).concat(this._mineSweeperWindow);
  };

  var _Window_Message_createSubWindows = Window_Message.prototype.createSubWindows;
  Window_Message.prototype.createSubWindows = function() {
    _Window_Message_createSubWindows.call(this);
    this._mineSweeperWindow = new Window_MineSweeper(this);
  };

  var _Window_Message_isAnySubWindowActive = Window_Message.prototype.isAnySubWindowActive;
  Window_Message.prototype.isAnySubWindowActive = function() {
    return (_Window_Message_isAnySubWindowActive.call(this) ||
            this._mineSweeperWindow.active);
  };

  var _Window_Message_startInput = Window_Message.prototype.startInput;
  Window_Message.prototype.startInput = function() {
    if ($gameMessage.isMineSweeper()) {
      this._mineSweeperWindow.start();
      return true;
    }
    return _Window_Message_startInput.call(this);
  };

  //-----------------------------------------------------------------------------
  // Scene_Boot
  //

  var _Scene_Boot_loadSystemImages = Scene_Boot.loadSystemImages;
  Scene_Boot.loadSystemImages = function() {
    _Scene_Boot_loadSystemImages.call(this);
    ImageManager.loadSystem(TMPlugin.MineSweeper.IconImage);
  };

})();
[/pre]

点评

链接也点不进去。。  发表于 2016-9-24 13:50
看不懂日文。。。  发表于 2016-9-24 13:47
回复

使用道具 举报

梦石
0
星屑
462
在线时间
871 小时
注册时间
2014-5-5
回帖
914
发表于 2016-9-24 13:14:02 | 显示全部楼层
弱弱的问句,这有啥用?貌似现在没几个会玩扫雷把?

点评

我没有别的意思,只觉得PC都自带的游戏,移植到MV意义不大,纯属个人见解,勿怪  发表于 2016-9-24 21:57
可以作为小游戏 加到游戏里 你可以改下素材 比如扫翔  发表于 2016-9-24 19:39
楼上可以证明别人也有写。  发表于 2016-9-24 13:49
回复

使用道具 举报

梦石
0
星屑
245
在线时间
219 小时
注册时间
2015-9-24
回帖
138
发表于 2016-9-29 21:27:32 | 显示全部楼层
做过纯事件版本····虽然支持任意多行···不过要提前放置好事件

点评

好厉害(づ ●─● )づ  发表于 2016-9-30 07:06
回复

使用道具 举报

梦石
0
星屑
230
在线时间
174 小时
注册时间
2016-2-24
回帖
83
发表于 2016-10-1 03:44:03 | 显示全部楼层
素材不是扫向差评
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册会员

本版积分规则

Powered by Discuz! X5.0 © 2001-2026 Discuz! Team.

在本版发帖返回顶部