Ok I’m going to show you a sample of the minimum
requirements for the final project. This is
a simplified game of War with a cards class.
And we have the main War method as well. And
when we run it…
…you will have 2 decks of cards and every
time you click, it is going to pull a card.
It’s actually pulling it from the bottom have
the deck and moving it to the center and comparing
the 2 cards. Whichever card is higher gets
So you can see…now I don’t think…we may
not get a tie. If there’s a tie, nothing happens.
No points change. So the cards layout is pretty
similar to what we did with the memory game.
We’ve just…I’ve changed it so we’ve got
20 cards and you can do all 52. We’ve added
an additional value called “mp”. It’s coming
in as “mp” but here its myPoints so each card
stores the point value of the card at its
face. Since we’re going through each of the
different suits, we have to declare how many
points are each and we’re going to count jacks
is 11, queens is 12, and kings is 13 so they
We have a display which loads image and we
have a setX which moves the card to the center
and flips it over so you see the face. So
when we’re clicking here, that’s what’s happening.
We’re taking the card off the back of the
deck, actually flipping it over and moving
it into the center.
Then we have getPoints which returns the point
value of the cards so that it can compare
the left card to the right card to see who
In the War side our setup, we’ve got our background
we have a myX1 and myX2 because each pile
has its own X value and then moves them to
the center. We’ve set the size. This is pretty
straightforward. When we’re creating our arrays,
my currentPoints because I’m only doing 10
cards of each is going to 10 and that’s resetting
it to 1. So it’s counting 1 through 10 and
then starting over so that the point values
match the face value of the card. So an ace
is 1, 2 is 2.
Now to put them into 2 piles, we are checking
to see if our I value is divisible by 2 without
a remainder. This is the modulus function and
what we’re checking is to see if there is
a remainder. 2 divided by 2 equals 0. That
would go in the even pile. 3 divided by 2
would leave a remainder; that would go in the
odd pile. And so we’re going to increment
myY by adding 2 to it, myX1 by adding 2, myX2
by adding 2; this is making us have…what
that’s by incriminating by 2 pixels, each
new card is going to come in 2 pixels lower
and 2 pixels further to right. It gives us
this illusion of dimension.
And whether they are odd or even is going
to determine if it is in the X1 or X2 because
if it is evenly divisible it is going to be
in the X1 pile, otherwise it is going to be
in the X2 pile. Again, that’s just for 1 or
2 piles. We shuffle a couple of times and
then we display the cards on the screen.
Here we’re just checking to see if we’ve won.
We’re comparing then if leftDeck is 19, that
means that I’ve gone through all of the cards
because leftDeck is my index for the left
deck; rightDeck is my index for the right
deck. So when we’ve hit the end of the cards,
when it’s greater than 19, we will check to
see which side has more points.
On the mouseClicked, if you’re clicking on
the red box we have leftDeck where we set
the X to 190, rightDeck setting the X to 310.
And this is the index for myCard so again
what’s happening here is when I click this,
it sets this X value here, this X value here
and its action moving the cards from the back
of the deck, flipping them over, and putting
them in the new stack.
We’re incriminating by 2 because the odd ones
are going up 1, 3, 5, 7 and the even ones
are going up 0, 2, 4, 6, and 8. So leftDeck
starts at 1; rightDeck starts at 0 and we
add 2 to them each time to increment them
to the next. When we are out of cards, that’s
how you know to check if you have won.
Our shuffle is almost the same as it was in
the memory game except you have to move the
point value with the face value so that they
stay tied together. So that is your simplest
version. If you do this one, you need to do
all 52 cards.