Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | DeathArcanaXIII |
Basically i have a working card game of Rock, Paper, Scissors, were both decks have 5 cards of each, right now my opponent pick a random card of his hand(Array) and play.
I want him to always pick a card that beats the player card. This is the code i have right now for the random card pick.
func _enemy_pick():
if(Table.played == true): #Check if the player already choose his card
randomize()
var temp = randi() % Table.enemyHand.size()
Table.pick = Table.enemyHand[temp]
Table.enemyHand.pop_at(temp)
Table.enemy_actual_hand -= 1
Table.played = false
if(Table.pick == Table.cards.Paper): #Instantiate the picked card
_show_enemy_pick(paper_scene)
if(Table.pick == Table.cards.Rock):
_show_enemy_pick(rock_scene)
if(Table.pick == Table.cards.Scissors):
_show_enemy_pick(scissors_scene)
if(Table.enemy_actual_hand == 0): #Reset Hand size because of "pop_at"
all_cards_played = true
Table.enemyHand = [7,7,7]
if(Table.enemy_actual_hand > 0):
all_cards_played = false
You don’t need to call randomize()
each time you call a function with RNG; you can just call it in _ready()
func _ready():
randomize()
SQBX | 2023-01-03 15:40