<file_sep>package com.example.bazile.morpion.game

val x = "X"
val o = "O"<file_sep>package com.example.bazile.morpion.Utils

import android.content.Context
import android.util.AttributeSet
import android.widget.TextView
import android.graphics.Typeface

class FippsTextView : TextView{

    constructor(context: Context?) : super(context){
        val face = Typeface.createFromAsset(context!!.assets, "fonts/fipps_regular.otf")
        this.typeface = face
    }

    constructor(context: Context?, attrs: AttributeSet?) : super(context, attrs){
        val face = Typeface.createFromAsset(context!!.assets, "fonts/fipps_regular.otf")
        this.typeface = face
    }
    constructor(context: Context?, attrs: AttributeSet?, defStyleAttr: Int) : super(context, attrs, defStyleAttr){
        val face = Typeface.createFromAsset(context!!.assets, "fonts/fipps_regular.otf")
        this.typeface = face
    }


}<file_sep>package com.example.bazile.morpion.game

val combinaison: Array<IntArray> = arrayOf(
        intArrayOf(1, 2, 3),
        intArrayOf(4, 5, 6),
        intArrayOf(7, 8, 9),
        intArrayOf(2, 5, 8),
        intArrayOf(1, 4, 7),
        intArrayOf(3, 6, 9),
        intArrayOf(1, 5, 9),
        intArrayOf(3, 5, 7)
)
<file_sep>package com.example.bazile.morpion.game

import android.support.v7.app.AppCompatActivity
import android.os.Bundle
import android.view.View
import android.widget.*
import com.example.bazile.morpion.R
import kotlinx.android.synthetic.main.activity_main.*


class MainActivity() : AppCompatActivity(), View.OnClickListener {

    private var board = mutableMapOf<Int, String>()
    private var Player = true
    private var winner: String = ""
    private var totalBoard = 9
    private val btn = arrayOfNulls<Button>(totalBoard)

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)
        initButon()
        replay_button.setOnClickListener {
            Toast.makeText(this, "Replay", Toast.LENGTH_LONG).show()
            newGame()
        }
    }

    private fun initButon() {
        for (i in 1..totalBoard) {
            val button = findViewById<Button>(resources.getIdentifier("button$i", "id", packageName))
            button.setOnClickListener(this)
            btn[i - 1] = button
        }
    }

    override fun onClick(view: View) {
        val buSelected: Button = view as Button
        var selected = 0
        when (buSelected.id) {
            R.id.button1 -> selected = 1
            R.id.button2 -> selected = 2
            R.id.button3 -> selected = 3
            R.id.button4 -> selected = 4
            R.id.button5 -> selected = 5
            R.id.button6 -> selected = 6
            R.id.button7 -> selected = 7
            R.id.button8 -> selected = 8
            R.id.button9 -> selected = 9
        }
        jouer(selected, buSelected)
        checkWinner()
    }

    private fun checkWinner(): Int {
        if (board.isNotEmpty()) {
            for (combine in combinaison) {
                val (a, b, c) = combine
                if (board[a] != null && board[a] == board[b] && board[a] == board[c] && board[a] == x) {
                    Toast.makeText(this, "Winner 1 ", Toast.LENGTH_LONG).show()
                    this.winner = board.toString()
                    return 10
                }

                if (board[a] != null && board[a] == board[b] && board[a] == board[c] && board[a] == o) {
                    Toast.makeText(this, "Winner 2 ", Toast.LENGTH_LONG).show()
                    this.winner = board.toString()
                    return 10
                }
            }
        }
        return 0
    }

    private fun jouer(selected: Int, buSelected: Button) {
        var cpt = 0
        if (!winner.isEmpty()) {
            Toast.makeText(this, "The game is over", Toast.LENGTH_LONG).show()
            return
        }

        for (i in 1..totalBoard) {
            if (board[i] != null) {
                cpt++
            }
        }
        if (cpt == 8)
            Toast.makeText(this, "Draw ", Toast.LENGTH_LONG).show()


        if (board[selected] != null) {
            Toast.makeText(this, "Don't play ", Toast.LENGTH_LONG).show()
            return
        }
        when {
            Player -> board[selected] = x
            else -> board[selected] = o
        }
        buSelected.text = board[selected]
        Player = !Player
    }


    private fun dejouer(selected: Int, buSelected: Button) {
        if (board[selected] == x || board[selected] == o) {
            board[selected] = ""
            buSelected.text = board[selected]
        }
    }


    private fun resetButton() {
        for (i in 1..totalBoard) {
            var button = btn[i - 1]
            button?.text = ""
            button?.isEnabled = true
        }
    }

    private fun newGame() {
        board = mutableMapOf()
        Player = true
        winner = ""
        resetButton()
    }
}
<file_sep>package com.example.bazile.morpion.game

import android.annotation.SuppressLint
import android.os.Bundle
import android.support.v7.app.AppCompatActivity
import android.widget.Toast
import com.example.bazile.morpion.R
import kotlinx.android.synthetic.main.activity_inscription.*
import java.util.regex.Pattern

class Inscription : AppCompatActivity() {

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_inscription)
        valider()
    }

    private fun checkMail():Boolean{
        return !edit_text_email.text.isEmpty() && isEmailValid(edit_text_email.text.toString())
    }

    private fun isEmailValid(email: String): Boolean {
        return Pattern.compile(
                "^(([\\w-]+\\.)+[\\w-]+|([a-zA-Z]|[\\w-]{2,}))@"
                        + "((([0-1]?[0-9]{1,2}|25[0-5]|2[0-4][0-9])\\.([0-1]?"
                        + "[0-9]{1,2}|25[0-5]|2[0-4][0-9])\\."
                        + "([0-1]?[0-9]{1,2}|25[0-5]|2[0-4][0-9])\\.([0-1]?"
                        + "[0-9]{1,2}|25[0-5]|2[0-4][0-9]))|"
                        + "([a-zA-Z]+[\\w-]+\\.)+[a-zA-Z]{2,4})$"
        ).matcher(email).matches()
    }

    private fun checkpassword():Boolean{
        return !edit_text_password.text.isEmpty() && edit_text_password.text.length >=6
    }

    @SuppressLint("ShowToast")
    private fun valider(){

        valider.setOnClickListener {
            if (checkMail() && checkpassword())
                Toast.makeText(this, "Le mail correct and password", Toast.LENGTH_LONG).show()
            else
                Toast.makeText(this, "Veilliez mettre un mail correct et un password de 6 mots", Toast.LENGTH_LONG).show()
        }
    }
}<file_sep>package com.example.bazile.morpion.game

import android.annotation.SuppressLint
import android.content.Intent
import android.os.Bundle
import android.support.v7.app.AppCompatActivity
import com.example.bazile.morpion.R
import kotlinx.android.synthetic.main.activity_title.*

@SuppressLint("Registered")
class TitleActivity : AppCompatActivity() {

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_title)
        onclick()
    }

    private fun onclick() {
        single_player.setOnClickListener {
            val intent = Intent(this, MainActivity::class.java)
            startActivity(intent)
        }

        multi_player.setOnClickListener {
            val intent = Intent(this, Inscription::class.java)
            startActivity(intent)
        }
    }
}