Jump to content


Check out our Community Blogs

Register and join over 40,000 other developers!


Recent Status Updates

View All Updates

Photo
- - - - -

Ruby simple Solitaire Game

ruby

This topic has been archived. This means that you cannot reply to this topic.
6 replies to this topic

#1 ekultek

ekultek

    CC Lurker

  • New Member
  • Pip
  • 4 posts

Posted 23 September 2015 - 03:23 AM

Alright, I've decided I'm going to create an app, I've learned a lot and now is the time for me to put my training into action, I have an idea of what I want to do. I'm going to make a game similar to solitaire the only problem is I have no idea how to start this or even how to begin...

 

 

So my question is, how would you start if you where going to create a game like what I'm doing? Would you use classes, a superclass, just variables, methods etc.? I'm trying to get a grasp on what I want to accomplish within this game. I've made games already (just text games though "You walk through a door, what do you want to do?" gets.chomp! etc..)

 

 

So I'm looking for all possible solutions and looking very deep into how this will work and how this is going to be achieved I want to learn something from this experience. Please give examples of what you would personally use.

 

This will be my first actual app in Ruby and I'm looking for some help and guidance. Thank you!

 



#2 WingedPanther73

WingedPanther73

    A spammer's worst nightmare

  • Moderator
  • 17757 posts

Posted 23 September 2015 - 04:50 AM

Step 1: forget about coding for a moment. What are the rules of the game? What are the pieces in the game? What should the user be able to do?

You mentioned you want to make a game similar to solitaire. Unfortunately, there are a LOT of games that go by that title, from the card games Klondike and Spider Solitaire, to various peg-jumping games on triangular and cross-shaped boards. Heck, I've even played a solitaire version of the board game Robo-Rally.

 

You need to know what your game is, in detail, before you can start to think about classes, etc.


Programming is a branch of mathematics.
My CodeCall Blog | My Personal Blog

My MineCraft server site: http://banishedwings.enjin.com/


#3 ekultek

ekultek

    CC Lurker

  • New Member
  • Pip
  • 4 posts

Posted 23 September 2015 - 04:52 AM

Ha, didn't really think of that, I'll do some research on it and see what I can come up with I guess.



#4 ekultek

ekultek

    CC Lurker

  • New Member
  • Pip
  • 4 posts

Posted 23 September 2015 - 06:51 AM

Alright so I've done my reasearch and I'm going to be making it into original Solitaire.

I'll be using 52 cards, suit 2-Ace and it'll be just like a normal game.

Now back to my original question:

I have done some of the coding already, just the outline, and don't know where to go from here:

 

class Game
    attr_accessor :deck, :rank, :suit, :player
end


class Deck < Game
    def initialize(deck)
        @deck = amount_of_cards
        amount_of_cards = 52
        Deck.shuffle!
    end
end



class Rank < Game
    def initialize(rank)
        @rank = card_rank
        card_rank = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 'J', 'Q', 'K', 'A']
    end
end



class Suit < Game
    def initialize(suit)
        @suit = card_suit
        card_suit = ['D', 'C', 'H', 'S']
    end
end


class Player < Game
    def initialize(player)
        @player = player
    end
end


#5 WingedPanther73

WingedPanther73

    A spammer's worst nightmare

  • Moderator
  • 17757 posts

Posted 23 September 2015 - 10:56 AM

As far as your statement "original Solitaire", that doesn't tell me much, though I suspect you're referring to Klondike. https://en.wikipedia..._patience_games

 

I think your first step is to think about the objects more carefully. A Deck of cards consists of 52 cards. Each card has a suit and a rank, and no two are the same. This implies your Deck object needs to have an Array of Card objects (which need to be initialized). You can "shuffle" the deck by rearranging the Cards in the Array of Cards.

 

Various elements of the play field will then contain array of cards in various states (upright or face down) and positions. That should give you something to work on :)


Programming is a branch of mathematics.
My CodeCall Blog | My Personal Blog

My MineCraft server site: http://banishedwings.enjin.com/


#6 ekultek

ekultek

    CC Lurker

  • New Member
  • Pip
  • 4 posts

Posted 23 September 2015 - 12:39 PM

"have an Array of Card objects (which need to be initialized)"

That would look like this if I'm not mistaken:

 

@@deck = Array.new(' ')
       

correct?



#7 WingedPanther73

WingedPanther73

    A spammer's worst nightmare

  • Moderator
  • 17757 posts

Posted 24 September 2015 - 04:45 AM

Unfortunately, I'm NOT a python expert, just fumbling through with general structure, etc :)


Programming is a branch of mathematics.
My CodeCall Blog | My Personal Blog

My MineCraft server site: http://banishedwings.enjin.com/