Untitled

mail@pastecode.io avatar
unknown
plain_text
7 months ago
2.0 kB
0
Indexable
Never
class Solution : ComponentActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContent {
            MyApplicationTheme {

                SudokuGame1()
            }
        }
    }
}


@Composable
fun SudokuGame1() {

    Column(
        modifier = Modifier.fillMaxSize(),
        verticalArrangement = Arrangement.Center,
        horizontalAlignment = Alignment.CenterHorizontally
    ) {

        // Display the provided Sudoku puzzle
        for (row in board.indices) {
            SudokuRow1(board[row])
        }

        Spacer(modifier = Modifier.height(16.dp))
    }
}


@Composable
fun SudokuRow1(row: IntArray) {
    Row(
        modifier = Modifier.padding(1.dp),
        verticalAlignment = Alignment.CenterVertically
    ) {
        for (col in row.indices) {
            SudokuCell1(row[col])
        }
    }
}

@Composable
fun SudokuCell1(value: Int) {
    val density = LocalDensity.current.density

    // Set the text color based on whether the number is solved or passed
//    val textColor = if (value != 0 && numbers.contains(value)) {
//        println("Value: $value is in numbers.")
//        Color.Black
//    } else {
//        println("Value: $value is not in numbers.")
//        Color.Blue
//    }


    val borderModifier = Modifier.border(
        width = 1.dp,
        color = Color.Gray
    )

    Box(
        modifier = Modifier
            .background(Color.White)
            .padding(1.dp)
            .width(15.dp * density)
            .height(15.dp * density)
            .then(borderModifier)
    ) {
        Text(
            text = if (value != 0) value.toString() else "",
            modifier = Modifier
                .fillMaxSize()
                .padding(4.dp),
            style = TextStyle(
                fontSize = 20.sp,
                fontWeight = FontWeight.Bold,
                textAlign = TextAlign.Center,
                color = Color.Blue
            )
        )
    }
}


Leave a Comment