You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
289 lines
6.6 KiB
289 lines
6.6 KiB
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
using LzFramework.UI;
|
|
using LzFramework;
|
|
using Newtonsoft.Json;
|
|
using EduCoderTool;
|
|
|
|
namespace DisComputer
|
|
{
|
|
/// <summary>
|
|
/// 诺依曼总控制
|
|
/// </summary>
|
|
public class VonNeumannControll : MonoBehaviour
|
|
{
|
|
|
|
public static VonNeumannControll Instance;
|
|
|
|
[SerializeField]
|
|
private CommandUnitSet commandUnitSet;
|
|
|
|
[SerializeField]
|
|
private IRegUnit iregUnit;
|
|
|
|
[SerializeField]
|
|
private PRegUnit pRegUnit;
|
|
|
|
[SerializeField]
|
|
private DecoderUnit decoderUnit;
|
|
|
|
[SerializeField]
|
|
private OperationUnitSet operationUnitSet;
|
|
|
|
[SerializeField]
|
|
private ALUUnit aLUUnit;
|
|
|
|
[SerializeField]
|
|
private RegsUnitSet regsUnitSet;
|
|
|
|
[SerializeField]
|
|
private MEMUnitSet mEMUnitSet;
|
|
|
|
|
|
|
|
public CommandControl commandControl;
|
|
|
|
private void Awake()
|
|
{
|
|
Instance = this;
|
|
}
|
|
|
|
// Start is called before the first frame update
|
|
void Start()
|
|
{
|
|
TTUIPage.ShowPage<TipView>();
|
|
Invoke("Rewind",0.05f);
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
/// 复原结构图
|
|
/// </summary>
|
|
public void Rewind()
|
|
{
|
|
if (!this.gameObject.activeSelf)
|
|
return;
|
|
|
|
commandUnitSet.RewindCommand();
|
|
iregUnit.RewindUnit();
|
|
pRegUnit.RewindUnit();
|
|
decoderUnit.RewindUnit();
|
|
|
|
operationUnitSet.Rewind();
|
|
|
|
aLUUnit.RewindUnit();
|
|
|
|
regsUnitSet.RewinRegsUnitSet();
|
|
|
|
mEMUnitSet.RewindMEMUnitSet();
|
|
|
|
commandControl.progressView.ClearItem();
|
|
|
|
VonNeumann.CommandIndex = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
//移动指令
|
|
public void OnMov3()
|
|
{
|
|
Debug.LogFormat("OnMov3!!!!");
|
|
OnOperation();
|
|
|
|
}
|
|
|
|
//加法
|
|
public void OnAdd()
|
|
{
|
|
Debug.LogFormat("OnAdd!!!!");
|
|
OnOperation();
|
|
|
|
}
|
|
|
|
//减法
|
|
public void OnSub()
|
|
{
|
|
Debug.LogFormat("OnSub!!!!");
|
|
OnOperation();
|
|
}
|
|
|
|
//乘法
|
|
public void OnMul()
|
|
{
|
|
Debug.LogFormat("OnMul!!!!");
|
|
OnOperation();
|
|
}
|
|
|
|
//除法
|
|
public void OnDiv()
|
|
{
|
|
Debug.LogFormat("OnDiv!!!!");
|
|
OnOperation();
|
|
}
|
|
|
|
//终止
|
|
public void OnHalt()
|
|
{
|
|
OnHaltAction();
|
|
}
|
|
|
|
//输入
|
|
public void OnIn()
|
|
{
|
|
|
|
}
|
|
|
|
//输出
|
|
public void OnOut()
|
|
{
|
|
OnOperation();
|
|
}
|
|
|
|
/// <summary>
|
|
/// 运算操作
|
|
/// </summary>
|
|
void OnOperation()
|
|
{
|
|
VonNeumann.isRunning = true;
|
|
|
|
iregUnit.nextUnit = decoderUnit.gameObject;
|
|
iregUnit.pReg_unit = pRegUnit;
|
|
|
|
commandUnitSet.Command(() =>
|
|
{
|
|
if (iregUnit.pReg_unit != null)
|
|
{
|
|
iregUnit.SetInfoTxt(VonNeumann.data.ActName);
|
|
//启动Ireg=> pReg
|
|
iregUnit.ShowArrow(1, false, () =>
|
|
{
|
|
|
|
string tempStr = GetMemoryAdd();
|
|
Debug.LogFormat(">>>>>>>>>>> {0}", tempStr);
|
|
iregUnit.pReg_unit.SetInfoTxt(GetMemoryAdd());
|
|
//启动pReg=> command
|
|
iregUnit.pReg_unit.Active(() =>
|
|
{
|
|
//iReg结束回调
|
|
|
|
iregUnit.ShowArrow(0, false, () =>
|
|
{
|
|
iregUnit.nextUnit.GetComponent<DecoderUnit>().Active();
|
|
});
|
|
}, VonNeumann.CommandIndex+1);
|
|
});
|
|
|
|
}
|
|
});
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// 终止动作
|
|
/// </summary>
|
|
void OnHaltAction()
|
|
{
|
|
VonNeumann.isRunning = true;
|
|
|
|
iregUnit.nextUnit = decoderUnit.gameObject;
|
|
iregUnit.pReg_unit = pRegUnit;
|
|
|
|
commandUnitSet.Command(() =>
|
|
{
|
|
if (iregUnit.pReg_unit != null)
|
|
{
|
|
iregUnit.SetInfoTxt(VonNeumann.data.ActName);
|
|
//启动Ireg=> pReg
|
|
iregUnit.ShowArrow(1, false, () =>
|
|
{
|
|
iregUnit.pReg_unit.SetInfoTxt(GetMemoryAdd());
|
|
|
|
//启动pReg=> command
|
|
iregUnit.pReg_unit.Active(() =>
|
|
{
|
|
//iReg结束回调
|
|
FinishCurStep();
|
|
}, VonNeumann.CommandIndex + 1);
|
|
});
|
|
|
|
}
|
|
});
|
|
|
|
}
|
|
|
|
/// <summary>
|
|
/// 当前步骤完成
|
|
/// </summary>
|
|
public void FinishCurStep()
|
|
{
|
|
VonNeumann.CommandIndex++;
|
|
VonNeumann.isRunning = false;
|
|
if (VonNeumann.CommandIndex >= VonNeumann.data.ActCommandList.Count)
|
|
{
|
|
VonNeumann.isFinish = true;
|
|
|
|
MessageContainer.SendMessage("恭喜闯关成功!!!", this, MsgName.TipVonneumannPoint);
|
|
commandControl.progressView.ClearItem();
|
|
SendSuccessToWeb();
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 发送通关成功
|
|
/// </summary>
|
|
public void SendSuccessToWeb()
|
|
{
|
|
WebData webData = new WebData();
|
|
webData.Data = "";
|
|
webData.GameState = "Success";
|
|
string json = JsonConvert.SerializeObject(webData);
|
|
|
|
WebConnecter.Singleton.SendDataToWeb(json);
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
/// 初始化指令图
|
|
/// </summary>
|
|
public void InitCommandMap()
|
|
{
|
|
|
|
commandUnitSet.ShakeCommands(()=>
|
|
{
|
|
pRegUnit.ShakeUnit();
|
|
pRegUnit.SetInfoTxt("000");
|
|
|
|
pRegUnit.ShowArrow(0, false, () =>
|
|
{
|
|
|
|
commandControl.progressView.InitActItems();
|
|
|
|
|
|
});
|
|
});
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
string GetMemoryAdd()
|
|
{
|
|
int i = VonNeumann.CommandIndex+1;
|
|
|
|
string val = "00" + (i).ToString();
|
|
|
|
return val;
|
|
}
|
|
|
|
|
|
}
|
|
}
|
|
|