Skip to content

Commit

Permalink
Add level difficulty and progression of level. Add levels design.
Browse files Browse the repository at this point in the history
  • Loading branch information
haxpor committed Jun 23, 2017
1 parent a640a28 commit 778ac96
Show file tree
Hide file tree
Showing 4 changed files with 115 additions and 16 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
buildscript {
ext {
kotlinVersion = '1.1.2-5'
kotlinVersion = '1.1.3'
}
repositories {
mavenLocal()
Expand Down
5 changes: 3 additions & 2 deletions core/src/io/wasin/omo/Game.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import com.badlogic.gdx.ApplicationAdapter
import com.badlogic.gdx.Gdx
import com.badlogic.gdx.graphics.g2d.SpriteBatch
import io.wasin.omo.handlers.*
import io.wasin.omo.states.Play

class Game : ApplicationAdapter() {

Expand Down Expand Up @@ -37,8 +38,8 @@ class Game : ApplicationAdapter() {

res.loadAtlas("pack.atlas", "pack")

// set to begin with Play state
gsm.pushState(GameStateManager.PLAY)
// begin with Easy difficulty of Play state
gsm.pushState(Play(gsm, Play.Difficulty.EASY))
}

override fun render() {
Expand Down
6 changes: 5 additions & 1 deletion core/src/io/wasin/omo/handlers/GameStateManager.kt
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class GameStateManager(game: Game){

private fun getState(state: Int): GameState? {
if (state == MAINMENU) return Mainmenu(this)
else if (state == PLAY) return Play(this)
else if (state == PLAY) return Play(this, Play.Difficulty.EASY) // default to Easy difficulty for barebone constructor
return null
}

Expand All @@ -51,6 +51,10 @@ class GameStateManager(game: Game){
this.pushState(state)
}

fun pushState(gameState: GameState) {
this.gameStates.push(gameState)
}

fun pushState(state: Int) {
this.gameStates.push(this.getState(state))
}
Expand Down
118 changes: 106 additions & 12 deletions core/src/io/wasin/omo/states/Play.kt
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,22 @@ import io.wasin.omo.ui.Tile
/**
* Created by haxpor on 6/13/17.
*/
class Play(gsm: GameStateManager): GameState(gsm) {
class Play(gsm: GameStateManager, difficulty: Difficulty): GameState(gsm) {

object MultiTouch {
const val MAX_FINGERS: Int = 2
}

enum class Difficulty {
EASY,
NORMAL,
HARD,
INSANE
}

private var level: Int = 1
private var maxLevel: Int = 3
private var difficulty: Difficulty = difficulty

private var tiles: ArrayList<ArrayList<Tile>> = arrayListOf()
private var tileSize: Float = -1f
Expand All @@ -29,19 +44,17 @@ class Play(gsm: GameStateManager): GameState(gsm) {

private var prevPosTouched: kotlin.Array<Pair<Int, Int>> = kotlin.Array(MultiTouch.MAX_FINGERS, { _ -> Pair(-1, -1)})

object MultiTouch {
const val MAX_FINGERS: Int = 2
}

init {

// initially create empty array for selected, and finished first
selected = Array()
finished = Array()

val args = getArgs(difficulty)

// create board
createBoard(3, 3)
createFinished()
createBoard(args[0], args[1])
createFinished(args[2])
}

override fun handleInput() {
Expand Down Expand Up @@ -76,14 +89,18 @@ class Play(gsm: GameStateManager): GameState(gsm) {

// if finished then restart the board again
if (checkIsFinished()) {
createBoard(3, 3)
createFinished()
level++
if (level > maxLevel) {
done()
}
val args = getArgs(difficulty)
createBoard(args[0], args[1])
createFinished(args[2])
}
}

// save for previous touched position
prevPosTouched[i] = Pair(row, col)
Gdx.app.log("Play", "Touched at $row, $col")
}
}

Expand Down Expand Up @@ -185,18 +202,19 @@ class Play(gsm: GameStateManager): GameState(gsm) {
}
}

private fun createFinished() {
private fun createFinished(numTilesToLight: Int) {

selected.clear()
finished.clear()

showing = true
showTimer = 0f

var numTilesToLight = 4
for (i in 0..numTilesToLight-1) {

var row = 0
var col = 0

do {
row = MathUtils.random(tiles.count() - 1)
col = MathUtils.random(tiles[row].count() - 1)
Expand All @@ -218,4 +236,80 @@ class Play(gsm: GameStateManager): GameState(gsm) {

return true
}

private fun getArgs(difficulty: Difficulty): kotlin.Array<Int> {
// create arguments
// arguments are as follows
// => number of rows, number of columns, and num tiles to light
val args = kotlin.Array(3, { _ -> 0 })

if (difficulty == Difficulty.EASY) {
args[0] = 3
args[1] = 3
if (level in 1..3) {
args[2] = 3
}
else if (level in 4..5){
args[2] = 4
}
maxLevel = 5
}
else if (difficulty == Difficulty.NORMAL) {
args[0] = 4
args[1] = 4
if (level in 1..2) {
args[2] = 4
}
else if (level in 3..4) {
args[2] = 5
}
else if (level in 5..6) {
args[2] = 6
}
maxLevel = 6
}
else if (difficulty == Difficulty.HARD) {
args[0] = 5
args[1] = 5
if (level in 1..2) {
args[2] = 6
}
else if (level in 3..4) {
args[2] = 7
}
else if (level in 5..6) {
args[2] = 8
}
else if (level in 7..8) {
args[2] = 9
}
maxLevel = 8
}
else if (difficulty == Difficulty.INSANE) {
args[0] = 6
args[1] = 6
if (level in 1..2) {
args[2] = 8
}
else if (level in 3..4) {
args[2] = 9
}
else if (level in 5..6) {
args[2] = 10
}
else if (level in 7..8) {
args[2] = 11
}
else if (level in 9..10) {
args[2] = 12
}
maxLevel = 10
}

return args
}

private fun done() {

}
}

0 comments on commit 778ac96

Please sign in to comment.