临时代码请勿删除

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
/// 
/// 颜色配置
/// 
public static class ColorConfig {
    public static List mColorTemplates = new List();
    static ColorConfig()
    {
        mColorTemplates.Add(Color.red);
        mColorTemplates.Add(Color.black);
        mColorTemplates.Add(Color.blue);
    }
}


using System.Collections;
using System.Collections.Generic;
using UnityEngine;
/// 
/// 图形模板配置 
/// 0 :无填充图形
/// 1 :可填充图形
/// 
public static class TemplateConfig
{
    public static List mTemplates = new List();
    static TemplateConfig() {
        byte[] template1 = new byte[] {
         0,1,0,
         0,1,0,
         0,1,0,
         0,1,0,
         0,1,0
        };

        byte[] template2 = new byte[] {
         0,0,0,
         0,1,0,
         1,1,1,
         0,1,0,
         0,0,0
        };

        byte[] template3 = new byte[] {
         0,1,0,
         0,1,0,
         0,1,1,
         0,0,0,
         0,0,0
        };

        byte[] template4 = new byte[] {
         1,1,0,
         0,1,0,
         0,1,0,
         0,0,0,
         0,0,0
        };

        byte[] template5 = new byte[] {
         1,1,0,
         0,1,0,
         0,1,1,
         0,0,0,
         0,0,0
        };

        mTemplates.Add(template1);
        mTemplates.Add(template2);
        mTemplates.Add(template3);
        mTemplates.Add(template4);
        mTemplates.Add(template5);
    }
}


using System.Collections;
using System.Collections.Generic;
using UnityEngine;

/// 
/// 棋盘
/// 
public class Grid
{
    public const int ROW = 9;
    public const int ROL = 9;
    public Color DefaultColorBg = Color.gray;
    public byte[,] mData = new byte[ROW, ROL];
    /// 
    /// 判断是否为空
    /// 
    /// 
    /// 
    /// 
    public bool IsEmpty(int rRowIdx, int rColIdx) {
        return mData[rRowIdx,rColIdx]==0;
    }
    /// 
    /// 填充对应的格子
    /// 
    /// 
    /// 
    public void Fill(int rRowIdx, int rColIdx) {
        mData[rRowIdx, rColIdx] = 1;
    }

    public void Clear(int rRowIdx, int rColIdx) {
        mData[rRowIdx, rColIdx] = 0;
    }
}


using System.Collections;
using System.Collections.Generic;
using UnityEngine;
/// 
/// 新生成以及持有物数据
/// 
public class GridHolder  {
    //持有物颜色数据
    public Color mColor;
    //持有物数据
    public byte[] mData;
}


using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class ChessLogic  {
    public Grid mGrid;
    public GridHolder mHolder;

    public Action OnRefreshHolder;
    public Action OnClearGrid;
    
    static ChessLogic instance;
    public static ChessLogic Instance()
    {
        if (instance == null)
        {
            instance = new ChessLogic();
        }
        return instance;
    }

    public void GenerateHolder()
    {
        if(mHolder==null) mHolder = new GridHolder();
        int colorIdx = UnityEngine.Random.Range(0, ColorConfig.mColorTemplates.Count);
        int templateIdx = UnityEngine.Random.Range(0, TemplateConfig.mTemplates.Count);
        mHolder.mColor = ColorConfig.mColorTemplates[colorIdx];
        mHolder.mData = TemplateConfig.mTemplates[templateIdx];
        if (OnRefreshHolder != null)
        {
            OnRefreshHolder(mHolder);
        }
    }

    public void Move()
    {

    }

    public bool TryPut()
    {
        GenerateHolder();
        return true;
    }

    public bool CanCheck()
    {
        return false;
    }
}


using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.UI;

public class GridHolderView : MonoBehaviour, IDragHandler, IEndDragHandler, IBeginDragHandler
{
    public Canvas mCanvas;
    public RectTransform mHolderRoot;
    public Image[] mData = new Image[15];

    private Vector3 mDefaultHolderLocalPosition;

    void Awake() {
        mDefaultHolderLocalPosition = mHolderRoot.transform.localPosition;
        ChessLogic.Instance().OnRefreshHolder += (holder) =>
        {
            mHolderRoot.transform.localPosition = mDefaultHolderLocalPosition;
            for (int i = 0; i < holder.mData.Length; i++)
            {
                if (holder.mData[i] != 0)
                {
                    mData[i].enabled = true;
                    mData[i].color = holder.mColor;
                }
                else
                {
                    mData[i].enabled = false;
                }
            }
        };
    }

    public void OnEndDrag(PointerEventData eventData)
    {
        ChessLogic.Instance().TryPut();
    }

    IEnumerator Small()
    {
        int startFrame = Time.frameCount;
        while (Time.frameCount - startFrame < 5)
        {
            mHolderRoot.localScale -= new Vector3(0.1f, 0.1f, 0.1f);
            yield return null;
        }
    }


    void IDragHandler.OnDrag(PointerEventData eventData)
    {
        mHolderRoot.anchoredPosition += new Vector2(eventData.delta.x, eventData.delta.y) / mCanvas.scaleFactor;
    }

    public void OnBeginDrag(PointerEventData eventData)
    {
      
    }
}

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class GridView : MonoBehaviour {

	// Use this for initialization
	void Start () {
		
	}
	
	// Update is called once per frame
	void Update () {
		
	}
}


using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.Experimental.UIElements;

public class Hello : MonoBehaviour{

    void OnGUI() {
        if (Input.GetKeyUp(KeyCode.F1))
        {
            ChessLogic.Instance().GenerateHolder();
        }
    }
}

你可能感兴趣的:(java,开发语言)