Skip to content

Commit

Permalink
0.2.7; fixes #34
Browse files Browse the repository at this point in the history
  • Loading branch information
trolley813 committed Sep 22, 2018
1 parent 1407328 commit c5b493f
Show file tree
Hide file tree
Showing 14 changed files with 97 additions and 26 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
# Changelog
## 0.2.7 (2018-09-22)
- Cards which cannot be used now are greyed out (highly experimental)
- Stripped decks (24, 32 or 36 cards) cas be used along with 52-card deck
- Fixed issue #34 (team play checkbox was inaccessible when using Russian)
## 0.2.6 (2018-08-11)
- Fixed issue #32 when individual play could not finish sometimes
- Added information about places taken by the players onto the result screen.
Expand Down
4 changes: 2 additions & 2 deletions android/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="ru.hyst329.openfool"
android:versionCode="26"
android:versionName="0.2.6" >
android:versionCode="27"
android:versionName="0.2.7" >

<application
android:allowBackup="true"
Expand Down
1 change: 1 addition & 0 deletions android/assets/i18n/OpenFool.properties
Original file line number Diff line number Diff line change
Expand Up @@ -47,3 +47,4 @@ DefeatText=You lost the game.
DrawHeader=It's a draw.
DrawText=Friendship won!
PlayerPlace={0} took place {1}
DeckCardsCount=Number of cards:
3 changes: 2 additions & 1 deletion android/assets/i18n/OpenFool_cs.properties
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,5 @@ DrawHeader=Remíza.
VictoryText=Jste vyhráli!
DefeatText=Jste prohráli.
DrawText=Přátelství vyhrálo!
PlayerPlace={0} obsadil(a) {1}. místo
PlayerPlace={0} obsadil(a) {1}. místo
DeckCardsCount=Počet karet:
3 changes: 2 additions & 1 deletion android/assets/i18n/OpenFool_en.properties
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,5 @@ DrawHeader=It's a draw.
VictoryText=You won the game!
DefeatText=You lost the game.
DrawText=Friendship won!
PlayerPlace={0} took place {1}
PlayerPlace={0} took place {1}
DeckCardsCount=Number of cards:
3 changes: 2 additions & 1 deletion android/assets/i18n/OpenFool_ru.properties
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,5 @@ DrawHeader=Ничья.
VictoryText=Вы выиграли!
DefeatText=Вы проиграли.
DrawText=Победила дружба!
PlayerPlace={0} занял(а) {1}-е место
PlayerPlace={0} занял(а) {1}-е место
DeckCardsCount=Количество карт:
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ allprojects {
apply plugin: "eclipse"
apply plugin: "idea"

version = '0.2.6'
version = '0.2.7'
ext {
appName = "OpenFool"
gdxVersion = '1.9.9-SNAPSHOT'
Expand Down
9 changes: 9 additions & 0 deletions core/src/ru/hyst329/openfool/CardActor.kt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package ru.hyst329.openfool

import com.badlogic.gdx.graphics.Color
import com.badlogic.gdx.graphics.Texture
import com.badlogic.gdx.graphics.g2d.Batch
import com.badlogic.gdx.graphics.g2d.Sprite
Expand Down Expand Up @@ -48,4 +49,12 @@ internal class CardActor(game: OpenFoolGame, val card: Card, deckStyle: String)
// System.out.printf("actor %s %s %s %s\n", getX(), getY(), getWidth(), getHeight());
(if (isFaceUp) face else back).draw(batch!!)
}

fun tint(color: Color) {
face.color = color
}

fun untint() {
face.color = Color.WHITE
}
}
36 changes: 32 additions & 4 deletions core/src/ru/hyst329/openfool/GameScreen.kt
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,9 @@ class GameScreen(private val game: OpenFoolGame) : Screen, EventListener {
internal var defenseCards = arrayOfNulls<Card>(DEAL_LIMIT)
private set
private val cardActors = HashMap<Card, CardActor>()
private val deck = Deck()
internal var ruleSet = RuleSet(game.preferences)
private set
private val deck = Deck(ruleSet.lowestRank)
private var currentAttackerIndex: Int = 0
private var currentThrowerIndex: Int = 0
private var playersSaidDone: Int = 0
Expand All @@ -102,8 +104,6 @@ class GameScreen(private val game: OpenFoolGame) : Screen, EventListener {
private val sortingMode: Player.SortingMode
private var throwLimit = DEAL_LIMIT
private var playerDoneStatuses: BooleanArray
internal var ruleSet = RuleSet(game.preferences)
private set
internal var places = IntArray(DEAL_LIMIT) { 0 }

init {
Expand Down Expand Up @@ -131,7 +131,7 @@ class GameScreen(private val game: OpenFoolGame) : Screen, EventListener {
stage.addActor(deckGroup)
discardPileGroup = Group()
stage.addActor(discardPileGroup)
playerGroups = Array(ruleSet.playerCount, { Group() })
playerGroups = Array(ruleSet.playerCount) { Group() }
for (i in 0 until ruleSet.playerCount) {
playerGroups[i] = Group()
stage.addActor(playerGroups[i])
Expand Down Expand Up @@ -277,6 +277,7 @@ class GameScreen(private val game: OpenFoolGame) : Screen, EventListener {
}
if (oldGameState != gameState) {
System.out.printf("Game state is %s\n", gameState)
tintCards()
oldGameState = gameState
}
when (gameState) {
Expand Down Expand Up @@ -489,6 +490,33 @@ class GameScreen(private val game: OpenFoolGame) : Screen, EventListener {
gameState = READY
}

fun tintCards() {
// Tint the available cards for throwing/beating
for (a in cardActors.values) {
a.untint()
}
when {
currentThrower === players[0] && attackCards[0] != null -> {
for (c in players[0].hand) {
val actor = cardActors[c]
// If the card cannot be thrown, grey it out
if (!players[0].cardCanBeThrown(c, attackCards, defenseCards))
actor?.tint(Color.GRAY)
}
}
currentDefender === players[0] -> {
for (c in players[0].hand) {
val actor = cardActors[c]
// If the card cannot beat, grey it out
if (!players[0].cardCanBeBeaten(c, attackCards, defenseCards, trumpSuit))
actor?.tint(Color.GRAY)
}
}
else -> {
}
}
}

private // TODO: Generalise
val isGameOver: Boolean
get() {
Expand Down
24 changes: 19 additions & 5 deletions core/src/ru/hyst329/openfool/NewGameScreen.kt
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import com.badlogic.gdx.scenes.scene2d.utils.ClickListener
import com.badlogic.gdx.utils.viewport.FitViewport
import com.kotcrab.vis.ui.widget.VisCheckBox
import com.kotcrab.vis.ui.widget.VisLabel
import com.kotcrab.vis.ui.widget.VisSelectBox
import com.kotcrab.vis.ui.widget.VisTextButton
import com.kotcrab.vis.ui.widget.spinner.IntSpinnerModel
import com.kotcrab.vis.ui.widget.spinner.Spinner
Expand All @@ -23,6 +24,8 @@ internal class NewGameScreen(private val game: OpenFoolGame) : Screen {
private val limitCheckBox: VisCheckBox
private val playerCountSpinner: Spinner
private val teamCheckBox: VisCheckBox
private val cardCountLabel: VisLabel
private val cardCountSelectBox: VisSelectBox<Int>
private val ruleSet: RuleSet = RuleSet(game.preferences)

init {
Expand All @@ -37,29 +40,39 @@ internal class NewGameScreen(private val game: OpenFoolGame) : Screen {
})
stage.addActor(singlePlayerButton)
gameplayLabel = VisLabel(game.localeBundle.get("GameplaySettings"))
gameplayLabel.setBounds(390f, 350f, 320f, 40f)
gameplayLabel.setBounds(340f, 350f, 400f, 40f)
stage.addActor(gameplayLabel)
deuceCheckBox = VisCheckBox(game.localeBundle.get("DeuceBeatsAce"))
deuceCheckBox.setBounds(390f, 300f, 320f, 40f)
deuceCheckBox.setBounds(340f, 300f, 400f, 40f)
deuceCheckBox.isChecked = ruleSet.deuceBeatsAce
stage.addActor(deuceCheckBox)
limitCheckBox = VisCheckBox(game.localeBundle.get("LimitTo5Cards"))
limitCheckBox.setBounds(390f, 250f, 320f, 40f)
limitCheckBox.setBounds(340f, 250f, 400f, 40f)
stage.addActor(limitCheckBox)
limitCheckBox.isChecked = ruleSet.loweredFirstDiscardLimit
val intSpinnerModel = IntSpinnerModel(ruleSet.playerCount, 2, 5, 1)
playerCountSpinner = Spinner(game.localeBundle.get("PlayerCount"), intSpinnerModel)
playerCountSpinner.setBounds(390f, 200f, 320f, 40f)
playerCountSpinner.setBounds(340f, 200f, 400f, 40f)
playerCountSpinner.addListener(object : ChangeListener() {
override fun changed(event: ChangeListener.ChangeEvent, actor: Actor) {
ruleSet.playerCount = intSpinnerModel.value
}
})
stage.addActor(playerCountSpinner)
teamCheckBox = VisCheckBox(game.localeBundle.get("TeamPlay"))
teamCheckBox.setBounds(390f, 150f, 320f, 40f)
teamCheckBox.setBounds(340f, 150f, 400f, 40f)
stage.addActor(teamCheckBox)
teamCheckBox.isChecked = ruleSet.teamPlay
cardCountLabel = VisLabel(game.localeBundle.get("DeckCardsCount"))
cardCountLabel.setBounds(340f, 100f, 180f, 40f)
stage.addActor(cardCountLabel)
cardCountSelectBox = VisSelectBox()
cardCountSelectBox.setItems(24, 32, 36, 52)
println("card count is ${ruleSet.cardCount}")
cardCountSelectBox.selected = ruleSet.cardCount
println("selected is ${cardCountSelectBox.selected}")
cardCountSelectBox.setBounds(540f, 100f, 200f, 40f)
stage.addActor(cardCountSelectBox)
}


Expand Down Expand Up @@ -97,6 +110,7 @@ internal class NewGameScreen(private val game: OpenFoolGame) : Screen {
ruleSet.loweredFirstDiscardLimit = limitCheckBox.isChecked
ruleSet.teamPlay = teamCheckBox.isChecked
ruleSet.playerCount = (playerCountSpinner.model as IntSpinnerModel).value
ruleSet.cardCount = cardCountSelectBox.selected
ruleSet.save(game.preferences)
game.screen = GameScreen(game)
dispose()
Expand Down
27 changes: 20 additions & 7 deletions core/src/ru/hyst329/openfool/Player.kt
Original file line number Diff line number Diff line change
Expand Up @@ -240,10 +240,9 @@ class Player internal constructor(private val ruleSet: RuleSet, private var name
hand.clear()
}

fun throwCard(c: Card,
attackCards: Array<Card?>,
defenseCards: Array<Card?>,
trumpSuit: Suit) {
fun cardCanBeThrown(c: Card,
attackCards: Array<Card?>,
defenseCards: Array<Card?>): Boolean {
val ranksPresent = BooleanArray(13)
for (card in attackCards) {
if (card != null)
Expand All @@ -253,18 +252,32 @@ class Player internal constructor(private val ruleSet: RuleSet, private var name
if (card != null)
ranksPresent[card.rank.value - 1] = true
}
if (hand.contains(c) && (ranksPresent[c.rank.value - 1] || Arrays.equals(attackCards, arrayOfNulls<Card>(6)))) {
return hand.contains(c) && (ranksPresent[c.rank.value - 1] || Arrays.equals(attackCards, arrayOfNulls<Card>(6)))
}

fun throwCard(c: Card,
attackCards: Array<Card?>,
defenseCards: Array<Card?>,
trumpSuit: Suit) {
if (cardCanBeThrown(c, attackCards, defenseCards)) {
hand.remove(c)
fire(CardThrownEvent(c))
}
}

fun cardCanBeBeaten(c: Card,
attackCards: Array<Card?>,
defenseCards: Array<Card?>,
trumpSuit: Suit) : Boolean {
val attack = attackCards[Arrays.asList<Card>(*defenseCards).indexOf(null)] ?: return false
return hand.contains(c) && c.beats(attack, trumpSuit, ruleSet.deuceBeatsAce)
}

fun beatWithCard(c: Card,
attackCards: Array<Card?>,
defenseCards: Array<Card?>,
trumpSuit: Suit) {
val attack = attackCards[Arrays.asList<Card>(*defenseCards).indexOf(null)] ?: return
if (hand.contains(c) && c.beats(attack, trumpSuit, ruleSet.deuceBeatsAce)) {
if (cardCanBeBeaten(c, attackCards, defenseCards, trumpSuit)) {
hand.remove(c)
fire(CardBeatenEvent(c))
}
Expand Down
1 change: 0 additions & 1 deletion core/src/ru/hyst329/openfool/PlayerTesting.kt
Original file line number Diff line number Diff line change
Expand Up @@ -309,5 +309,4 @@ class PlayerTesting(val gameId: Int, val ruleSet: RuleSet, val lowestRank: Rank)
gameState = READY
println("[$gameId] Turn ended, remaining ${cardsRemaining()} cards, $isGameOver")
}

}
4 changes: 2 additions & 2 deletions core/src/ru/hyst329/openfool/RuleSet.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ package ru.hyst329.openfool
*/

import com.badlogic.gdx.Preferences
import kotlin.math.min
import kotlin.math.max

class RuleSet(var deuceBeatsAce: Boolean = false,
var loweredFirstDiscardLimit: Boolean = false,
Expand All @@ -29,7 +29,7 @@ class RuleSet(var deuceBeatsAce: Boolean = false,
// Team play only for even number of players (4 or 6 actually)
teamPlay = teamPlay && (playerCount > 2 && playerCount % 2 == 0)
// Card count must be a multiple of 4 and not less than 6 * cardCount
cardCount = min(6 * playerCount, (cardCount + 3) / 4 * 4)
cardCount = max(6 * playerCount, (cardCount + 3) / 4 * 4)
}

fun save(preferences: Preferences) {
Expand Down
2 changes: 1 addition & 1 deletion core/src/ru/hyst329/openfool/SettingsScreen.kt
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ internal class SettingsScreen(private val game: OpenFoolGame) : Screen {

})
stage.addActor(backgroundSpinner)
deckSelectBox = VisSelectBox<String>()
deckSelectBox = VisSelectBox()
deckSelectBox.setBounds(530f, 300f, 230f, 40f)
deckSelectBox.setItems(*DECKS.keys.toTypedArray())
deckSelectBox.addListener(object : ChangeListener() {
Expand Down

0 comments on commit c5b493f

Please sign in to comment.