Skip to content
This repository has been archived by the owner on Apr 26, 2021. It is now read-only.

Commit

Permalink
Check is right selected
Browse files Browse the repository at this point in the history
  • Loading branch information
Team-on committed Jan 30, 2021
1 parent 38a4ab7 commit c6b9f81
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 9 deletions.
36 changes: 30 additions & 6 deletions GGJ21/Assets/Scripts/Game.cs
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,14 @@ void OnNewClient() {
StartLevel();
}
else {
Client = new Client(PetType.None, AccessoryType.None, "Dialog text");
Array pets = Enum.GetValues(typeof(PetType));
Array accessory = Enum.GetValues(typeof(AccessoryType));

Client = new Client(
(PetType)pets.GetValue(Random.Range(0, pets.Length)),
(AccessoryType)accessory.GetValue(Random.Range(0, pets.Length)),
"Dialog text"
);

cardsSelector.IsCanSelect = true;

Expand All @@ -123,21 +130,38 @@ void OnNewClient() {
}

void OnSelectLeft() {
OnSelectAnyCard();
bool isRight = CheckCard(0);
OnSelectAnyCard(isRight);
}

void OnSelectRight() {
OnSelectAnyCard();
bool isRight = CheckCard(1);
OnSelectAnyCard(isRight);
}

bool CheckCard(int id) {
bool isRight = true;

if (Client.wantedPet != PetType.None)
isRight = Client.wantedPet == cards[id].petType;

if (isRight && Client.wantedAccessory != AccessoryType.None)
isRight = Client.wantedAccessory == cards[id].accessoryType;

Debug.Log($"Is right: {isRight}");
return isRight;
}

void OnSelectAnyCard() {
clientLeftUI.UpdateValue(currClientId + 1, Level.clients);
void OnSelectAnyCard(bool isRight) {
if(isRight)
clientLeftUI.UpdateValue(currClientId + 1, Level.clients);
dialog.Hide();

cardsSelector.IsCanSelect = false;

LeanTween.delayedCall(1.0f, () => {
++currClientId;
if(isRight)
++currClientId;
OnNewClient();
});
}
Expand Down
15 changes: 12 additions & 3 deletions GGJ21/Assets/Scripts/Pet/PetCard.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@

public class PetCard : MonoBehaviour {
public bool IsSelected { private set; get; }
public PetType petType { private set; get; }
public AccessoryType accessoryType { private set; get; }

[Header("Data")]
[SerializeField] PetData[] pets;
Expand All @@ -22,21 +24,28 @@ public class PetCard : MonoBehaviour {


#region Data
public void SetCard(PetType petType, AccessoryType accessoryType) {
public void SetCard(PetType _petType, AccessoryType _accessoryType) {
petType = _petType;
accessoryType = _accessoryType;

PetData petData;
PetSpriteData petSprites;
Sprite accessorySprite;

if(petType == PetType.None) {
petData = pets.Random();
int randomNum = Random.Range(0, pets.Length);
petData = pets[randomNum];
petType = (PetType)(randomNum);
}
else {
petData = pets[(int)(petType) - 1];
}
petSprites = petData.sprites.Random();

if (accessoryType == AccessoryType.None) {
accessorySprite = petData.accessories.Random();
int randomNum = Random.Range(0, petData.accessories.Length);
accessorySprite = petData.accessories[randomNum];
accessoryType = (AccessoryType)(randomNum);
}
else {
accessorySprite = petData.accessories[(int)(accessoryType) - 1]; ;
Expand Down

0 comments on commit c6b9f81

Please sign in to comment.