public GameLogic() { HostShipsLeft = new Ships.ShipsLeft(Settings.Default.Carriers, Settings.Default.Battleships, Settings.Default.Cruisers, Settings.Default.Destroyers, Settings.Default.Submarines); PostTurnDelay = Settings.Default.PostTurnDelay; ClientShipsLeft = HostShipsLeft; //Generate the game boards int x = 61; int rowx = 0; int rowy = 0; int y = 0; for (int i = 0; i <= 80; i++) { HostGameBoard[rowx, rowy] = new GameBoardTile(new Rectangle(x, y, 61, 61), TileType.Water); ClientGameBoard[rowx, rowy] = new GameBoardTile(new Rectangle(x, y, 61, 61), TileType.Water); x += 61; if (rowx == 8) { y += 61; x = 61; rowx = 0; rowy++; } else { rowx++; } } }
/// <summary> /// Update the clients scoreboard /// </summary> public void UpdateScoreboard(Ships.ShipsLeft LocalShipsLeft, Ships.ShipsLeft OpponentShipsLeft) { MDI_Game.staticGame.BeginInvoke(MDI_Game.staticGame.DUpdateScoreboard, new object[] { LocalShipsLeft, OpponentShipsLeft }); }
/// <summary> /// Initializes the clients game /// </summary> /// <param name="ClientGameBoardTilesBinary">Byte array of the Clients game board converted using <see cref="LibOscar.Methods.GetBinaryArray{T}(T, bool)"/></param> /// <param name="HostGameBoardTilesBinary">Byte array of the Host's game board converted using <see cref="LibOscar.Methods.GetBinaryArray{T}(T, bool)"/></param> /// <param name="ShipsToPlace">How many ships to place</param> /// <param name="ShotsFirstTurn">How many shots should be fired on the first turn</param> /// <param name="ShotsPerTurn">How many shots should be fired each normal turn</param> public void GameStarting(byte[] ClientGameBoardTilesBinary, byte[] HostGameBoardTilesBinary, Ships.ShipsLeft ShipsToPlace, int ShotsFirstTurn, int ShotsPerTurn) { IsServer = false; MDI_Container.GameIsFinished = false; MDI_Container.staticMdi_Container.Invoke(MDI_Container.DSwitchMDI, new object[] { MDI_Form_Enum.MDI_Game, true }); MDI_Game.staticGame.BeginInvoke(MDI_Game.staticGame.DSetGameSettings, new object[] { ShipsToPlace, ShotsFirstTurn, ShotsPerTurn }); MDI_Game.staticGame.BeginInvoke(MDI_Game.staticGame.DUpdateGameBoard, new object[] { GetObjectFromBinaryArray <GameLogic.GameBoardTile[, ]>(ClientGameBoardTilesBinary), GetObjectFromBinaryArray <GameLogic.GameBoardTile[, ]>(HostGameBoardTilesBinary) }); }