public void GetTurn(int x, int y) { if (_game != null) { if (_game.field.GetCell(x, y) == Cell.Empty) { _game.field.SetCell(x, y, Cell.Missed); try { _callback.UpdateYourField(x, y, Cell.Missed); } catch (Exception) { } try { _game.Opponent.UpdateOpponentField(x, y, Cell.Missed); } catch (Exception) { } YouTurn(); return; } if (_game.field.GetCell(x, y) == Cell.DeadShip || _game.field.GetCell(x, y) == Cell.Fire || _game.field.GetCell(x, y) == Cell.Missed) { _game.Opponent.AlreadyClicked(); _game.Opponent.YouTurn(); return; } List <Point> list = new List <Point>(); list.Add(new Point(x, y)); _game.field.SetCell(x, y, Cell.Fire); bool killed = true; for (int i = 0; i < list.Count; i++) { int lx = list[i].x; int ly = list[i].y; if (lx > 0) { if (_game.field.GetCell(lx - 1, ly) == Cell.Ship) { killed = false; break; } if (_game.field.GetCell(lx - 1, ly) == Cell.Fire && !ListContained(list, lx - 1, ly)) { list.Add(new Point(lx - 1, ly)); } } if (lx < 9) { if (_game.field.GetCell(lx + 1, ly) == Cell.Ship) { killed = false; break; } if (_game.field.GetCell(lx + 1, ly) == Cell.Fire && !ListContained(list, lx + 1, ly)) { list.Add(new Point(lx + 1, ly)); } } if (ly > 0) { if (_game.field.GetCell(lx, y - 1) == Cell.Ship) { killed = false; break; } if (_game.field.GetCell(lx, ly - 1) == Cell.Fire && !ListContained(list, lx, ly - 1)) { list.Add(new Point(lx, ly - 1)); } } if (ly < 9) { if (_game.field.GetCell(lx, ly + 1) == Cell.Ship) { killed = false; break; } if (_game.field.GetCell(lx, ly + 1) == Cell.Fire && !ListContained(list, lx, ly + 1)) { list.Add(new Point(lx, ly + 1)); } } } if (!killed) { try { _callback.UpdateYourField(x, y, Cell.Fire); } catch (Exception) { } try { _game.Opponent.UpdateOpponentField(x, y, Cell.Fire); } catch (Exception) { } _game.Opponent.YouTurn(); return; } for (int i = 0; i < list.Count; i++) { int lx = list[i].x; int ly = list[i].y; if (lx > 0) { if (_game.field.GetCell(lx - 1, ly) == Cell.Empty) { _game.field.SetCell(lx - 1, ly, Cell.Missed); try { _callback.UpdateYourField(lx - 1, ly, Cell.Missed); } catch (Exception) { } try { _game.Opponent.UpdateOpponentField(lx - 1, ly, Cell.Missed); } catch (Exception) { } } } if (lx > 0 && ly > 0) { if (_game.field.GetCell(lx - 1, ly - 1) == Cell.Empty) { _game.field.SetCell(lx - 1, ly - 1, Cell.Missed); try { _callback.UpdateYourField(lx - 1, ly - 1, Cell.Missed); } catch (Exception) { } try { _game.Opponent.UpdateOpponentField(lx - 1, ly - 1, Cell.Missed); } catch (Exception) { } } } if (ly > 0) { if (_game.field.GetCell(lx, ly - 1) == Cell.Empty) { _game.field.SetCell(lx, ly - 1, Cell.Missed); try { _callback.UpdateYourField(lx, ly - 1, Cell.Missed); } catch (Exception) { } try { _game.Opponent.UpdateOpponentField(lx, ly - 1, Cell.Missed); } catch (Exception) { } } } if (ly > 0 && lx < 9) { if (_game.field.GetCell(lx + 1, ly - 1) == Cell.Empty) { _game.field.SetCell(lx + 1, ly - 1, Cell.Missed); try { _callback.UpdateYourField(lx + 1, ly - 1, Cell.Missed); } catch (Exception) { } try { _game.Opponent.UpdateOpponentField(lx + 1, ly - 1, Cell.Missed); } catch (Exception) { } } } if (lx < 9) { if (_game.field.GetCell(lx + 1, ly) == Cell.Empty) { _game.field.SetCell(lx + 1, ly, Cell.Missed); try { _callback.UpdateYourField(lx + 1, ly, Cell.Missed); } catch (Exception) { } try { _game.Opponent.UpdateOpponentField(lx + 1, ly, Cell.Missed); } catch (Exception) { } } } if (lx < 9 && ly < 9) { if (_game.field.GetCell(lx + 1, ly + 1) == Cell.Empty) { _game.field.SetCell(lx + 1, ly + 1, Cell.Missed); try { _callback.UpdateYourField(lx + 1, ly + 1, Cell.Missed); } catch (Exception) { } try { _game.Opponent.UpdateOpponentField(lx + 1, ly + 1, Cell.Missed); } catch (Exception) { } } } if (ly < 9) { if (_game.field.GetCell(lx, ly + 1) == Cell.Empty) { _game.field.SetCell(lx, ly + 1, Cell.Missed); try { _callback.UpdateYourField(lx, ly + 1, Cell.Missed); } catch (Exception) { } try { _game.Opponent.UpdateOpponentField(lx, ly + 1, Cell.Missed); } catch (Exception) { } } } if (lx > 0 && ly < 9) { if (_game.field.GetCell(lx - 1, ly + 1) == Cell.Empty) { _game.field.SetCell(lx - 1, ly + 1, Cell.Missed); try { _callback.UpdateYourField(lx - 1, ly + 1, Cell.Missed); } catch (Exception) { } try { _game.Opponent.UpdateOpponentField(lx - 1, ly + 1, Cell.Missed); } catch (Exception) { } } } _game.field.SetCell(lx, ly, Cell.DeadShip); try { _callback.UpdateYourField(lx, ly, Cell.DeadShip); } catch (Exception) { } try { _game.Opponent.UpdateOpponentField(lx, ly, Cell.DeadShip); } catch (Exception) { } } _game.ships--; if (_game.ships == 0) { try { _game.Opponent.Win(); } catch (Exception) { } try { _callback.Loose(); } catch (Exception) { } Client client = _game.Opponent; _game = null; client.JoinTo(this); return; } _game.Opponent.YouTurn(); return; } }