Ejemplo n.º 1
0
        public static bool containsRightAmountOfShips(char[,] charBoard, ref List <ShipPlacement> ships)
        {
            List <string> rows = BoardUtils.generateRows(charBoard);
            List <string> cols = BoardUtils.generateCols(charBoard);

            int[] shipCounter = new int[5] {
                0, 0, 0, 0, 0
            };
            List <ShipPlacement> newShips = new List <ShipPlacement> ();

            countShipsInStringList(rows, ref shipCounter, true, newShips);
            countShipsInStringList(cols, ref shipCounter, false, newShips);

            string count = "";

            foreach (int i in shipCounter)
            {
                count += "  " + i;
            }
            //	Main.GameMaster.singleton.debugPrint (count);

            foreach (int i in shipCounter)
            {
                if (i != 1)
                {
                    return(false);
                }
            }

            ships = newShips;
            return(true);
        }
Ejemplo n.º 2
0
 private bool isValidStartBoard(string startBoard, out char[,] charBoard, ref List <ShipPlacement> ships)
 {
     if (BoardUtils.charBoardFromString(startBoard, out charBoard) == false)
     {
         return(false);
     }
     if (BoardUtils.containsRightAmountOfShips(charBoard, ref ships) == false)
     {
         return(false);
     }
     charBoard = BoardUtils.charBoardFromShipList(ships);
     return(true);
 }
Ejemplo n.º 3
0
        public char fireAtBoard(int target, ref ShipPlacement potentialShip)
        {
            BoardUtils.printCharBoard(charBoard);
            int[] pos = BoardUtils.numberToCoord(target);
            //	Main.GameMaster.singleton.debugPrint ("Fire at: " + pos[0] + "." + pos[1] + "   ****************");
            char hitSign = charBoard [pos [0], pos [1]];

            if (char.IsNumber(hitSign) && hitSign != GameConstants.EMPTYCHAR)              // We got a new hit
            {
                hitSign = handleHit(pos, ref potentialShip);
            }
            else if (hitSign == GameConstants.EMPTYCHAR)
            {
                charBoard [pos [0], pos [1]] = GameConstants.MISSCHAR;
            }
            else               //We hit a target we have already hit before
            {
                hitSign = GameConstants.MISSCHAR;
            }

            //	Main.GameMaster.singleton.debugPrint ("Target sign: " + hitSign);
            return(hitSign);
        }
Ejemplo n.º 4
0
 public void createEmptyTargetBoard()
 {
     charBoard = BoardUtils.generateEmptyBoard();
 }