Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Scanner netbean = new Scanner(System.in);
- int board[][] = new int[8][8];
- int player=1;
- int x=0;
- Functions.draw(board);
- do {
- //inputs
- player=1;
- do {
- System.out.println("Player 1 enter a letter: ");
- x=(netbean.next().toUpperCase().charAt(0))-65;
- } while (Functions.possible(board, x) != true);
- Functions.drop(board, x, player);
- Functions.draw(board);
- //game end statements
- if (Functions.checkdone(board, x)) {
- System.out.println("Tie");
- break;
- }
- if (Functions.checkwinZ(board, player)) {
- System.out.println("Player 1 wins");
- break;
- }
- if (Functions.checkwinS(board, player)) {
- System.out.println("Player 1 wins");
- break;
- }
- if (Functions.checkwinV(board, player)) {
- System.out.println("Player 1 wins");
- break;
- }
- if (Functions.checkwinUV(board, player)) {
- System.out.println("Player 1 wins");
- break;
- }
- player=2;
- //player2 inputs
- do {
- System.out.println("Player 2 enter a letter: ");
- x=(netbean.next().toUpperCase().charAt(0))-65;
- } while (Functions.possible(board, x) != true);
- Functions.drop(board, x, player);
- Functions.draw(board);
- //game end statements
- if (Functions.checkdone(board, x)) {
- System.out.println("Tie");
- break;
- }
- if (Functions.checkwinZ(board, player)) {
- System.out.println("Player 2 wins");
- break;
- }
- if (Functions.checkwinS(board, player)) {
- System.out.println("Player 2 wins");
- break;
- }
- if (Functions.checkwinV(board, player)) {
- System.out.println("Player 2 wins");
- break;
- }
- if (Functions.checkwinUV(board, player)) {
- System.out.println("Player 2 wins");
- break;
- }
- } while (1==1);
- public static String letters = "ABCDEFGH";
- public static int k = 0;
- public static boolean win=false;
- public static void drop(int board[][], int x, int player) {
- for (int i = 7; i > -1; i--) {
- if (board[x][i] == 0) {
- if (player==1) {
- board[x][i] = 1;
- k = i;
- }
- if (player==2) {
- board[x][i] = 2;
- }
- break;
- }
- }
- }
- public static boolean possible(int board[][], int x) {
- boolean node = false;
- for (int i = 7; i > -1; i--) {
- if (board[x][i] == 0) {
- node = true;
- break;
- }
- }
- return node;
- }
- public static void draw(int board[][]) {
- System.out.println("");
- for (int i = 0; i < 8; i++) {
- for (int j = 0; j < 8; j++) {
- System.out.print(board[j][i] + " ");
- }
- System.out.println("");
- }
- for (int i = 0; i <letters.length(); i++) {
- System.out.print(letters.substring(i,i+1) + " ");
- }
- System.out.println("\n");
- }
- public static boolean checkdone(int board[][], int x) {
- boolean end = true;
- for (int i = 0; i < 8; i++) {
- for (int j = 0; j < 8; j++) {
- if (board[j][i] == 0) {
- end = false;
- }
- }
- }
- return end;
- }
- public static boolean checkwinZ(int board[][], int player){
- for (int i = 0; i <board.length-2; i++) {
- for (int j = 0; j <board[0].length-2; j++) {
- if (board[i][j]==player && board[i][j]==board[i+1][j] && board[i][j]==board[i+1][j+1] && board[i][j]==board[i+1][j+2] && board[i][j]==board[i+2][j+2]) {
- win=true;
- }
- }
- }
- return win;
- }
- public static boolean checkwinS(int board[][], int player){
- for (int i = 0; i <board.length-2; i++) {
- for (int j = 2; j <8; j++) {
- if (board[i][j]==player && board[i][j]==board[i+1][j] && board[i][j]==board[i+1][j-1] && board[i][j]==board[i+1][j-2] && board[i][j]==board[i+2][j-2]) {
- win=true;
- }
- }
- }
- return win;
- }
- public static boolean checkwinV(int board[][], int player){
- for (int i = 0; i <4; i++) {
- for (int j = 0; j <board[0].length-2; j++) {
- if (board[i][j]==player && board[i][j]==board[i+1][j+1] && board[i][j]==board[i+2][j+2] && board[i][j]==board[i+3][j+1] && board[i][j]==board[i+4][j]) {
- win=true;
- }
- }
- }
- return win;
- }
- public static boolean checkwinUV(int board[][], int player){
- for (int i = 0; i <4; i++) {
- for (int j = 2; j<8; j++) {
- if (board[i][j]==player && board[i][j]==board[i+1][j-1] && board[i][j]==board[i+2][j-2] && board[i][j]==board[i+3][j-1] && board[i][j]==board[i+4][j]) {
- win=true;
- }
- }
- }
- return win;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement