void SetNeighbors() { for (int i = 0; i < GridSize.x; i++) { for (int j = 0; j < GridSize.y; j++) { Transform tempCell = Grid[i, j]; CellLogic tempScript = tempCell.GetComponent <CellLogic>(); if (i != 0) { tempScript.Neighbors.Add(Grid[i - 1, j]); } if (j != 0) { tempScript.Neighbors.Add(Grid[i, j - 1]); } if (i != GridSize.x - 1) { tempScript.Neighbors.Add(Grid[i + 1, j]); } if (j != GridSize.y - 1) { tempScript.Neighbors.Add(Grid[i, j + 1]); } } } }
// Use this for initialization void Start () { scored = false; cells = new CellLogic[HEIGHT][]; for(int i = 0; i < HEIGHT; i++) cells[i] = new CellLogic[WIDTH]; // Initializing cells for(int r = 0; r < HEIGHT; r++) for(int c = 0; c < WIDTH; c++) { cells[r][c] = new CellLogic(r, c); GameObject go = Instantiate(cell); go.transform.parent = this.transform; cells[r][c].SetCellView(go.GetComponent<CellView>(), 1); } // Filling siblings up for(int r = 0; r < HEIGHT; r++) for(int c = 0; c < WIDTH; c++) { if(r > 1) cells[r][c].up = cells[r-1][c]; if(r < HEIGHT-1) cells[r][c].dn = cells[r+1][c]; if(c > 1) cells[r][c].lf = cells[r][c-1]; if(c < WIDTH-1) cells[r][c].rt = cells[r][c+1]; } }
void Start() { cell = GetComponent <CellLogic>(); FinanceRise.SetActive(false); SocialRise.SetActive(false); EnvironmentRise.SetActive(false); FinanceRiseText.text = ""; SocialRiseText.text = ""; EnvironmentRiseText.text = ""; }
public void Iterate() { CellLogic[,] newCellBoard = new CellLogic[getWidth (), getHeight()]; for(int i = 0; i < getWidth(); i ++) { for(int j = 0; j < getHeight(); j ++ ) { newCellBoard[i,j] = cells[i,j].checkForNeighbors(NeighborsOnAt(i,j)); } } cells = newCellBoard; }
public void shouldBeAbleToAddACellLogic() { FieldLogic underTest = new FieldLogic(5, 5); CellLogic cell = new CellLogic(null, null, false); underTest.AddCellAt(cell, 4, 4); UUnitAssert.Equals(5, underTest.getWidth()); UUnitAssert.Equals(5, underTest.getHeight()); UUnitAssert.Equals(cell, underTest.CellAt(4, 4)); }
public void shouldBeAbleToAddACellLogic() { FieldLogic underTest = new FieldLogic(5,5); CellLogic cell = new CellLogic(null, null, false); underTest.AddCellAt(cell, 4,4); UUnitAssert.Equals(5, underTest.getWidth()); UUnitAssert.Equals(5, underTest.getHeight()); UUnitAssert.Equals(cell, underTest.CellAt(4,4)); }
public void TestTurnOnForThreeNeighboorsWhenOff() { Boolean turnOnCalled = false; CellLogic.TurnOn turnOn = (() => {turnOnCalled = true;}); CellLogic underTest = new CellLogic(turnOn, null, false); underTest.checkForNeighbors(3); UUnitAssert.True(turnOnCalled); }
public void TestTurnOffForOneNeighboor() { Boolean turnOffCalled = false; CellLogic.TurnOff turnOff = (() => {turnOffCalled = true;}); CellLogic underTest = new CellLogic(null, turnOff, false); underTest.checkForNeighbors(1); UUnitAssert.True(turnOffCalled); }
public void Iterate() { CellLogic[,] newCellBoard = new CellLogic[getWidth(), getHeight()]; for (int i = 0; i < getWidth(); i++) { for (int j = 0; j < getHeight(); j++) { newCellBoard[i, j] = cells[i, j].checkForNeighbors(NeighborsOnAt(i, j)); } } cells = newCellBoard; }
public void TestTurnOffFor2NeighborsWhenNotAlreadyOn() { Boolean turnOffCalled = false; CellLogic.TurnOff turnOff = (() => { turnOffCalled = true; }); CellLogic underTest = new CellLogic(null, turnOff, false); underTest.checkForNeighbors(2); UUnitAssert.True(turnOffCalled); }
public void TestTurnOnForNeighboorsWhenAlreadyOn() { Boolean turnOnCalled = false; CellLogic.TurnOn turnOn = (() => { turnOnCalled = true; }); CellLogic underTest = new CellLogic(turnOn, null, true); underTest.checkForNeighbors(2); UUnitAssert.True(turnOnCalled); }
public PieceLogic() { // initialing array of cells // we pre aloc memory for 3x3, // because is the max size of a piece. cells = new CellLogic[3][]; for(int r = 0; r < 3; r++) { cells[r] = new CellLogic[3]; for(int c = 0; c < 3; c++) cells[r][c] = new CellLogic(r,c); } ResetPosition(); }
void OnEnable() { agent.speed = Utilities.RandomFloat(10, 20); canMove = true; nextPoint = Utilities.RandomInt(0, Waypoints.Count); nextWaypoint = Waypoints[nextPoint]; agent.SetDestination(nextWaypoint); Cell = CellGrid.Instance.GetRandomCell(); CellLogic = Cell.GetComponent <CellLogic>(); if (representation != null) { representation.GetComponentInChildren <Animator>().SetBool("walk", false); representation.GetComponentInChildren <Animator>().SetBool("wave", false); representation.GetComponentInChildren <Animator>().SetBool("walk", true); } }
//waiting for both InventoryItem stop dragging and internal void LateUpdate() { if (isCurrentDropFrame) { if (dropCell) { DropToCellLogic(); } else { MoveItemBack(); } } isCurrentDropFrame = false; dropCell = null; }
//private void Update() { //} public void Indicate(CellLogic logic) { if (IndicatedInfo == CellIndication.Nothing) { IndicatedText = ""; TextIndicator.enabled = false; return; } else { TextIndicator.enabled = true; } if (IndicatedInfo == CellIndication.CellName) { IndicatedText = logic.gameObject.name; } else if (logic.Data == null) { Debug.LogError("Can't indicate Data because it's null", this); } else if (IndicatedInfo == CellIndication.EnergyMax) { IndicatedText = logic.Data.CellStateFormT.EnergyMaxStored.ToString("G3"); } else if (IndicatedInfo == CellIndication.EnergyCurrent) { IndicatedText = logic.Data.EnergyCurrent.ToString("G3"); } else if (IndicatedInfo == CellIndication.EnergyFlowIn) { IndicatedText = logic.Data.EnergyReceived.EnergyFlowInExternal.ToString("G3"); } else { IndicatedText = ""; TextIndicator.enabled = false; } TextIndicator.text = IndicatedText; }
public void TestIsOnShouldReturnDelegate() { CellLogic underTest = new CellLogic(null, null, true); UUnitAssert.True(underTest.isOn()); }
private void Execute(object paremeter) { ThreadParameter p = paremeter as ThreadParameter; JZDocument oldDoc = p.OldDoc; JZDocument newDoc = p.NewDoc; if (oldDoc == null) { return; } String json = ""; List <JZModifyItem> modifyList = new List <JZModifyItem>(); List <CellChangedNotifyItem> notifyList = new List <CellChangedNotifyItem>(); if (p.OptType == "修改") { #region 统计修改单元格 if (newDoc == null || oldDoc.ID != newDoc.ID) { return; } try { ModuleHelper mh = new ModuleHelper(); CaiJiHelper caiji = new CaiJiHelper(); int CaiJiCount = caiji.CaiJiCountByDataID(p.DocBase.ID); foreach (JZSheet sheet in oldDoc.Sheets) { Sys_Sheet sheetBase = mh.GetSheetItemByID(sheet.ID); List <CellLogic> cellLogicList = Newtonsoft.Json.JsonConvert.DeserializeObject <List <CellLogic> >(JZCommonHelper.GZipDecompressString(sheetBase.CellLogic)); foreach (JZCell cell in sheet.Cells) { if (cell.Value != null && cell.Value.ToString().Length < 4000 && cell.Value.ToString() != "" && cell.Value.ToString() != "/") { Object obj = JZCommonHelper.GetCellValue(newDoc, sheet.ID, cell.Name); String newValue = obj == null ? "" : obj.ToString(); if (cell.Value.ToString() != newValue) { JZModifyItem item = new JZModifyItem() { CellPosition = cell.Name, SheetID = sheet.ID, OriginalValue = cell.Value.ToString(), CurrentValue = newValue }; modifyList.Add(item); CellLogic cl = GetCellLogic(cell.Name, cellLogicList); if (cl != null) { if (cl.IsKey && cl.Description.Contains("编号") == false && CaiJiCount > 0 && p.IsAdministrator == false) { CellChangedNotifyItem ni = new CellChangedNotifyItem(); ni.Description = cl.Description; ni.CellPosition = item.CellPosition; ni.CurrentValue = item.CurrentValue; ni.OriginalValue = item.OriginalValue; bool bIsExits = false; foreach (var ccni in notifyList) { if (ccni.Description == ni.Description) { bIsExits = true; break; } } if (bIsExits == false && !string.IsNullOrEmpty(ni.Description)) { notifyList.Add(ni); } else if (string.IsNullOrEmpty(ni.Description)) { logger.Info(string.Format("SheetName:{1},,CellPosition:{0}的Description为空", item.CellPosition, sheet.Name)); } } } } } } } if (modifyList.Count == 0) { return; } json = Newtonsoft.Json.JsonConvert.SerializeObject(modifyList).Replace("'", "''"); } catch (Exception ex) { logger.Error("changes log modify:" + ex.Message); } #endregion } else if (p.OptType == "删除") { json = ""; } else { return; } Guid requestID = Guid.Empty; try { #region 修改日志 DocumentHelper dh = new DocumentHelper(); if (p.RelationRequestChange) { requestID = dh.GetLastApprovedRequestChangeID(newDoc.ID); } String sql = String.Format(@"INSERT INTO dbo.sys_operate_log ( dataID , requestID , modifiedby , modifiedDate , optType , modifyItem, moduleID , testRoomCode , BGBH , DataName ) VALUES ( '{0}','{1}' ,'{2}', GETDATE(),'{3}','{4}','{5}','{6}','{7}','{8}')", oldDoc.ID, requestID, p.UserName, p.OptType, json, p.DocBase.ModuleID, p.DocBase.TestRoomCode, p.DocBase.BGBH, p.DocBase.DataName.Replace("'", "''")); ExcuteCommand(sql); if (modifyList.Count > 0) { UploadHelper uh = new UploadHelper(); UploadSetting uploadSetting = uh.GetUploadSettingByModuleID(p.DocBase.ModuleID); if (uploadSetting != null && uploadSetting.Items != null) { Boolean isChangedSpecialCell = false; foreach (var item in modifyList) { if (isChangedSpecialCell) { break; } foreach (var uploadSettingItem in uploadSetting.Items) { if (item.SheetID == uploadSettingItem.SheetID && item.CellPosition == uploadSettingItem.CellName) { isChangedSpecialCell = true; break; } } } if (isChangedSpecialCell) { sql = "UPDATE dbo.sys_document SET NeedUpload=1 WHERE ID='" + oldDoc.ID + "'"; ExcuteCommand(sql); } } } #endregion } catch (Exception ex) { logger.Error("changes log big error:" + ex.Message); } if (notifyList.Count > 0 && requestID != Guid.Empty) { ///TODO: 用户修改了关键字段,需给业主提示 CellChangedNotifyHelper ccnh = new CellChangedNotifyHelper(); ccnh.NotifyLeader(p.OldDoc.ID, notifyList, p.UserName, p.IsAdministrator, requestID, p.LineID, p.TestRoomCode, p.SegmentName, p.CompanyName, p.TestRoomName, p.LineName); //DocumentHelper dh = new DocumentHelper(); //dh.UpdateDocumentStatus(p.OldDoc.ID, 1); } }
public void AddCellAt(CellLogic cell, int x, int y) { cells[x,y] = cell; }
/// <summary> /// 保存表单样式 /// </summary> private void SaveSheetStyle() { try { Sys_Sheet sheet = new Sys_Sheet(); sheet.ID = sheetID; sheet.Name = SheetName; sheet.SheetXML = JZCommonHelper.GZipCompressString(Editor.GetActiveSheetXml()); List <JZCell> cells = new List <JZCell>(); List <CellLogic> cellLogicList = new List <CellLogic>(); List <JZFormulaData> cellFormulasList = new List <JZFormulaData>(); //bool bIsKeyDescEmpty = false; #region CellLogic foreach (Cell cell in dataCells) { if (cell == null) { continue; } JZCell c = new JZCell(); c.Name = cell.Column.Label + cell.Row.Label; c.Value = cell.Value; bool bHasExist = false; foreach (JZCell cc in cells) { if (cc.Name == c.Name) { bHasExist = true; break; } } if (bHasExist == true) { continue; } cells.Add(c); CellLogic cl = new CellLogic(); cl.Name = c.Name; JZCellProperty p = cell.Tag as JZCellProperty; if (p != null) { cl.Description = p.Description; cl.IsKey = p.IsKey; cl.IsNotCopy = p.IsNotCopy; cl.IsNotNull = p.IsNotNull; cl.IsPingxing = p.IsPingxing; cl.IsReadOnly = p.IsReadOnly; cl.IsUnique = p.IsUnique; if (cl.IsKey == true && string.IsNullOrEmpty(cl.Description)) { //bIsKeyDescEmpty = true; MessageBox.Show(string.Format("单元格{0}的描述不能为空", c.Name)); return; } } cellLogicList.Add(cl); } #endregion #region Formulas if (FpSpread.Sheets[0] != null) { for (int j = 0; j < FpSpread.Sheets[0].ColumnCount; j++) { for (int m = 0; m < FpSpread.Sheets[0].RowCount; m++) { Cell c = FpSpread.Sheets[0].Cells[m, j]; JZFormulaData cl = new JZFormulaData(); if (c != null) { if (!string.IsNullOrEmpty(c.Formula)) { //logger.Error(string.Format("Name:{0} ColumnIndex:{1} RowIndex:{2} Formula:{3} ", ((char)('A' + c.Column.Index)).ToString() + (c.Row.Index + 1).ToString(), c.Column.Index, c.Row.Index, c.Formula)); cl.ColumnIndex = c.Column.Index; cl.RowIndex = c.Row.Index; cl.Formula = c.Formula; cellFormulasList.Add(cl); } } } } } #endregion sheet.SheetData = Newtonsoft.Json.JsonConvert.SerializeObject(cells); sheet.CellLogic = JZCommonHelper.GZipCompressString(Newtonsoft.Json.JsonConvert.SerializeObject(cellLogicList)); sheet.Formulas = JZCommonHelper.GZipCompressString(Newtonsoft.Json.JsonConvert.SerializeObject(cellFormulasList)); if (ModuleHelperClient.SaveSheet(sheet)) { MessageBox.Show("保存成功。", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); } else { MessageBox.Show("保存失败。", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); } } catch (Exception ex) { MessageBox.Show("保存失败。" + ex.Message, "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); } }
public void DropPieces(CellLogic cell) { int c = cell.GetCol(); int or = 1; // check how position is must drop before lay onto any piece while(cell.dn != null &&cell.dn.Match(CellColor.NoColor)) { cell = cell.dn; or++; } // drop the cells for(int r = cell.GetRow()-or; r >= 0; r--) { if(cells[r+or][c].Match(CellColor.NoColor)) { cells[r+or][c].SetColor(cells[r][c].GetColor()); cells[r][c].SetColor(CellColor.NoColor); } } // clear the top cells for(int r = or; r >= 0; r--) { cells[r][c].SetColor(CellColor.NoColor); } }
public void DestroyCell(CellLogic cell, List<CellLogic> scoreCells) { cell.Destroy(); }
/* * Check if given cell forms a score. * */ List<CellLogic> IsCellScore(CellLogic cell) { List<CellLogic> hCells = new List<CellLogic>(); List<CellLogic> vCells = new List<CellLogic>(); CellColor clr = cell.GetColor(); hCells.Add(cell); vCells.Add(cell); CellLogic baseCell = cell; // walking the neighborhood while they are the same color // walking to the left while(cell.lf != null && cell.lf.Match(clr)) { hCells.Add(cell.lf); cell = cell.lf; } cell = baseCell; // walking to the right while(cell.rt != null && cell.rt.Match(clr)) { hCells.Add(cell.rt); cell = cell.rt; } cell = baseCell; // walking up while(cell.up != null && cell.up.Match(clr)) { vCells.Add(cell.up); cell = cell.up; } cell = baseCell; // walking down while(cell.dn != null && cell.dn.Match(clr)) { vCells.Add(cell.dn); cell = cell.dn; } // if found a sequence greater than 2, then the player scored. List<CellLogic> scoredCells = new List<CellLogic>(); if(vCells.Count > 2) { scoredCells.AddRange(vCells); foreach(var c in vCells) { CheckBombCell(c, scoredCells); } } if(hCells.Count > 2) { scoredCells.AddRange(hCells); foreach(var c in hCells) { CheckBombCell(c, scoredCells); } } return scoredCells; }
public void Rotate() { /* w 3, h 2 h 3, w 2 * |1,0|1,1|1,2| |0,0|1,0| |2,0|2,1| * |0,0|0,1|0,2| -> |0,1|1,1| |1,0|1,1| * |0,2|1,2| -> |0,0|0,1| * * |1,0|1,1| |0,0|1,0| * |0,0|0,1| -> |0,1|1,1| */ CellLogic[][] temp = new CellLogic[3][]; for(int r = 0; r < width; r++) { temp[r] = new CellLogic[3]; for(int c = 0; c < height; c++) { temp[r][c] = new CellLogic(r,c); temp[r][c].SetColor(cells[c][width-r-1].GetColor()); temp[r][c].SetFeature(cells[c][width-r-1].GetFeature()); } } for(int r = 0; r < width; r++) { for(int c = 0; c < height; c++) { cells[r][c].SetColor(temp[r][c].GetColor()); cells[r][c].SetFeature(temp[r][c].GetFeature()); } } int holdwidth = width; width = height; height = holdwidth; //cells = temp; }
void CheckBombCell(CellLogic cell, List<CellLogic> scoreCells) { // If it was a bomb cell, neighborhood is destroyed if(cell.GetFeature() == CellFeature.Bomb) { // left cell if(cell.lf != null) { if(!cell.lf.Match(CellColor.NoColor) && !scoreCells.Contains(cell.lf)) scoreCells.Add(cell.lf); // up cell of left cell if(cell.lf.up != null && !cell.lf.up.Match(CellColor.NoColor) && !scoreCells.Contains(cell.lf.up)) scoreCells.Add(cell.lf.up); // down cell of left cell if(cell.lf.dn != null && !cell.lf.dn.Match(CellColor.NoColor) && !scoreCells.Contains(cell.lf.dn)) scoreCells.Add(cell.lf.dn); } if(cell.rt != null) { if(!cell.rt.Match(CellColor.NoColor) && !scoreCells.Contains(cell.rt)) scoreCells.Add(cell.rt); // up cell of right cell if(cell.rt.up != null && !cell.rt.up.Match(CellColor.NoColor) && !scoreCells.Contains(cell.rt.up)) scoreCells.Add(cell.rt.up); // down cell of right cell if(cell.rt.dn != null && !cell.rt.dn.Match(CellColor.NoColor) && !scoreCells.Contains(cell.rt.dn)) scoreCells.Add(cell.rt.dn); } if(cell.dn != null) { if(!cell.dn.Match(CellColor.NoColor) && !scoreCells.Contains(cell.dn)) scoreCells.Add(cell.dn); // left cell of down cell if(cell.dn.lf != null && !cell.dn.lf.Match(CellColor.NoColor) && !scoreCells.Contains(cell.dn.lf)) scoreCells.Add(cell.dn.lf); // right cell of down cell if(cell.dn.rt != null && !cell.dn.rt.Match(CellColor.NoColor) && !scoreCells.Contains(cell.dn.rt)) scoreCells.Add(cell.dn.rt); } if(cell.up != null) { if(!cell.up.Match(CellColor.NoColor) && !scoreCells.Contains(cell.up)) scoreCells.Add(cell.up); // left cell of up if(cell.up.lf != null && !cell.up.lf.Match(CellColor.NoColor) && !scoreCells.Contains(cell.up.lf)) scoreCells.Add(cell.up.lf); // right cell of up if(cell.up.rt != null && !cell.up.rt.Match(CellColor.NoColor) && !scoreCells.Contains(cell.up.rt)) scoreCells.Add(cell.up.rt); } } }
public void AddCellAt(CellLogic cell, int x, int y) { cells[x, y] = cell; }
public void Setup() { MockMUDDataAccess = new Mock <IMUDDataAccess>(); cellLogic = new CellLogic(MockMUDDataAccess.Object); }