DefaultRules.kt 4.87 KB
Newer Older
1
2
package com.mygdx.game.model.gamemodes.rules

3
import com.badlogic.gdx.Gdx
4
import com.badlogic.gdx.math.Vector3
5
import com.mygdx.game.Constants
6
7
8
import com.mygdx.game.model.AbstractRules

class DefaultRules: AbstractRules() {
9
    override var startFields = generateStartFields()
10
    override var moveRange = 1
11
    override var jumpRange = 1
12

13
14
    override fun getPlayerStartfields(boardSlot: Int): List<Vector3> {
        return startFields[boardSlot]
15
16
    }

17
18
    override fun getPlayerTargetFields(boardSlot: Int): List<Vector3> {
        var slot = boardSlot
19
20

        for (i in 0..2) {
21
            slot++
22
            // Wrap around to first player
23
24
            if(slot == 6) {
                slot = 0
25
26
            }
        }
27
        return startFields[slot]
28
29
    }

30
    // Sequence: top, upperright, lowerright, bottom, lowerleft, upperleft
31
32
33
    override fun generateStartFields(playerCount: Int): List<List<Vector3>> {
        val startFields: MutableList<List<Vector3>> = mutableListOf()
        val allStartFields: List<List<Vector3>> = listOf(
34
35
36
                listOf(Vector3(1F, 4F, -5F), Vector3(2F, 3F, -5F), Vector3(3F, 2F, -5F), Vector3(4F, 1F, -5F),
                        Vector3(2F, 4F, -6F), Vector3(3F, 3F, -6F), Vector3(4F, 2F, -6F), Vector3(3F, 4F, -7F),
                        Vector3(4F, 3F, -7F), Vector3(4F, 4F, -8F)
37
                ),
38
39
40
                listOf(Vector3(5F, -1F, -4F), Vector3(5F, -2F, -3F), Vector3(5F, -3F, -2F), Vector3(5F, -4F, -1F),
                        Vector3(6F, -2F, -4F), Vector3(6F, -3F, -3F), Vector3(6F, -4F, -2F), Vector3(7F, -3F, -4F),
                        Vector3(7F, -4F, -3F), Vector3(8F, -4F, -4F)
41
                ),
42
                listOf(Vector3(4F, -5F, 1F), Vector3(3F, -5F, 2F), Vector3(2F, -5F, 3F), Vector3(1F, -5F, 4F),
43
                        Vector3(4F, -6F, 2F), Vector3(3F, -6F, 3F), Vector3(2F, -6F, 4F), Vector3(4F, -7F, 3F),
44
                        Vector3(3F, -7F, 4F), Vector3(4F, -8F, 4F)
45
                ),
46
47
48
                listOf(Vector3(-4F, -1F, 5F), Vector3(-3F, -2F, 5F), Vector3(-2F, -3F, 5F), Vector3(-1F, -4F, 5F),
                        Vector3(-4F, -2F, 6F), Vector3(-3F, -3F, 6F), Vector3(-2F, -4F, 6F), Vector3(-4F, -3F, 7F),
                        Vector3(-3F, -4F, 7F), Vector3(-4F, -4F, 8F)
49
                ),
50
51
52
                listOf(Vector3(-5F, 4F, 1F), Vector3(-5F, 3F, 2F), Vector3(-5F, 2F, 3F), Vector3(-5F, 1F, 4F),
                        Vector3(-6F, 4F, 2F), Vector3(-6F, 3F, 3F), Vector3(-6F, 2F, 4F), Vector3(-7F, 4F, 3F),
                        Vector3(-7F, 3F, 4F), Vector3(-8F, 4F, 4F)
53
                ),
54
55
56
                listOf(Vector3(-1F, 5F, -4F), Vector3(-2F, 5F, -3F), Vector3(-3F, 5F, -2F), Vector3(-4F, 5F, -1F),
                        Vector3(-2F, 6F, -4F), Vector3(-3F, 6F, -3F), Vector3(-4F, 6F, -2F), Vector3(-3F, 7F, -4F),
                        Vector3(-4F, 7F, -3F), Vector3(-4F, 8F, -4F)
57
                )
58
        )
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77

        when (playerCount) {
            2 -> {
                startFields.add(allStartFields[0])
                startFields.add(allStartFields[3])
            }
            4 -> {
                startFields.add(allStartFields[1])
                startFields.add(allStartFields[2])
                startFields.add(allStartFields[4])
                startFields.add(allStartFields[5])
            }
            6 -> startFields.addAll(allStartFields)
            else -> {
                print("ERROR: DefaultBoard needs 2, 4 or 6 players.")
            }
        }

        return startFields
78
    }
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103

    override fun getUsedBoardSlots(playerCount: Int): List<Int> {
        return when (playerCount) {
            2 -> {
                listOf(0, 3)
            }
            4 -> {
                listOf(1, 2, 4, 5)
            }
            else -> {
                listOf(0, 1, 2, 3, 4, 5)
            }
        }
    }

    override fun getPlayerNameCoordinates(hex_side_length: Float): List<List<Float>> {
        return listOf(
                listOf(Gdx.graphics.width / 2f - Constants.PLAYER_NAME_TEXT_FIELD_WIDTH - 2.5f * hex_side_length, Gdx.graphics.height - Constants.PLAYER_NAME_TEXT_FIELD_HEIGHT - 1.5f * hex_side_length),
                listOf(Gdx.graphics.width / 2f + Constants.PLAYER_NAME_TEXT_FIELD_WIDTH + 4f * hex_side_length, Gdx.graphics.height / 2f + 4 * hex_side_length),
                listOf(Gdx.graphics.width / 2f + Constants.PLAYER_NAME_TEXT_FIELD_WIDTH + 4f * hex_side_length, Gdx.graphics.height / 2f - 5 * hex_side_length),
                listOf(Gdx.graphics.width / 2f - Constants.PLAYER_NAME_TEXT_FIELD_WIDTH - 2.5f * hex_side_length, 1.5f * hex_side_length),
                listOf(Gdx.graphics.width / 2f - Constants.PLAYER_NAME_TEXT_FIELD_WIDTH - 12f * hex_side_length, Gdx.graphics.height / 2f - 5 * hex_side_length),
                listOf(Gdx.graphics.width / 2f - Constants.PLAYER_NAME_TEXT_FIELD_WIDTH - 12f * hex_side_length, Gdx.graphics.height / 2f + 4 * hex_side_length)
        )
    }
104
105
}