private void M_ShotResponseRecieved(object sender, EventArgs e) { if (myTurn) { WeaponResponseComm c = (WeaponResponseComm)sender; short field = 0; if (c.result == null) { if (c.response == FireResponse.hit) { //myTurn = true; field = 3; } else { field = 2; //myTurn = false; } } else if (c.result == FireResult.sunk) { //myTurn = true; field = 4; } else //implement o win { Won.Invoke(me, EventArgs.Empty); } myTurn = false; opponent.Battlefield.field[getIntFromLetter(c.x), c.y] = field; } }
public void AddPoints() { СountPoints += 200 + _coefficientOfPoints; ChangeColor(); if (СountPoints >= _level.WinCountPoints) { _isOpacity = true; Won?.Invoke(); } }
public void OnEnemyKilled() { if (_activeDeathRequiredAmount) { _currentEnemyDeath++; if (_currentEnemyDeath >= _deathRequiredAmount) { Won?.Invoke(_missionName); ChangeLevelStatus(); } } }
public void OnPlayerReceivedDamage(bool receivedDamage) { if (_activeUntouchable) { if (receivedDamage == false) { Won?.Invoke(_missionName); ChangeLevelStatus(); } else { MissionFailed?.Invoke(_missionName); } } }
public void OnTimeIsOver(float timeValue) { if (_activeTimeToHoldOut) { if (timeValue == 0) { Won?.Invoke(_missionName); ChangeLevelStatus(); } else { MissionFailed?.Invoke(_missionName); } } }
public void Sunk(BattleshipShip ship) { player1.sunk.Add(ship); for (int i = 0; i < ship.size; i++) { rightBoard.cells[ship.positions[i][0] - 1, ship.positions[i][1] - 1].BackgroundImage = ship.components[i]; } if (player1.sunk.Count == player1.myShips.Count) { finished = true; //rightBoard.ImgClick -= Guess1; Won?.Invoke(this, new OnWin { player = player1 }); } }
private void OnWon() { Won?.Invoke(this, new GameControllerEventArgs(this)); }
private void Guess1(object sender, BattleshipBoard.ImgClickEventArgs e) { int x = e.coordinates[0] - 1, y = e.coordinates[1] - 1; if (!finished) { Guess(); } void Guess() { if (player1.guesses[x, y] == 0) { bool hit = false; foreach (BattleshipShip ship in bot.myShips) { if (!hit) { int i = 0; while (i < ship.size && !(ship.positions[i][0] == x + 1 && ship.positions[i][1] == y + 1)) { i++; } if (i < ship.size) { hit = true; player1.guesses[x, y] = 2; Hit(new int[] { x, y }, rightBoard); ship.hp -= 1; if (ship.hp == 0) { Sunk(ship); } } } } if (!hit) { player1.guesses[x, y] = 1; Miss(new int[] { x, y }, rightBoard); } //BOT GUESS if (!finished) { hit = false; int[] botGuess = bot.Guesser(); foreach (BattleshipShip ship in player1.myShips) { if (!hit) { int i = 0, xBot = botGuess[0] + 1, yBot = botGuess[1] + 1; while (i < ship.size && !(ship.positions[i][0] == xBot && ship.positions[i][1] == yBot)) { i++; } if (i < ship.size) { hit = true; bot.guesses[x, y] = 2; bot.Hit(); Hit(botGuess, leftBoard); ship.hp -= 1; if (ship.hp == 0) { bot.sunk.Add(ship); if (bot.sunk.Count == bot.myShips.Count) { finished = true; Won?.Invoke(this, new OnWin { player = bot }); } } } } } if (!hit) { bot.guesses[x, y] = 1; Miss(botGuess, leftBoard); } } } } }
private void OnWon(WonArgs e) { Won?.Invoke(this, e); }