Hello a quick introduction my major experiance of Java has been college work I did 2 semesters one based around GUIs. In my first semester it was mostly theory which was very dissapointing but my second semester I had a very hands on lecturer and really enjoyed it unfortunatly this was a fairly advanced course and while I did well in it I don't think I had fully understood some fairly basic OO concepts such as inheritence since I didn't get assigments to practice them in the first semester. While I had all this theory in my head I misunderstood it and late in the second semester it all started making sense. I was fairly handy when it came to coding and debugging it's just the inheritence stuff like say Mountain Bike extends Bike that sort of stuff.
A couple of months ago in my spare time I decided to try and do some Java and I wanted to do something with poker or at least cards my first challenge was fairly simple create a Card class and a Deck class and a Deck Test class. I had done this before but it was a nice refresher and got it done fairly quick.
I then decided to build a GUI to show all the cards in the deck and as a test if a card was clicked a message box would pop up show what card it is. This wasn't too hard what I decided to do was create a Graphic Card class which extended Card. I don't have the code with me but I think the additional methods were things like drawCard which took in a compent to draw it on along with width height and I think where to draw it. Once again pretty simple and it worked it showed up all the cards(I got images for them off the internet).
I then added a contains method which took in two integers (mouse x and mouse y) and returned a boolean if the point was in the card, so when a position was clicked it would make this method call to all the Graphic Cards and if it returned true it would call the method printCardName. Now at this stage I started working on a website with a friend and left this project.
I went back to it over the weekend and wasn't really happy with the way this worked so changed things around, I wanted to expand on the poker idea and decided to make a simple video poker game. I changed it so there is a Class called CardCollection which is extended by Hand and Deck. I scrapped the graphic card class and added a StrengthChecker class(determines the strength of the hand passed to it) it only works for 5 card hands at the moment but I quite like it and it works I also started a VideoPoker and once again this worked quite well in the command line I was able to show a hand and toggle whether a card was held or not and print out the strength of the finishing hand, all very good. But then I started on a GUI for the game I was able to display the deck(well an image representing the deck) and the five cards, but putting any interactivity on top of this proved beyond me. What I want is that when the player clicks the deck it will invoke the dealFirstHand method and then when a player clicks the cards it toggles whether they are held or not and when the player clicks the deck again it will deal out second hand. Now I was kind of thinking Image would have a contains method similar to that of the shape class which I worked fairly extensively with before. Unfortunatly it didn't. Now I thought a way to avaoid this was to put some buttons in but I wasn't keen on that I also thought maybe since theres always going to be 5 cards and 1 deck I could just have an If point is in range1 then toggle this card1 that sort of thing. I think this would work but I thought there had to be a way to check if an image is clicked. I couldn't find any solution for this with a quick internet search I didn't delve too deeply but I was hoping someone could point me in the right direction for this.
Now I don't know why this didn't occur to me yesterday but I've just checked BufferedImage would the getData method from that be a way to go about things?
Also one other thing I that confused me. I cant exactly remember the problem my Deck class had an Array of Card objects I would have been under the impression that I could then put GraphicCard objects(which extends Card) but I don't think I was able to anyone help me on this?
I think I had a few more minor things but I can't remember the exact details right now and I don't have the code with me to check so I might add these at another time.
Anyway that was a fairly long winded post so thanks to anyone who took the time to read it, and if anything wasn't clear please don't hesitate to let me know.
Regards
Faz


LinkBack URL
About LinkBacks
Reply With Quote
.