public void loadcard(card_class c) { //Debug.Log(" loaded"); if (c == null) { return; } card = c; id.text = c.cardId.ToString(); name.text = c.cardName; //img.sprite = c.cardImg; strength.text = c.strength.ToString(); speed.text = c.speed.ToString(); life.text = c.life.ToString(); food_chain.text = c.food_chain.ToString(); }
public IEnumerator NewCurrentCard(int suit, int rank, bool from_deck, bool undo)//show the new current card in target deck { player_can_move = false; animationsCount++; previus_rank = current_card_rank; current_card_suit = suit; current_card_rank = rank; if (from_deck)//the new card is give from the deck { MenuManager.GetInstance().PlaySound(MenuManager.SoundNamesEnum.NEW_CARD_SOUND); if (undo) { target_new_card.sprite = card_deck_sprite [current_card_suit, current_card_rank]; UpdateScore(undo_score); CreateScoreEvent(undo_button.transform.position, undo_score.ToString(scoreFormat), current_score); new_card_anim.Play("undo_to_deck_card_anim"); yield return(new WaitForSeconds(undo_animation_duration)); RemoveUndoStep(); UpdateUndoButton(); unused_card_count--; //Update_combo_text(); new_card_anim_sprite.sprite = card_deck_sprite [current_card_suit, current_card_rank]; } else { current_target_deck_position++; if (game_started) { unused_card_count++; //check if give an useful card for sure /*if (unused_card_count > give_an_useful_card_not_less_than_n_new_card_from_the_deck) * { * //search a face up card from the board * int random_start_point = Util.GetRandomBetween0And(cards_on_board.Length-1); * bool card_found = false; * for (int i = random_start_point; i < cards_on_board.Length; i++) * { * if (cards_on_board [i].This_card_is_free() && cards_on_board [i].gameObject.activeSelf == true && cards_on_board [i].face_up) //if this card is active * { * * deck_cards[current_deck_position].rank = cards_on_board [i].my_rank; * card_found = true; * break; * } * } * if (!card_found) * { * for (int i = 0; i < random_start_point; i++) * { * if (cards_on_board [i].This_card_is_free() && cards_on_board [i].gameObject.activeSelf == true && cards_on_board [i].face_up) //if this card is active * { * deck_cards[current_deck_position].rank = cards_on_board [i].my_rank; * card_found = true; * break; * } * } * } * * //decide if the next card will have a rank +1 or -1 * if (Util.GetRandomBetween0And(1) > 0) * { * deck_cards[current_deck_position].rank++; * if (deck_cards[current_deck_position].rank > 12) * deck_cards[current_deck_position].rank = 0; * } * else * { * deck_cards[current_deck_position].rank--; * if (deck_cards[current_deck_position].rank < 0) * deck_cards[current_deck_position].rank = 12; * } * * current_card_rank = deck_cards[current_deck_position].rank; * }*/ if (show_unused_card_when_player_take_a_new_card_from_the_deck) { int avaible_move = CheckAvaibleMoves(previus_rank); if (avaible_move >= 0) //if there is a move //StartCoroutine(ShakeCard(cards_on_board[avaible_move].transform)); { } } } target_deck_cards [current_target_deck_position] = new card_class(); target_deck_cards [current_target_deck_position].suit = current_card_suit; target_deck_cards [current_target_deck_position].rank = current_card_rank; new_card_anim_sprite.sprite = card_deck_sprite [current_card_suit, current_card_rank]; new_card_anim.Play("new_card_anim"); yield return(new WaitForSeconds(animation_duration)); previous_combo_count = combo_count; combo_count = 0; /*Update_combo_text(); * * same_color_combo = 0; * same_suit_combo = 0; * score_multiplier = 0; * * Update_score_multiplier();*/ // Update undo AddUndoStep(null, moveType.ask_new_card_from_deck, current_score); UpdateUndoButton(); target_new_card.sprite = card_deck_sprite [current_card_suit, current_card_rank]; } if (!game_started) { game_started = true; target_new_card.gameObject.SetActive(true); } } else //from board { MenuManager.GetInstance().PlaySound(MenuManager.SoundNamesEnum.TAKE_CARD_SOUND); if (undo) { target_new_card.sprite = card_deck_sprite [current_card_suit, current_card_rank]; int deltaScore = -undo_list [undo_list.Count - 1].undo_previous_score + undo_score; UpdateScore(deltaScore); CreateScoreEvent(undo_button.transform.transform.position, deltaScore.ToString(scoreFormat), current_score); yield return(new WaitForSeconds(animation_duration));//wait the end of the animation undo_list [undo_list.Count - 1].card.SetActive(true); RemoveUndoStep(); UpdateUndoButton(); RefreshCardRotation(); } else //card take from board and this not is an undo move { yield return(new WaitForSeconds(animation_duration));//wait the end of the animation current_target_deck_position++; target_deck_cards [current_target_deck_position] = new card_class(); target_deck_cards [current_target_deck_position].suit = current_card_suit; target_deck_cards [current_target_deck_position].rank = current_card_rank; target_new_card.sprite = card_deck_sprite [current_card_suit, current_card_rank]; unused_card_count = 0; current_total_card_on_board--; if (current_total_card_on_board == 0) { StartCoroutine(GameOver(0)); } } } animationsCount--; CheckPlayerCanMove(); }
void FillDeck()//decide what card put in the deck, but some can change if give_an_useful_card_not_less_than_n_new_card_from_the_deck is trigger { //for (int i = board.childCount-1 ; i >= 0 ; i--) for (int i = 0; i < board.childCount; i++) { //Levels Transform levelObj = board.GetChild(i).transform; for (int j = 0; j < levelObj.childCount; j++) { // Cards total_card_on_board++; } } deck_card_left = 52 - total_card_on_board; deck_cards = new card_class[deck_card_left]; cards_on_board = new card[total_card_on_board]; List <int> suits = new List <int> (); for (int x = 0; x < 4; x++) { suits.Add(x); } List <int>[] ranks = new List <int> [4]; for (int j = 0; j < 4; j++) { ranks [j] = new List <int> (); for (int k = 0; k < 13; k++) { ranks [j].Add(k); } } // Fill deck for (int i = 0; i < deck_card_left; i++) { deck_cards [i] = new card_class(); int sindex = Util.GetRandomBetween0And(suits.Count - 1); int s = suits [sindex]; int rindex = Util.GetRandomBetween0And(ranks [s].Count - 1); int r = ranks [s] [rindex]; ranks [s].RemoveAt(rindex); if (ranks [s].Count == 0) { suits.RemoveAt(sindex); } deck_cards [i].suit = s; deck_cards [i].rank = r; } // Fill cards on board int w = 0; //for (int i = board.childCount-1 ; i >= 0 ; i--) for (int i = 0; i < board.childCount; i++) { //Levels Transform levelObj = board.GetChild(i).transform; for (int j = 0; j < levelObj.childCount; j++) { // Cards cards_on_board [w] = levelObj.GetChild(j).GetComponent <card> ();//put all board card script in an array to quick reference cards_on_board [w].level = i; //Debug.Log(i); w++; } } for (int i = 0; i < total_card_on_board; i++) { int sindex = Util.GetRandomBetween0And(suits.Count - 1); int s = suits [sindex]; int rindex = Util.GetRandomBetween0And(ranks [s].Count - 1); int r = ranks [s] [rindex]; ranks [s].RemoveAt(rindex); if (ranks [s].Count == 0) { suits.RemoveAt(sindex); } cards_on_board [i].Init(s, r); } current_total_card_on_board = total_card_on_board; target_deck_cards = new card_class[deck_card_left + current_total_card_on_board + 1]; for (int i = 0; i < target_deck_cards.Length; i++) { target_deck_cards [i] = new card_class(); } max_number_of_card_with_the_same_rank_on_board = Mathf.CeilToInt(total_card_on_board * 0.25f);//decide the max number of card with the same rank to put on board /*for (int i = 0; i < deck_card_left; i++) * { * deck_cards [i] = new card_class (); * deck_cards[i].suit = Util.GetRandomBetween0And(3); * deck_cards[i].rank = Util.GetRandomBetween0And(12); * * } * * //Debug.Log(deck_card_left + " " + current_total_card_on_board); * target_deck_cards = new card_class[deck_card_left + current_total_card_on_board +1]; * for (int i = 0; i < target_deck_cards.Length; i++) * { * target_deck_cards[i] = new card_class(); * }*/ deck_card_left_text.text = (deck_card_left - 1).ToString(); }