Professional Documents
Culture Documents
Spelbart Tre-I-Rad
Spelbart Tre-I-Rad
java
/*
package threeInARowGame;
import java.util.Scanner;
/**
*
* @author Benjamin Chinwe Detta ett spelprogram fr tv spelare. Den frsta att
* f sin tagg i tre platser i rad vinner spelet.
*/
// klass konstruktr
public ThreeInARowGame() {
+ "Den frsta att f sin tagg i tre platser i rad vinner spelet.");
System.out.println();
System.out.print("Vi har tv spelare X och O. Vlj som spelar frsta X eller O !: "
// while statement - att iterera att acceptera koordinaterna och kontrollera vinnar
while (moves <= 9) {
System.out.println("A Draw!");
1.1 of 10
break;
2015.09.24 01:17:03
C:/Android/chinwe/NetBeansProjects/ThreeInARowGame/src/threeInARowGame/ThreeInARowGame.java
t Properties.
vinner spelet.");
1.2 of 10
2015.09.24 01:17:03
C:/Android/chinwe/NetBeansProjects/ThreeInARowGame/src/threeInARowGame/ThreeInARowGame.java
break;
} else {
break;
moves++; // rknare fr att hlla rkningen p antalet drag under spelets gng
if (playerLebel.equals("X")) {
playerLebel = "O";
} else {
}
playerLebel = "X";
/**
}
2.1 of 10
2015.09.24 01:17:03
C:/Android/chinwe/NetBeansProjects/ThreeInARowGame/src/threeInARowGame/ThreeInARowGame.java
2.2 of 10
2015.09.24 01:17:03
C:/Android/chinwe/NetBeansProjects/ThreeInARowGame/src/threeInARowGame/ThreeInARowGame.java
// metod fr att visa spelplanen.
public void createBoard() {
System.out.println();
System.out.print("_");
} else {
}
System.out.print(table1[j]);
if (j < 2) {
System.out.print("|");
} else {
System.out.println();
r = enteredLetter.nextInt();
} else {
continue;
2015.09.24 01:17:03
C:/Android/chinwe/NetBeansProjects/ThreeInARowGame/src/threeInARowGame/ThreeInARowGame.java
3.2 of 10
2015.09.24 01:17:03
C:/Android/chinwe/NetBeansProjects/ThreeInARowGame/src/threeInARowGame/ThreeInARowGame.java
if ((r < 0) || (r > 2) || (c < 0) || (c > 2)) {
} else {
table[r][c] = playerAlphabet;
return;
int playDiagonal1 = 0;
int playDiagonal2 = 0;
continue;
if (table[i][j].equals(playerAlphabet)) {
playInRow++;
playInColumn[j]++;
if (i == j) {
playDiagonal1++;
} else if (i + j == 2) {
playDiagonal2++;
if (playInRow == 3) {
}
return true;
if (playDiagonal1 == 3 || playDiagonal2 == 3) {
}
4.1 of 10
return true;
2015.09.24 01:17:03
C:/Android/chinwe/NetBeansProjects/ThreeInARowGame/src/threeInARowGame/ThreeInARowGame.java
4.2 of 10
2015.09.24 01:17:03
C:/Android/chinwe/NetBeansProjects/ThreeInARowGame/src/threeInARowGame/ThreeInARowGame.java
if (playInColumn[i] == 3) {
}
}
5.1 of 10
return true;
return false;
2015.09.24 01:17:03
C:/Android/chinwe/NetBeansProjects/ThreeInARowGame/src/threeInARowGame/ThreeInARowGame.java
5.2 of 10
2015.09.24 01:17:03