diff options
| author | Jakob L. Kreuze <jakob@memeware.net> | 2018-12-17 10:16:09 -0500 |
|---|---|---|
| committer | Jakob L. Kreuze <jakob@memeware.net> | 2018-12-17 10:16:09 -0500 |
| commit | edfed0cf5065595d982c6a1d21f7c77b173ee2b5 (patch) | |
| tree | 7689b7daabece5767f728540abace29f3efb4429 /app/src/main/java/space/jakob/mines/SetupActivity.kt | |
| parent | 1321cdd4ef707c6375cbb6ea6d49f3839a2a4a53 (diff) | |
Implement functionality in SetupActivity
Diffstat (limited to 'app/src/main/java/space/jakob/mines/SetupActivity.kt')
| -rw-r--r-- | app/src/main/java/space/jakob/mines/SetupActivity.kt | 83 |
1 files changed, 82 insertions, 1 deletions
diff --git a/app/src/main/java/space/jakob/mines/SetupActivity.kt b/app/src/main/java/space/jakob/mines/SetupActivity.kt index 002b6e6..61b678c 100644 --- a/app/src/main/java/space/jakob/mines/SetupActivity.kt +++ b/app/src/main/java/space/jakob/mines/SetupActivity.kt @@ -12,19 +12,100 @@ package space.jakob.mines +import android.app.AlertDialog +import android.content.DialogInterface import android.support.v7.app.AppCompatActivity import android.os.Bundle import android.widget.Button +import android.widget.EditText import android.content.Intent +private const val MIN_WIDTH = 8 +private const val MIN_HEIGHT = 8 +private const val MIN_MINES = 10 +private const val MAX_WIDTH = 30 +private const val MAX_HEIGHT = 24 + class SetupActivity : AppCompatActivity() { + /** + * Shows a basic notification dialog with no callbacks. + * + * @param[message] The message to show in the dialog. + */ + private fun popMessage(message: String) { + val builder = AlertDialog.Builder(this) + builder.setMessage(message) + builder.setNeutralButton( + "Okay...", + object : DialogInterface.OnClickListener { + override fun onClick(dialog: DialogInterface, id: Int) { + dialog.cancel() + } + } + ) + + builder.create().show() + } + override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.activity_setup) + // Inputs + val heightEntry = findViewById(R.id.heightEntry) as EditText + val widthEntry = findViewById(R.id.widthEntry) as EditText + val minesEntry = findViewById(R.id.minesEntry) as EditText + + // Difficulties + val selectEasy = findViewById(R.id.selectEasy) as Button + val selectIntermediate = findViewById(R.id.selectIntermediate) as Button + val selectExpert = findViewById(R.id.selectExpert) as Button + + selectEasy.setOnClickListener { + heightEntry.setText("8") + widthEntry.setText("8") + minesEntry.setText("10") + } + selectIntermediate.setOnClickListener { + heightEntry.setText("16") + widthEntry.setText("16") + minesEntry.setText("40") + } + selectExpert.setOnClickListener { + heightEntry.setText("16") + widthEntry.setText("30") + minesEntry.setText("99") + } + + val goButton = findViewById(R.id.goButton) as Button + goButton.setOnClickListener { - startActivity(Intent(this, GameActivity::class.java)) + val width = widthEntry.text.toString().toInt() + val height = heightEntry.text.toString().toInt() + val mines = minesEntry.text.toString().toInt() + + val maxMines = (width - 1) * (height - 1) + + if (width < MIN_WIDTH) { + popMessage("Currently, the minimum allowable width is ${MIN_WIDTH}.") + } else if (width > MAX_WIDTH) { + popMessage("Currently, the maximum allowable width is ${MAX_WIDTH}.") + } else if (height < MIN_HEIGHT) { + popMessage("Currently, the minimum allowable height is ${MIN_HEIGHT}.") + } else if (height > MAX_HEIGHT) { + popMessage("Currently, the maximum allowable height is ${MAX_HEIGHT}.") + } else if (mines < MIN_MINES) { + popMessage("The number of mines must be at least ${MIN_MINES}.") + } else if (mines > maxMines) { + popMessage("Seriously, tone it back. That's waaaay too many mines.") + } else { + startActivity(with (Intent(this, GameActivity::class.java)) { + putExtra("WIDTH", width) + putExtra("HEIGHT", height) + putExtra("MINES", mines) + }) + } } } } |