Esempio n. 1
0
  void CheckDiagonal1(Graphics canvas) {
    // Check diagonal 1

    for (int nRow = NUMROWS - 1; nRow >= 0; nRow--) {
      int nCol = 0;

      int nThisRow = nRow;
      int nThisCol = nCol;

      int nColCount = 0;

      while (nThisCol < NUMCOLS && nThisRow < NUMROWS) {
        if (m_nBoard[nThisRow][nThisCol] != 0) {
          nColCount++;
        }
        nThisCol++;
        nThisRow++;
      }

      if (nColCount > 1) {
        canvas.drawLine(
            BOARDLEFT + nCol * SQUAREWIDTH + (SQUAREWIDTH / 2),
            BOARDTOP + nRow * SQUAREHEIGHT + (SQUAREHEIGHT / 2),
            BOARDLEFT + (nThisCol - 1) * SQUAREWIDTH + (SQUAREWIDTH / 2),
            BOARDTOP + (nThisRow - 1) * SQUAREHEIGHT + (SQUAREHEIGHT / 2));

        m_bClash = true;
      }
    }

    for (int nCol = 1; nCol < NUMCOLS; nCol++) {
      int nRow = 0;

      int nThisRow = nRow;
      int nThisCol = nCol;

      int nColCount = 0;

      while (nThisCol < NUMCOLS && nThisRow < NUMROWS) {
        if (m_nBoard[nThisRow][nThisCol] != 0) {
          nColCount++;
        }
        nThisCol++;
        nThisRow++;
      }

      if (nColCount > 1) {
        canvas.drawLine(
            BOARDLEFT + nCol * SQUAREWIDTH + (SQUAREWIDTH / 2),
            BOARDTOP + nRow * SQUAREHEIGHT + (SQUAREHEIGHT / 2),
            BOARDLEFT + (nThisCol - 1) * SQUAREWIDTH + (SQUAREWIDTH / 2),
            BOARDTOP + (nThisRow - 1) * SQUAREHEIGHT + (SQUAREHEIGHT / 2));

        m_bClash = true;
      }
    }
  }
Esempio n. 2
0
 public void paint(Graphics canvas) {
   m_bClash = false;
   DrawSquares(canvas);
   canvas.setColor(Color.RED);
   CheckColumns(canvas);
   CheckRows(canvas);
   CheckDiagonal1(canvas);
   CheckDiagonal2(canvas);
   canvas.setColor(Color.BLUE);
   canvas.drawString(m_strStatus, BOARDLEFT, BOARDTOP + SQUAREHEIGHT * 8 + 20);
 }
Esempio n. 3
0
  void DrawSquares(Graphics canvas) {
    canvas.setColor(Color.BLACK);
    for (int nRow = 0; nRow < NUMROWS; nRow++) {
      for (int nCol = 0; nCol < NUMCOLS; nCol++) {
        canvas.drawRect(
            BOARDLEFT + nCol * SQUAREWIDTH,
            BOARDTOP + nRow * SQUAREHEIGHT,
            SQUAREWIDTH,
            SQUAREHEIGHT);

        if (m_nBoard[nRow][nCol] != 0) {
          canvas.drawImage(
              m_imgQueen,
              BOARDLEFT + nCol * SQUAREWIDTH + 8,
              BOARDTOP + nRow * SQUAREHEIGHT + 6,
              null);
        }
      }
    }
  }
Esempio n. 4
0
  void CheckRows(Graphics canvas) {
    for (int nRow = 0; nRow < NUMROWS; nRow++) {
      int nRowCount = 0;
      for (int nCol = 0; nCol < NUMCOLS; nCol++) {
        if (m_nBoard[nRow][nCol] != 0) {
          nRowCount++;
        }
      }
      if (nRowCount > 1) {
        canvas.drawLine(
            BOARDLEFT + (SQUAREWIDTH / 2),
            BOARDTOP + nRow * SQUAREHEIGHT + (SQUAREHEIGHT / 2),
            BOARDLEFT + 7 * SQUAREWIDTH + (SQUAREWIDTH / 2),
            BOARDTOP + nRow * SQUAREHEIGHT + (SQUAREHEIGHT / 2));

        m_bClash = true;
      }
    }
  }
Esempio n. 5
0
  void CheckColumns(Graphics canvas) {
    // Check all columns
    for (int nCol = 0; nCol < NUMCOLS; nCol++) {
      int nColCount = 0;
      for (int nRow = 0; nRow < NUMROWS; nRow++) {
        if (m_nBoard[nRow][nCol] != 0) {
          nColCount++;
        }
      }
      if (nColCount > 1) {
        canvas.drawLine(
            BOARDLEFT + nCol * SQUAREWIDTH + (SQUAREWIDTH / 2),
            BOARDTOP + (SQUAREHEIGHT / 2),
            BOARDLEFT + nCol * SQUAREWIDTH + (SQUAREWIDTH / 2),
            BOARDTOP + SQUAREHEIGHT * 7 + (SQUAREHEIGHT / 2));

        m_bClash = true;
      }
    }
  }