Ejemplo n.º 1
0
        public Game(bool trial)
        {
            this.trial = trial;

            board      = new Board();
            scorer     = new Scorer();
            resetEvent = new AutoResetEvent(false);

            cellPrintFn = (cell) => {
                if (cell.HitCount > 0)
                {
                    if (cell.Target == null)
                    {
                        return("x");
                    }
                    return("^");
                }
                return(" ");
            };

            showShipsFn = (cell) =>
            {
                if (cell.Target != null)
                {
                    return("*");
                }
                return("-");
            };
        }
Ejemplo n.º 2
0
 private static void setPrintContent(Cell[,] cells, CellPrintFunction cellPrintFn, int u1, int u2, int l1, int l2, string[,] printArray)
 {
     for (int row = l1 + 1; row < u1 + 2; row++)
     {
         for (int col = l2 + 1; col < u2 + 2; col++)
         {
             printArray[row, col] = cellPrintFn(cells[row - 1, col - 1]);
         }
     }
 }
Ejemplo n.º 3
0
        public static void Print(Cell[,] cells, CellPrintFunction cellPrintFn)
        {
            int u1 = cells.GetUpperBound(0);
            int u2 = cells.GetUpperBound(1);
            int l1 = cells.GetLowerBound(0);
            int l2 = cells.GetLowerBound(1);

            string[,] printArray = new string[u1 + 2, u2 + 2];
            setPrintContent(cells, cellPrintFn, u1, u2, l1, l2, printArray);
            setPrintRowHeading(printArray);
            setPrintColHeading(printArray);
            printIt(printArray);
        }