public void render() { TileFactory tf = TileFactory.Instance; Bitmap pg = new Bitmap(800, 600); Graphics gr = Graphics.FromImage(pg); ZRTSModel.Map map = gameworld.GetMap(); // TODO: Change to include the scrolling model. for (int x = 0; x < map.GetWidth(); x++) { for (int y = 0; y < map.GetHeight(); y++) { ZRTSModel.Tile tile = map.GetCellAt(x, y).GetTile(); if (tile != null) { gr.DrawImage(tf.getBitmapImproved(tile), x * 16, y * 16, 16, 16); } //if (map.cells[x, y] != null && map.cells[x, y].tile != null && map.cells[x, y].tile.tileType != null) //gr.DrawImage(tf.getBitmap(map.cells[x, y].tile.tileType), x * 16, y * 16, 16, 16); else { gr.DrawRectangle(new Pen(Color.Black), x * 16, y * 16, 16, 16); } } } pictureBox1.Image = pg; }
/// <summary> /// Changes the target cell to include the new target tile. /// </summary> public void Do() { if (CanBeDone()) { previousTile = targetCell.GetTile(); // Cell.AddChild is overriden to ensure that only one tile exists. This action // removes the previous tile and replaces it with the new one. targetCell.AddChild(targetTile); } }
internal void OnDragMapCell(CellComponent cell) { if (model.GetSelectionState().SelectionType == typeof(ZRTSModel.Tile)) { TileFactory tf = TileFactory.Instance; ZRTSModel.Tile tile = tf.GetImprovedTile(model.GetSelectionState().SelectedTileType); ChangeCellTileCommand command = new ChangeCellTileCommand(cell, tile); if (command.CanBeDone()) { model.GetCommandStack().ExecuteCommand(command); } } }
/// <summary> /// Determines from the selection state if we are placing a resource, building, unit, or tile, and then places it based on /// the selection state. /// </summary> /// <param name="x"></param> /// <param name="y"></param> internal void OnClickMapCell(int x, int y) { if (model.GetSelectionState().SelectionType == typeof(ZRTSModel.Tile)) { TileFactory tf = TileFactory.Instance; CellComponent cell = model.GetScenario().GetGameWorld().GetMap().GetCellAt(x, y); ZRTSModel.Tile tile = tf.GetImprovedTile(model.GetSelectionState().SelectedTileType); ChangeCellTileCommand command = new ChangeCellTileCommand(cell, tile); if (command.CanBeDone()) { model.GetCommandStack().ExecuteCommand(command); } } else if (model.GetSelectionState().SelectionType == typeof(UnitComponent)) { // Get instance of Unit Factory, produce unit, and place on map for the given player. } }
internal void OnClickMapCell(CellComponent cellComponent, float xPercent, float yPercent) { if (model.GetSelectionState().SelectionType == typeof(ZRTSModel.Tile)) { TileFactory tf = TileFactory.Instance; ZRTSModel.Tile tile = tf.GetImprovedTile(model.GetSelectionState().SelectedTileType); ChangeCellTileCommand command = new ChangeCellTileCommand(cellComponent, tile); if (command.CanBeDone()) { model.GetCommandStack().ExecuteCommand(command); } } else if (model.GetSelectionState().SelectionType == typeof(UnitComponent)) { UnitFactory uf = UnitFactory.Instance; UnitComponent unit = uf.Create(model.GetSelectionState().SelectedUnitType); //unit.PointLocation = new PointF((float)cellComponent.X + xPercent, (float)cellComponent.Y + yPercent); PlayerComponent player = model.GetScenario().GetGameWorld().GetPlayerList().GetPlayerByName(model.GetSelectionState().SelectedPlayer); AddUnitCommand command = new AddUnitCommand(unit, player, cellComponent); if (command.CanBeDone()) { model.GetCommandStack().ExecuteCommand(command); } } else if (model.GetSelectionState().SelectionType == typeof(Building)) { BuildingFactory bf = BuildingFactory.Instance; Building building = bf.Build(model.GetSelectionState().SelectedBuildingType, true); //building.PointLocation = new PointF((float)cellComponent.X + xPercent, (float)cellComponent.Y + yPercent); PlayerComponent player = model.GetScenario().GetGameWorld().GetPlayerList().GetPlayerByName(model.GetSelectionState().SelectedPlayer); AddBuildingCommand command = new AddBuildingCommand(building, player, cellComponent); if (command.CanBeDone()) { model.GetCommandStack().ExecuteCommand(command); } } }
public ChangeCellTileCommand(CellComponent cell, ZRTSModel.Tile tile) { targetCell = cell; targetTile = tile; }