public Block(Block block) { this.blockType = block.blockType; //this.PrevBlockType = SeaType.EmptySea; this.xPos = block.xPos; this.yPos = block.yPos; this.selected = block.selected; this.printChar = block.printChar; this.shipname = block.shipname; }
public void ChangeDirection() { Block[] oldblocks = this.blocks; if (this.direction == ShipDirection.Horizontal) { blocks = new Block[this.length]; this.direction = ShipDirection.Vertical; foreach (Block b in this.blocks) { } } else { } }
//constructor public Ship(SeaType shipType, int xpos, int ypos, int length, ShipDirection direction, int timesHit, bool sunk, string printchar, string name) { this.shipType = shipType; this.blocks = new Block[length]; for (int i = 0; i < length; i++) { if (direction == ShipDirection.Horizontal) blocks[i] = new Block(shipType, xpos + i, ypos, printchar, name); else blocks[i] = new Block(shipType, xpos, ypos + i, printchar, name); } this.length = length; this.direction = direction; this.timesHit = timesHit; this.sunk = sunk; }
private void UserSea_BlockChanged(Block block) { printOnPos(UserSea, PrintBlock(block, true), block.xPos, block.yPos); ResetColours(); }
private string PrintBlock(Block b, bool debug) { string temp; if (!b.selected) { if (b.blockType == SeaType.Attacked) { SetBackground(ConsoleConstants.CLR_ATTACKED_SQUARE_B); SetForeground(ConsoleConstants.CLR_ATTACKED_SQUARE_F); } else if (b.blockType == SeaType.Hit) { SetBackground(ConsoleConstants.CLR_HIT_SQUARE_B); SetForeground(ConsoleConstants.CLR_HIT_SQUARE_F); } else { if (b.blockType == SeaType.EmptySea) { ResetColours(); } if (debug) { if (b.blockType != SeaType.EmptySea) { SetBackground(ConsoleConstants.CLR_NORMAL_SQUARE_B); SetForeground(ConsoleConstants.CLR_NORMAL_SQUARE_F); } } else { b.printChar = "~"; } } temp = b.printChar; } else { SetBackground(ConsoleConstants.CLR_SELECTED_SQUARE_B); SetForeground(ConsoleConstants.CLR_SELECTED_SQUARE_F); temp = "+"; } return temp; }
private void ComputerSea_BlockChanged(Block block) { printOnPos(ComputerSea, PrintBlock(block, ConsoleConstants.DEBUG), block.xPos, block.yPos); ResetColours(); }