MCPcopy Create free account
hub / github.com/PrajaktaSathe/Java / is_finished

Method is_finished

Programs/Games/peg-solitaire/PegSolitaire.java:605–669  ·  view source on GitHub ↗

Method to determine if the game is finished. @return boolean to specify if the game is finished.

()

Source from the content-addressed store, hash-verified

603 * @return boolean to specify if the game is finished.
604 */
605 public boolean is_finished(){
606 boolean flag = true;
607
608 //Checking if the game ended
609 for (int i = 2; i < board.length; ++i){
610 for (int j = 0; j < board.length; ++j){
611 if (board[i][j].getBackground() == Color.BLACK){
612 if (board[i-1][j].getBackground()==Color.BLACK && board[i-2][j].getBackground() == Color.GRAY) flag = false;
613 }
614 }
615 }
616 for (int i = 0; i < board.length-2; ++i){
617 for (int j = 0; j < board.length; ++j){
618 if (board[i][j].getBackground()==Color.BLACK){
619 if (board[i+1][j].getBackground()==Color.BLACK && board[i+2][j].getBackground() == Color.GRAY) flag = false;
620 }
621 }
622 }
623 for (int i = 0; i < board.length; ++i){
624 for (int j = 2; j < board.length; ++j){
625 if (board[i][j].getBackground()==Color.BLACK){
626 if (board[i][j-1].getBackground()==Color.BLACK && board[i][j-2].getBackground() == Color.GRAY) flag = false;
627 }
628 }
629 }
630 for (int i = 0; i < board.length; ++i){
631 for (int j = 0; j < board.length-2; ++j){
632 if (board[i][j].getBackground()==Color.BLACK){
633 if (board[i][j+1].getBackground()==Color.BLACK && board[i][j+2].getBackground() == Color.GRAY) flag = false;
634 }
635 }
636 }
637 if (boardType == 6){
638 //Upleft for triangle board
639 for (int i = 2; i < board.length; ++i){
640 for (int j = 2; j < board.length; ++j){
641 if (board[i][j].getBackground()==Color.BLACK){
642 if (board[i-1][j-1].getBackground()==Color.BLACK && board[i-2][j-2].getBackground()==Color.GRAY) flag = false;
643 }
644 }
645 }
646
647 //Downright for triangle board
648 for (int i = 0; i < board.length-2; ++i){
649 for (int j = 0; j < board.length-2; ++j){
650 if (board[i][j].getBackground()==Color.BLACK){
651 if (board[i+1][j+1].getBackground()==Color.BLACK && board[i+2][j+2].getBackground()==Color.GRAY) flag = false;
652 }
653 }
654 }
655 }
656
657 //If game is finished
658 if (flag){
659 //Calculating the score and prints the message.
660 score=0;
661 for (int i = 0; i < board.length; ++i)
662 for (int j = 0; j < board[0].length; ++j)

Callers 1

autoOneMethod · 0.95

Calls

no outgoing calls

Tested by

no test coverage detected