//define(function () {

    

    "use strict";

    

    var Simular;

    

    (function () {

        

        var action = {

            

            battle : function(obj,callback) {

                

                var _actor = obj.actor;

                //var _env = obj.env;

                //var _type = obj.type;

                var _period = obj.period;

                var result = {

                    

                    winner : undefined

                    

                };

                

                var _a1 = obj.actor[0];

                var _a2 = obj.actor[1];

                    

                _a1.sp = weapons[_a1.weapon].strength / weapons[_a1.weapon].time;

                _a2.sp = weapons[_a2.weapon].strength / weapons[_a2.weapon].time;


                for(var i = 0; i < _period; ++i) {

                

                    _a1.health -=  _a2.sp;

                    

                    if (_a1.health <= 0) {break;}

                    

                    _a2.health -= _a1.sp;

                    

                    if (_a2.health <= 0) {break;}

                        

                }

                

                //console.log("_a1.health is " + _a1.health);

                //console.log("_a2.health is " + _a2.health);

                

                if (_a1.health <= 0) {

                    

                    result.winner = _a2;

                    

                } else {

                    

                    result.winner = _a1;

                    

                }


                callback(result);

                

            }

        

        };

     

        var weapons = {

     

            'dagger' : {

                weight : 1, //kg

                length : 50, //cm

                strength : 50,

                time : 1

            },

            'sword' : {

                weight : 5,

                length : 100,

                strength : 150,

                time : 2

            },

            'axe' : {

                weight : 10,

                length : 80,

                strength : 250,

                time : 3

            },

            'spear' : {

                weight : 8,

                length : 120,

                strength : 210,

                time : 3

            },

            'bow' : {

                weight : 4,

                length : 70,

                strength : 300,

                time : 5

            }

     

        };

     

        Simular = {

            action : action

        };

    

    }());

    


    var usr1 = {

        name : 'user1',

        sex : 'man',

        weapon : 'sword',

        health : 120

    };


    var usr2 = {

        name : 'user2',

        sex : 'man',

        weapon : 'dagger',

        health : 170

    };


    Simular.action.battle({

        actor : [usr1, usr2],

        env : "ground",

        type : "hand_to_hand",

        period : 5

    },function(result) {

        console.log("the winner is " + result.winner.name );

    });


//});



우선 시범용으로 간단히 짯는데, 제대로 된 게임수준으로 짤려면 험난해 보인다..