Thank you so much. I needed this for a University module I'm doing. I just have to add additional features to it now, which shouldn't be too bad. If I can work a quarter as quickly as you one day I'll be happy.
Hey! For those finding this tutorial, you may need to change up the "fun boardTapped(view: View)" function, as it no longer works in the current version (literally crashes if you press anything) My work around was setting each button like so in the oncreate function: binding.a1.setOnClickListener(this) binding.a2.setOnClickListener(this) etc. Then create override fun onClick(v: View?) { addToBoard(v as Button) } instead of the "fun boardTapped(view: View)" function be sure to also add: class MainActivity : AppCompatActivity(), View.OnClickListener {
Also, to get around draw popping up if you fill-up the board but also win I changed: override fun onClick(v: View?) { addToBoard(v as Button) var victory = false if(checkForVictory(NOUGHT)){ victory = true noughtsScore ++ result("Noughts Win!") } if(checkForVictory(CROSS)){ victory = true crossesScore ++ result("Crosses Win!") } if(fullBoard()) { if (victory == false) { result("Draw") } }
Hey Cal, I think you should make a playlist about layout design using XML, I saw lots of RU-vid tutorials but I'm not able to find any proper playlist for learning layout or android UI design using XML. Thank you.