Fixed: You can't place your move on the separators anymore

Improved: It is now much easier to select a field. Just say a number between 1 and 9.
This commit is contained in:
malik 2023-10-16 19:37:34 +02:00
parent 27d75a9bb5
commit 41bdc58b6d

View file

@ -23,10 +23,8 @@ fun multiplayer() {
var again = true
var playerOneCounter = 0
var playerTwoCounter = 0
var playerOneInput: String?
var playerOneInput1: String?
var playerTwoInput: String?
var playerTwoInput1: String?
var playerInput: String?
var playerFieldTemp = Point(-1,-1)
var playerOneField1 = Point(-1,-1)
var playerOneField2 = Point(-1,-1)
var playerOneField3 = Point(-1,-1)
@ -37,51 +35,6 @@ fun multiplayer() {
var playerTwoField3 = Point(-1,-1)
var playerTwoField4 = Point(-1,-1)
var playerTwoField5 = Point(-1,-1)
while(again){
gameField(playerOneField1, playerOneField2, playerOneField3, playerOneField4, playerOneField5, playerTwoField1, playerTwoField2, playerTwoField3, playerTwoField4, playerTwoField5)
println("Player 1: Choose your field:\nx: ")
playerOneInput = readlnOrNull()
println("y: ")
playerOneInput1 = readlnOrNull()
if(playerOneInput != null && playerOneInput1 != null) {
when(playerOneCounter){
0 -> playerOneField1 = Point(playerOneInput.toInt(),playerOneInput1.toInt())
1 -> playerOneField2 = Point(playerOneInput.toInt(),playerOneInput1.toInt())
2 -> playerOneField3 = Point(playerOneInput.toInt(),playerOneInput1.toInt())
3 -> playerOneField4 = Point(playerOneInput.toInt(),playerOneInput1.toInt())
4 -> playerOneField5 = Point(playerOneInput.toInt(),playerOneInput1.toInt())
else -> {
print("ERR: To many moves.")
}
}
playerOneCounter++
} else
println("ERR: Input was NULL")
gameField(playerOneField1, playerOneField2, playerOneField3, playerOneField4, playerOneField5, playerTwoField1, playerTwoField2, playerTwoField3, playerTwoField4, playerTwoField5)
println("Player 2! Choose your field:\nx: ")
playerTwoInput = readlnOrNull()
println("y: ")
playerTwoInput1 = readlnOrNull()
if(playerTwoInput != null && playerTwoInput1 != null) {
when(playerOneCounter){
0 -> playerTwoField1 = Point(playerTwoInput.toInt(),playerTwoInput1.toInt())
1 -> playerTwoField2 = Point(playerTwoInput.toInt(),playerTwoInput1.toInt())
2 -> playerTwoField3 = Point(playerTwoInput.toInt(),playerTwoInput1.toInt())
3 -> playerTwoField4 = Point(playerTwoInput.toInt(),playerTwoInput1.toInt())
4 -> playerTwoField5 = Point(playerTwoInput.toInt(),playerTwoInput1.toInt())
else -> {
print("ERR: To many moves.")
}
}
playerTwoCounter++
} else
println("ERR: Input was NULL")
}
}
fun gameField(playerOneField1: Point, playerOneField2: Point, playerOneField3: Point, playerOneField4: Point, playerOneField5: Point, playerTwoField1: Point, playerTwoField2: Point, playerTwoField3: Point, playerTwoField4: Point, playerTwoField5: Point) {
val gameField1 = Point(1, 1)
val gameField2 = Point(3, 1)
val gameField3 = Point(5, 1)
@ -92,6 +45,70 @@ fun gameField(playerOneField1: Point, playerOneField2: Point, playerOneField3: P
val gameField8 = Point(3, 5)
val gameField9 = Point(5, 5)
while(again){
gameField(gameField1, gameField2, gameField3, gameField4, gameField5, gameField6, gameField7, gameField8, gameField9, playerOneField1, playerOneField2, playerOneField3, playerOneField4, playerOneField5, playerTwoField1, playerTwoField2, playerTwoField3, playerTwoField4, playerTwoField5)
println("Player 1: Choose your field:")
playerInput = readlnOrNull()
if(playerInput != null) {
when(playerInput.toInt()){
1 -> playerFieldTemp = Point(gameField1)
2 -> playerFieldTemp = Point(gameField2)
3 -> playerFieldTemp = Point(gameField3)
4 -> playerFieldTemp = Point(gameField4)
5 -> playerFieldTemp = Point(gameField5)
6 -> playerFieldTemp = Point(gameField6)
7 -> playerFieldTemp = Point(gameField7)
8 -> playerFieldTemp = Point(gameField8)
9 -> playerFieldTemp = Point(gameField9)
}
when(playerOneCounter){
0 -> playerOneField1 = Point(playerFieldTemp)
1 -> playerOneField2 = Point(playerFieldTemp)
2 -> playerOneField3 = Point(playerFieldTemp)
3 -> playerOneField4 = Point(playerFieldTemp)
4 -> playerOneField5 = Point(playerFieldTemp)
else -> {
println("ERR: To many moves.")
}
}
playerOneCounter++
} else
println("ERR: Input was NULL")
gameField(gameField1, gameField2, gameField3, gameField4, gameField5, gameField6, gameField7, gameField8, gameField9, playerOneField1, playerOneField2, playerOneField3, playerOneField4, playerOneField5, playerTwoField1, playerTwoField2, playerTwoField3, playerTwoField4, playerTwoField5)
println("Player 2! Choose your field: ")
playerInput = readlnOrNull()
if(playerInput != null) {
when(playerInput.toInt()){
1 -> playerFieldTemp = Point(gameField1)
2 -> playerFieldTemp = Point(gameField2)
3 -> playerFieldTemp = Point(gameField3)
4 -> playerFieldTemp = Point(gameField4)
5 -> playerFieldTemp = Point(gameField5)
6 -> playerFieldTemp = Point(gameField6)
7 -> playerFieldTemp = Point(gameField7)
8 -> playerFieldTemp = Point(gameField8)
9 -> playerFieldTemp = Point(gameField9)
}
when(playerTwoCounter){
0 -> playerTwoField1 = Point(playerFieldTemp)
1 -> playerTwoField2 = Point(playerFieldTemp)
2 -> playerTwoField3 = Point(playerFieldTemp)
3 -> playerTwoField4 = Point(playerFieldTemp)
else -> {
println("ERR: To many moves.")
}
}
playerTwoCounter++
} else
println("ERR: Input was NULL")
}
}
fun gameField(gameField1: Point, gameField2: Point, gameField3: Point, gameField4: Point, gameField5: Point, gameField6: Point, gameField7: Point, gameField8: Point, gameField9: Point, playerOneField1: Point, playerOneField2: Point, playerOneField3: Point, playerOneField4: Point, playerOneField5: Point, playerTwoField1: Point, playerTwoField2: Point, playerTwoField3: Point, playerTwoField4: Point, playerTwoField5: Point) {
for (y in 1..5) {
for (x in 1..5) {
val p = Point(x, y)