Advertisement
Guest User

Untitled

a guest
Sep 19th, 2017
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.84 KB | None | 0 0
  1. private void checkWinDiagonal() {
  2. int rowStart = 0;
  3. int colStart = 0;
  4. int rowMax = 6;
  5. int colMax = 7;
  6. for (rowStart = 0; rowStart < rowMax; rowStart++) {
  7. int redCounter = 0;
  8. int yellowCounter = 0;
  9. int row, col;
  10. for (row = rowStart, col = 0; row < rowMax && col < colMax; row++, col++) {
  11. if (boardData[row][col] == Token.RED) {
  12. redCounter++;
  13. if (redCounter >= 4) {
  14. System.out.println("Red Player wins!");
  15. }
  16. } else if (boardData[row][col] == Token.YELLOW) {
  17. yellowCounter++;
  18. if (yellowCounter >= 4) {
  19. System.out.println("Yellow Player wins!");
  20. }
  21. } else {
  22. redCounter = 0;
  23. yellowCounter = 0;
  24. }
  25.  
  26. }
  27. }
  28.  
  29.  
  30. for (colStart = 1; colStart < colMax; rowStart++) {
  31. int redCounter = 0;
  32. int yellowCounter = 0;
  33. int row, col;
  34. for (row = 0, col = colStart; row < rowMax && col < colMax; row++, col++) {
  35. if (boardData[row][col] == Token.RED) {
  36. redCounter++;
  37. if (redCounter >= 4) {
  38. System.out.println("Red Player wins!");
  39. }
  40. } else if (boardData[row][col] == Token.YELLOW) {
  41. yellowCounter++;
  42. if (yellowCounter >= 4) {
  43. System.out.println("Yellow Player wins!");
  44. }
  45. } else {
  46. redCounter = 0;
  47. yellowCounter = 0;
  48. }
  49.  
  50. }
  51. }
  52. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement