Friday 2 May 2014

Go Fish and Giving Card

Okaaay... ignoring the previous error for now, I can now get the computer to give up a card if the player asks for it and that card will now be added to the player's hand. Instead of needing all four numbers I'm going to just make them pairs to make the game shorter.
The checking of pairing will be done in the beginning and a JOptionPane will pop up to tell the user that their pairs have been removed. The message will also pop up during the game when either the player or the computer is able to remove a pair of their cards.

Friday 25 April 2014

More on Removing Cards

I've decided to not just find pairs. I could just use a counter and keep on adding to it until 4 cards with the same value are found. When the card with the same value as the one currently being checked is found, that element is being placed into an Ingeter array. When counter is equal to 4, an if statement will run. Inside that if statement is another for loop (for(int remove=0; remove< ...)etc etc) that will remove the elements in the array from the playerHand as long as int remove is less than the length of the array.
It seems logical but I haven't actually tried to run it yet even though it does build with no problems. I'm just...going to move on to other parts of the program that still needs to be written.

Other Things
I think I'm just missing the part that will determine when the player wins. That would be when the player has 0 cards left in the list which I could use isEmpty...and I should check if the list is empty after each card that is removed from the list. If the player has no cards left then they should be brought back to the main menu after a JOptionPane shows up to tell them so.

And I just realised that I haven't written the code for the computer to ask if the player has certain cards... O_O


Wednesday 23 April 2014

Finding the Pairs

Okay so I started to write the code that will find pairs in the hand and remove them from the hand. I'm using a for loop and a nested for loop...and that confused me a bit so I just wrote it all out on paper first along with the list of cards and somehow fumbled around and made them work. So far in the actual program there is only the for loop conditions things like for(int blah = ....) etc., etc... and when I build it, it works nicely except there's no code inside yet. That, I will work on Friday.

--

It works now. I've run it. The only issue I have is making the new cards (after having the four of a kinds removed) show up. I have the method that refreshes the player's hand for me but it's not...working. I'll figure it out some time later.

Monday 14 April 2014

Uhhh...

Didn't actually do anything today... the deck was acting weird. It wasn't doing what it should be doing, and I just added some tracing statements and moved the resetGame(); around, and then the problem kind of disappeared...but then it came back.

Friday 11 April 2014

Go Fish

I'm finished with most of the JComboBox. Now the card number will be compared with computerHand and if the computer has the card the card will be removed from the computer's hand and a JOptionPane will pop up to tell you that you've found the ____ card.

There's a boolean to control whether found is true or not and this is so when the for loop (to find the matching value) runs, it won't tell you that the card isn't found after it has only gone through the loop once. Because the card you want to find might just not be the first one on the list. All this happens in a method called matchCards and then matchCards is put into the mouseClicked method.

The line of code that selectedNumber is declared is put into the mouseClicked method rather than the matchCards();

Thursday 10 April 2014

JComboBOx continued

Ahh snake game distractions... -_-

So, more about the JComboBox was done today. I have to make sure that the item I select is actually begin selected, so I added a mouse listener to the drop down menu, which is called listOfCards. I added the mouse listener to it, in the constructor method, where I put all the other mouse listeners that were added to buttons.

I also moved the reset method since it wasn't working as well as it would where it was now. Instead of just calling the method when the player presses the play button, I put it so it calls the restart method when the the program runs. Which means the reset method is also in the constructor method. It will also run when the player presses the back button from within the gameFrame.

I also have a few tracing statements throughout the game so that I'd know it's working properly. I have it show me the cards being dealt to the computer, which usually wouldn't show up in the real game. The player's hand is actually on the screen since the player would have to see it to chose what number to ask the computer.

Next, I made a method that will find the matching numbers. (If there is a number to match) and if there is not a number to match then a window will pop up saying that the computer doesn't have that number, and then another card will be dealt to the player. The player's hand on the screen will plus one card from the deck. Its linked list, playerHand will also have a new node to its list.

If the computer does have the card, then it will remove the card from that list and that card will be added to playerHand's list.

But I haven't done that yet. I just made the method for it and made a value for the item that was selected to check and it's called String selectedValue, or of some such.

Tuesday 8 April 2014

JComboBox

The drop down menu for selecting the number the player wants to ask the computer works (yay, but why is it even called a JComboBox??). Before, when I put it in the gam();, it didn't work because in the reset method, I had made the linked list for  playerHand empty and in the play method it was still 0. Which meant the for loop for adding items onto the drop down menu wouldn't work.

Then I tried to put the line of code for the drop down menu with the reset method and it worked. But then I thought that maybe it wouldn't work for the rest of the game, when the players' hands started to grow or shrink, so I removed it from the reset(); but it turns out that I'm just going crazy and that it would work for the rest of the game since later on, I'll just have to use some other method that's in JComboBox and remove an item or whatnot.

So, drop down menu is dealt with. Now I should actually show somewhere the computer hand's cards so I'll know if the game's actually working. But obviously while playing the game, the computer's hand wouldn't be seen. And also to actually start...programming this game.

Monday 7 April 2014

clear

Found out why the restart method wasn't resetting properly. The computerHand and playerHand linked lists weren't removing all the cards that were already inside. I had to do computerHand.clear(); and playerHand.clear();

Thursday 3 April 2014

Reset and Reset Problems

The dealSeven(); and updateHand(); methods are now just part of the reset(); as well as the line of code that tells the player what they have in their hand.

I'm having the same problem as the one for minesweeper. Game's not resetting properly. Have to figure out what's wrong with the code this time.

Kind of Start, Kind of Middle

I have a deck class and a card class. The card class holds the values for each card (suit and number) and the deck class includes methods for creating a deck of cards, shuffling the deck, and dealing out the cards. 

In the main method I have most of the buttons I need declared and have created two linked lists in that class for the computer's hand and the player's hand.

dealSeven()
There's a method that will deal out 7 cards to each player to start with, done with a for loop and the method that was created in the deck class. updateHand() is in this method outside of the for loop.
But two 10 of hearts is in the player's hand which isn't supposed to happen.

updateHand()
Another method is to show in a JLabel what the player's hand includes. 

I need a reset method and fix the shuffling.