public SportsCellData(ECell p_type, float p_value) { m_type = p_type; this.Title = TITLE_MAP[p_type]; this.Unit = METRIC_MAP[p_type]; this.Value = p_value.ToString(); this.Cursor = CURSOR_INVALID; }
/// <summary> /// Set cell /// </summary> /// <param name="cell">Cell</param> /// <param name="x">X</param> /// <param name="y">Y</param> /// <returns>"true" if successful, otherwise "false"</returns> internal bool SetCell(ECell cell, int x, int y) { bool ret = false; if ((x >= 0) && (x < width) && (y >= 0) && (y < height)) { cells[x + (y * width)] = cell; ret = true; } return(ret); }
/// <summary> /// Move block /// </summary> /// <param name="xOffset">X offset</param> /// <param name="yOffset">Y offset</param> /// <param name="landWhenFailed">Land when failed</param> /// <returns>"true" if possible, otherwise "false"</returns> private bool MoveBlock(int xOffset, int yOffset, bool landWhenFailed) { bool ret = false; Field field = user.FieldInternal; if (field.SelectedBlock != EBlock.Nothing) { ECell[] field_cells = new ECell[Field.width * Field.height]; ECell[,] block_cells = GetBlockCells(field.SelectedBlock, field.SelectedBlockRotation); int x_origin = (int)(field.SelectedBlockPositionX) + xOffset; int y_origin = (int)(field.SelectedBlockPositionY) + yOffset; if (field.CopyCellsTo(field_cells, false)) { ret = CheckCells(field_cells, block_cells, x_origin, y_origin); if (ret) { field.SelectedBlockPositionX = (uint)x_origin; field.SelectedBlockPositionY = (uint)y_origin; } else if (landWhenFailed) { for (int x = 0, y, x_len = block_cells.GetLength(0), y_len = block_cells.GetLength(1); x < x_len; x++) { int field_x = x + x_origin; if ((field_x >= 0) && (field_x < Field.width)) { for (y = 0; y < y_len; y++) { int field_y = y + y_origin; if ((field_y >= 0) && (field_y < Field.height)) { int field_index = field_x + (field_y * Field.width); if ((field_cells[field_index] != ECell.Nothing) && (block_cells[x, y] != ECell.Nothing)) { field_cells[field_index] = block_cells[x, y]; break; } } } } } field.SelectedBlock = EBlock.Nothing; field.SelectedBlockPositionX = 0U; field.SelectedBlockPositionY = 0U; field.UpdateCells(field_cells); } } } return(ret); }
/// <summary> /// User full field update event /// </summary> /// <param name="userID">User ID</param> /// <param name="cells">Cells</param> private void UserFullFieldUpdateEvent(int userID, ECell[] cells) { if (users.IsIDValid(userID)) { IHostUser user = users[userID] as IHostUser; if (user != null) { ECell[] old_cells = new ECell[Field.width * Field.height]; if (user.FieldInternal.CopyCellsTo(old_cells, false)) { if (user.FieldInternal.UpdateCells(cells)) { OnUserFieldUpdate?.Invoke(user, old_cells, cells); } } } } }
/// <summary> /// Rotate block /// </summary> /// <param name="blockCells">Block cells</param> /// <param name="blockRotation">Block rotation</param> /// <returns>ROtated block cells</returns> private static ECell[,] RotateBlock(ECell[,] blockCells, EBlockRotation blockRotation) { ECell[,] ret = null; switch (blockRotation) { case EBlockRotation.ZeroDegree: ret = blockCells; break; case EBlockRotation.NinetyDegree: ret = new ECell[blockCells.GetLength(1), blockCells.GetLength(0)]; for (int x = 0, y, x_len = ret.GetLength(0), y_len = ret.GetLength(1); x < x_len; x++) { for (y = 0; y < y_len; y++) { ret[x, y_len - y - 1] = blockCells[y, x]; } } break; case EBlockRotation.OneHundredEightyDegree: ret = new ECell[blockCells.GetLength(0), blockCells.GetLength(1)]; for (int x = 0, y, x_len = ret.GetLength(0), y_len = ret.GetLength(1); x < x_len; x++) { for (y = 0; y < y_len; y++) { ret[x_len - x - 1, y_len - y - 1] = blockCells[x, y]; } } break; case EBlockRotation.TwoHundredSeventyDegree: ret = new ECell[blockCells.GetLength(1), blockCells.GetLength(0)]; for (int x = 0, y, x_len = ret.GetLength(0), y_len = ret.GetLength(1); x < x_len; x++) { for (y = 0; y < y_len; y++) { ret[x_len - x - 1, y] = blockCells[y, x]; } } break; } return(ret); }
/// <summary> /// Get cell /// </summary> /// <param name="x">X position</param> /// <param name="y">Y position</param> /// <param name="copySelectedBlock">Copy selected block</param> /// <returns>Tetri cell</returns> public ECell GetCell(int x, int y, bool copySelectedBlock) { ECell ret = ECell.Nothing; if ((x >= 0) && (x < cells.GetLength(0)) && (x >= 0) && (x < cells.GetLength(0))) { ret = cells[x + (y * width)]; if (copySelectedBlock) { ECell[,] block_cells = GameManager.GetBlockCells(SelectedBlock, SelectedBlockRotation); int block_x = x - (int)SelectedBlockPositionX; int block_y = y - (int)SelectedBlockPositionY; if ((block_x >= 0) && (block_x < block_cells.GetLength(0)) && (block_y >= 0) && (block_y < block_cells.GetLength(1))) { ret = block_cells[block_x, block_y]; } } } return(ret); }
/// <summary> /// Turn block /// </summary> /// <param name="turnLeft">Turn left</param> /// <returns>"true" if successful, otherwise "false"</returns> private bool TurnBlock(bool turnLeft) { bool ret = false; Field field = user.FieldInternal; if (field.SelectedBlock != EBlock.Nothing) { EBlockRotation block_rotation = (EBlockRotation)(((int)(field.SelectedBlockRotation) + (turnLeft ? 1 : 3)) % blockRotationCount); ECell[] field_cells = new ECell[Field.width * Field.height]; ECell[,] block_cells = GetBlockCells(field.SelectedBlock, block_rotation); int x_origin = (int)(field.SelectedBlockPositionX); int y_origin = (int)(field.SelectedBlockPositionY); if (field.CopyCellsTo(field_cells, false)) { ret = CheckCells(field_cells, block_cells, x_origin, y_origin); if (ret) { field.SelectedBlockRotation = block_rotation; } } } return(ret); }
/// <summary> /// User partial field update event /// </summary> /// <param name="userID">User ID</param> /// <param name="cellPositions">Cell positions</param> private void UserPartialFieldUpdateEvent(int userID, CellPosition[] cellPositions) { if (users.IsIDValid((int)userID)) { IHostUser user = users[(int)userID] as IHostUser; if (user != null) { ECell[] old_cells = new ECell[Field.width * Field.height]; if (user.FieldInternal.CopyCellsTo(old_cells, false)) { foreach (CellPosition cell_position in cellPositions) { user.FieldInternal.SetCell(cell_position.Cell, (int)(cell_position.X), (int)(cell_position.Y)); } ECell[] new_cells = new ECell[old_cells.Length]; if (user.FieldInternal.CopyCellsTo(new_cells, false)) { OnUserFieldUpdate?.Invoke(user, old_cells, new_cells); } } } } }
public SportsCellData(ECell p_type) : this(p_type, 0.0f) { }
/**************************************************************** * Helpers **/ public static string TitleFrom(ECell p_cell) { return(TITLE_MAP[p_cell]); }
/// <summary> /// Cell position /// </summary> /// <param name="cell">Cell</param> /// <param name="x">X</param> /// <param name="y">Y</param> public CellPosition(ECell cell, uint x, uint y) { Cell = cell; X = x; Y = y; }
public SportsCellData (ECell p_type, float p_value) { m_type = p_type; this.Title = TITLE_MAP[p_type]; this.Unit = METRIC_MAP[p_type]; this.Value = p_value.ToString(); this.Cursor = CURSOR_INVALID; }
public SportsCellData (ECell p_type) : this(p_type, 0.0f) { }
public static string MetricFrom (ECell p_cell) { return METRIC_MAP[p_cell]; }
/**************************************************************** * Helpers **/ public static string TitleFrom (ECell p_cell) { return TITLE_MAP[p_cell]; }
private static void translateEntries(List<MapEntry> entries, DataManager manager, ContentManager content) { Dictionary<string, EPoint> points = new Dictionary<string, EPoint>(); Dictionary<string, Texture2D> textures = new Dictionary<string, Texture2D>(); Dictionary<string, ETile> tiles = new Dictionary<string, ETile>(); Dictionary<string, Grid> grids = new Dictionary<string, Grid>(); Dictionary<string, ECell> cells = new Dictionary<string, ECell>(); Dictionary<string, double> numbers = new Dictionary<string, double>(); Dictionary<string, bool> booleans = new Dictionary<string, bool>(); Dictionary<string, string> strings = new Dictionary<string, string>(); foreach (MapEntry entry in entries) { if (entry.TypeName == "Texture") { Texture2D texture = content.Load<Texture2D>(entry[0]); textures.Add(entry.EntryName, texture); } else if (entry.TypeName == "Point") { EPoint point = new EPoint( int.Parse(entry[0]), int.Parse(entry[1]), int.Parse(entry[2])); points.Add(entry.EntryName, point); } else if (entry.TypeName == "Tile") { ETile tile = new ETile(); tile.Texture = textures[entry[0]]; tile.Solid = bool.Parse(entry[1]); tiles.Add(entry.EntryName, tile); } else if (entry.TypeName == "Grid") { EPoint gridSize = points[entry[0]]; EPoint gridOrigin = points[entry[1]]; EPoint gridTileOffset = points[entry[2]]; EPoint gridTileSize = points[entry[3]]; EPoint playerStart = points[entry[4]]; Grid grid = new Grid( gridSize.X, gridSize.Y, gridSize.Z, null, gridTileOffset.X, gridTileOffset.Y, gridTileSize.X, gridTileSize.Y, gridTileOffset.Z, gridOrigin.X, gridOrigin.Y); grid.ShadowEast = content.Load<Texture2D>("Block Shadow\\Shadow East"); grid.ShadowEast = content.Load<Texture2D>("Block Shadow\\Shadow North East"); grid.ShadowEast = content.Load<Texture2D>("Block Shadow\\Shadow North West"); grid.ShadowEast = content.Load<Texture2D>("Block Shadow\\Shadow North"); grid.ShadowEast = content.Load<Texture2D>("Block Shadow\\Shadow West"); grid.ShadowEast = content.Load<Texture2D>("Block Shadow\\Shadow South East"); grid.ShadowEast = content.Load<Texture2D>("Block Shadow\\Shadow South West"); grid.ShadowEast = content.Load<Texture2D>("Block Shadow\\Shadow South"); grid.ShadowEast = content.Load<Texture2D>("Block Shadow\\Shadow East"); grids.Add(entry.EntryName, grid); } else if (entry.TypeName == "Cell") { ECell cell = new ECell(); cell.Point = new EPoint(int.Parse(entry[0]), int.Parse(entry[1]), int.Parse(entry[2])); cell.Grid = grids[entry[3]]; cell.Tile = tiles[entry[4]]; cell.Grid.setTile( cell.Point.X, cell.Point.Y, cell.Point.Z, cell.Tile.Texture, cell.Tile.Solid); if (!string.IsNullOrEmpty(entry.EntryName)) cells.Add(entry.EntryName, cell); } else if (entry.TypeName == "Number") { numbers.Add(entry.EntryName, double.Parse(entry[0])); } else if (entry.TypeName == "Boolean") { booleans.Add(entry.EntryName, bool.Parse(entry[0])); } else if (entry.TypeName == "String") { strings.Add(entry.EntryName, entry[0]); } } foreach (string key in grids.Keys) { manager.AddItem(key, grids[key]); } foreach (string key in textures.Keys) { manager.AddItem(key, textures[key]); } }
public static string MetricFrom(ECell p_cell) { return(METRIC_MAP[p_cell]); }