Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
  • Help Room /
avatar image
0
Question by LasseMillek · Dec 20, 2017 at 11:25 AM · gamerandomlayoutcards

Un randomize memory cardgame

Hello there. I have made a memory game with a randomizing effect on the cards, with help from a tutorial. Now i want the cards to not be random, but be in the slots i choose, can someone see a solution for this in the code? First script:

   public class Playmat : VersionedView
     {
         public bool gameWon = false;
         public int TotalPoints = 0;
         public int Points = 0;
         public int NumberOfCardsFlipped = 0;
     
         public enum BoardState {Flipping,Comparing}
         public BoardState state = BoardState.Flipping;
     
         private static Playmat mat;
         public GameObject cardPrefab;
         public Layout layout;
         public GameObject board;
     
         public List<Card> cards = new List<Card>();
     
         public Card card1;
         public Card card2;
     
         // Use this for initialization
         void Start ()
         {
             mat = this;
             GameSettings.Instance().SetDifficulty(GameSettings.GameDifficulty.Hard);
             CreateLayout();
             CreateCardsFromLayout();
             CreateCardTypes();
         }
     
         public static Playmat GetPlaymat()
         {
             return mat;
         }
     
         public void CreateLayout()
         {
             board = layout.GetRandomLayout();      
         }
         
         void CreateCardsFromLayout()
         {
             foreach(Slot s in layout.slots)
             {
                 GameObject go = GameObject.Instantiate(cardPrefab, s.transform.position, Quaternion.Euler(0, 90, 0)) as GameObject;
                 go.transform.parent = s.transform;
                 Destroy(s.GetComponent<BoxCollider>());
                 cards.Add(go.GetComponent<Card>());
             }
         }
     
         void CreateCardTypes()
         {
             for(int i=0;i <=cards.Count/2;i++)
             {
                 Card c1 = cards[i];
                 Card c2 = cards[cards.Count - 1 - i];
                 string type = GameSettings.Instance().GetRandomType();
                 c1.GenerateCard(type);
                 c2.GenerateCard(type);
             }
             TotalPoints = cards.Count / 2;
         }
         public string GetPointsString()
         {
             return Points.ToString() + "/" + TotalPoints.ToString();
         }
     
         public override void DirtyUpdate()
         {
             switch (state)
             {
                 case BoardState.Comparing:
                     Compare();
                     break;
             }
         }
     
         public void Compare()
         {
             if(card1.CardType == card2.CardType)
             {
                 NumberOfCardsFlipped = 0;
                 Points++;
                 if(TotalPoints == Points)
                 {
                     gameWon = true;
                 }
             }
     
     
             else
             {
                 card1.Unflip();
                 card2.Unflip();
             }
     
             card1 = null;
             card2 = null;
             state = BoardState.Flipping;
         }
     
         public void SetCardsForMatch(Card c)
         {
             if(card1==null)
             {
                 card1 = c;
                 state = BoardState.Flipping;
             }
             else
             {
                 card2 = c;
                 state = BoardState.Comparing;
             }
             MarkDirty();
             
         }
     } 

Game settings:

 public class GameSettings
 {
     private static GameSettings gameSetting;
     private GameSettings(){}
     public static GameSettings Instance()
     {
         if (gameSetting == null)
         {
             gameSetting = new GameSettings();
         }
 
 
         return gameSetting;
     }
 
 
 
     public enum GameDifficulty { Easy, Medium, Hard }
     public GameDifficulty difficulty= GameDifficulty.Easy;
     private string[] easyDifficulty = {"Blue", "Yellow", "Green", "Pink", "Purple", "Red", "Orange" };
     private string[] mediumDifficulty = {"Blue", "Yellow", "Green", "Pink", "Purple"};
     private string[] hardDifficulty = {"Blue", "Yellow", "Green", "Pink", "Purple", "Red", "Orange"};
 
 
     public List<string> CardTypes
     {
         get
         {
             List<string> tempList = new List<string>();
             switch (difficulty)
             {
                 case GameDifficulty.Easy:
                     tempList.AddRange(easyDifficulty);
                     break;
                 case GameDifficulty.Medium:
                     tempList.AddRange(mediumDifficulty);
                     break;
                 case GameDifficulty.Hard:
                     tempList.AddRange(hardDifficulty);
                     break;
             }
             return tempList;
         }
     }
 
     public void SetDifficulty(GameDifficulty diff)
     {
         difficulty = diff;
     }
 
     public string GetRandomType()
     {
         return CardTypes[Random.Range(0, CardTypes.Count)];
     }
 }



Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

0 Replies

· Add your reply
  • Sort: 

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

153 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

How to sort cards in order from smallest to the largest amount of strength? 0 Answers

In card game, Playing specific sounds when an object is revealed 0 Answers

is there a way to lock the layout? 1 Answer

Card array layout 1 Answer

Digital Card Game Phases 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges