Hi all - a unity and C# newbie here.
I’ve been trying, as my first unity project, to recreate a card game i wrote a while back in python using the pygame library. The game is similar (although with some significant differences) to this Switch (card game) - Wikipedia.
In my original python game there were four classes (in a single python file):
- Card - stored the value, suit and image of a single card
- Deck - instantiated a deck of card objects and contained methods to shuffle and deal
- Player - took input from the player and allowed valid moves to be played
- Opponent - computed possible runs from the opponents hand, assigned scores to each (based on my understanduing of the game) and then played the one with the highest score
-In addition to this there were global functions (which i believe are not allowed in C#) to control turns and draw the game window.
-Card objects were stored in lists: player hand, opponent hand, shuffled deck, pile, ect, and were transferred from one list to another each turn.
My question is this - what is the best way to recreate this in unity? Should I have separate scripts for the deck and the players (I have so far assumed so), should i have a separate game object for the card class? a separate script? or can I have this class defined in the same script as the deck class? What does it mean to define a class outside of the monobehavior inheriting class?
I have had a good go at it but i can tell there’s something I’m just not grasping about unity or C#. I have created something that looks superficially like my original game (with a single player) but, at the end of the day, I can tell it’s a non starter and needs significant changes.
In my deck gameobject’s script I am able to transfer card objects (containing amongst other things value and suit) from the shuffled deck to the players “arraylist” hand (which is a separate script on a different gameobject) and to instantiate these cards as prefab children of the player gameobject - and therefore draw them on screen and be able to move them from the player script. however from the player script i am unable to access the suit and value of the objects in my hand arraylist - I recieve the following error message when i try.
“object” does not contain a definition for “value” and no accessuible extention method “value” accepting a first arguement of type object"
however there is the correct number of these “objects” in the players hand.
I hope someone can help me out and will be very grateful for any pointers or tips at all really - and i hope my question is clearly enough stated. I am a self taught programmer with no real C# or unity experience to speak of (and only a bit of python!).
Thank you all in advance :).