'Kotlin: ArrayList verification
I am new to developping in kotlin and for my class, I have a tic tac toe game to create. I initialy create a MutableListOf at the top of my page that contain all the "box" of my playing grid.
private var playingBoard:MutableList<ImageView> = ArrayList()
then i had all the boxes of the grid to the list using a function like so :
private fun activerGrilleDeJeu() {
playingBoard.add(view.a1)
playingBoard.add(view.a2)
playingBoard.add(view.a3)
playingBoard.add(view.b1)
playingBoard.add(view.b2)
playingBoard.add(view.b3)
playingBoard.add(view.c1)
playingBoard.add(view.c2)
playingBoard.add(view.c3)
}
I then have a function that check for a victory when i click on an image view on the board but my problem is that function never seem's to trigger :
private fun victoryListener(): Boolean{
//Horizontal victory
if(playingBoard[0] == playingBoard[1] && playingBoard[0] == playingBoard[2] && playingBoard[1] == playingBoard[2]){
return true
}
this is how i call that function
grilleDeJeu[0].setOnClickListener {
ajouterjeton(grilleDeJeu[0])
if(victoryListener()){
if(tourPresent == joueur1){
joueur1.score += 1
tourPresent = joueur1
resultat("Victoire de ${joueur1.prenom}")
}
else{
joueur2.score += 1
tourPresent = joueur2
resultat("Victoire de ${joueur2.prenom}")
}
}
I had the same function for every "box" of the grid so I didn't had all of them but if you guy's need the full code just ask and i'll post it.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
