zoukankan      html  css  js  c++  java
  • 一个拳王小游戏

    1.想实现一个拳王的小游戏 

    2.看了下代码 分成map.js(实现地图) timer.js(实现一个定时器 ) class.js(实现类的概念 

    var Class = function(){
    var cache = {};//缓存对象
    var create = function( fn, methods, parent ){
    var _initialize, _instances = [], instance, _unique = 0;
    _initialize = function( args ){
    fn.apply( this, args );

    //下方实例化函数的时候调用这个方法 

    }
    if ( parent ){
    _initialize.prototype = parent;

    //有par参数 
    }
    for ( var i in methods ){

    // 遍历全部方法 赋值给原型对象
    _initialize.prototype[ i ] = methods[ i ];
    }
    //xthis.animate = this.implement( 'Animate' );

    _initialize.prototype.implement = function(){

    //实现的方法
    var fns = arguments[0].split('.'),

    //第一个参数 用.来分割
    args = Array.prototype.slice.call( arguments, 1 ), fn = this;

    //获取全部参数
    for ( var i = 0, c; c = fns[i++]; ){

    //
    fn = fn[ c ];
    if ( !fn ){
    return alert ('接口尚未实现');
    }

    }
    return fn.apply( this, args );


    }
    ///获取实例
    var getInstance = function(){

    var args = Array.prototype.slice.call( arguments, 0 );
    _instances[ _unique++ ] = new _initialize( args );
    return _instances[ _unique - 1 ];

    //返回实例
    }

    var empty = function(){

    // 清空方法 
    for ( var i = 0, c; c = _instances[i++]; ){
    c = null;
    }
    _instances = [];
    _instances.length = 0;
    _unique = 0;
    }

    var getCount = function(){
    return _unique;
    }

    var getPrototype = function(){
    return _initialize.prototype;
    }

    var subClass = function( fn, methods ){
    var a = Class.create( fn, methods, _instances[0] || getInstance() );
    return a
    }

    var interface = function( key, fn ){
    _initialize.prototype[ key ] = fn;
    if ( _initialize ){
    }
    }

    return {
    interface: interface,
    getInstance: getInstance,
    empty: empty,
    getCount: getCount,
    getPrototype: getPrototype,
    subClass: subClass,
    }

    }

    return {
    create: create,
    getInstances: function(){
    return _instances;
    }
    }


    }()

    2. timer.js

  • 相关阅读:
    BZOJ2286 [Sdoi2011]消耗战 【虚树 + 树形Dp】
    BZOJ1305 [CQOI2009]dance跳舞 【网络流】
    BZOJ1452 [JSOI2009]Count 【树套树 (树状数组)】
    BZOJ1103 [POI2007]大都市meg 【树剖】
    BZOJ1927 [Sdoi2010]星际竞速 【费用流】
    POJ3450 Corporate Identity 【后缀数组】
    POJ3623 Best Cow Line, Gold 【后缀数组】
    POJ3415 Common Substrings 【后缀数组 + 单调栈】
    关于线上bug
    关于线上bug
  • 原文地址:https://www.cnblogs.com/esZhang/p/5296207.html
Copyright © 2011-2022 走看看