public HitInfo GetShot(Position pos) { HitInfo result = null; if (pos.Row >= 0 && pos.Row < _map.Height && pos.Column >= 0 && pos.Column < _map.Width) { var val = _map[pos.Row, pos.Column]; var p = new Position { Row = pos.Row, Column = pos.Column }; if (val <= 0) { result = new HitInfo { IsHit = false, Destroyed = false }; } else { var count = 0; for (int row = 0; row < _map.Height; row++) { for (int col = 0; col < _map.Width; col++) { if (_map[row, col] == val) count++; } } if (count == 1) result = new HitInfo { IsHit = true, Destroyed = true }; else result = new HitInfo { IsHit = true, Destroyed = false }; } _map[pos.Row, pos.Column] = -1; result.Pos = p; return result; } else throw new Exception("Invalid shot"); }
public Position GetMove(Random rnd) { Position pos = null; do { var r = rnd.Next(0, 10) % 10; var c = rnd.Next(0, 10) % 10; pos = new Position { Row = r, Column = c }; } while (_dic.ContainsKey(pos)); _dic.Add(pos, null); _recent = pos; return pos; }
private void Attack(string playerName, Position pos, bool isHit) { //TxtContent.Text += string.Format("{0} attacks at ({1},{2}), {3}\r\n", playerName, pos.Row, pos.Column, isHit? "hit":"missed"); }