Week 6 – Max Min Word Problems and Economic Analysis

With about 10 minutes after a Calculus BC test, I quickly did an introduction to Max Min word problems. Instructions: Pick an x value and find the volume of the (open) box (I gave the diagram, but didn’t have the 11-2x and 8.5-2x, those came after the class came up with them).

2014-10-07_10h42_56

They entered in their x and their volume on a google spreadsheet at a couple of computers and built the following chart.

2014-10-07_10h42_44

 

Also fun economic analysis – piecewise function maximization:

FullSizeRender

 

 

2014-10-09_11h14_23

 

 

Week 5 – Groupwork

(Re)Inspired by a tweet from Alex Overwijk,

unnamed

unnamed (1)
I used my “Vertical Non-Permanent Writing Surfaces” and “Visibly Random Grouping” in two classes today:

Precalculus H2014-10-03_08h56_242014-10-03_08h57_07

 

and BC Calculus

2014-10-03_10h16_35

2014-10-03_10h16_51

 

The goofy outfits are to be blamed on Spirit week.

Week 4 – Graphing f'(x) and Peardeck

Peardeck is a neat program. Students given f(x) and had to graph f'(x). Next time they’ll be given f'(x) and will have to graph f(x). Here’s what the teacher sees:
2014-09-26_10h24_59

And here’s the classroom action:
IMG_3738.JPG

Week 3 – Distance Formula, Desmos, and Calculus Groupwork

Here’s some students using paper, pencil, and calculator to check their Scratch program output (they needed to calculate the distance between two points).
IMG_3676-0.JPG
Desmos and transformations, a match made in (precalc) heaven.

IMG_3675.JPG
Lastly here’s calc doing what we do nearly every day, group work.

IMG_3673.JPG

Week 2 – Turn and Talk

My two intro to programming classes have started off well. Lots of work with Scratch, so lots of clicking. Silent clicking. At least once per day I have a “turn and talk” time where one student must turn off their screen and talk to a neighbor about programming difficulties. At least right now, they default to silently working (not a bad thing), but I want them to see their fellow students as resources as well. Python next week!
IMG_3663.JPG

Week 1 – Desmos Name Tags

PreCalc H students were tasked with graphing their full (first) name in desmos as homework for the first night. Here’s the results:
2014-09-05_10h02_35
I printed the images out and they now sit on their desks. Fun!

Week 0. New Setup

Hello Dear Readers,
This photo blog will have a new setup this year, 40 weeks – 40 posts. The 180 days of photos for the past two years was to much of a drain on my other blog and my writing in general, so I’m cutting it back to once a week. It’s an exciting year, so remember to visit.
Thanks,
Dan

161 – Dark Sky

For the rest of the year, I’m going to highlight some impressive final projects in Computer Programming and BC Calculus.
The computer programming students have had the majority of the term to work on their projects and one of the requirements was to write a blog post about their experience.
Here’s a crosspost of a game called Dark Sky. A fun 2D overhead game which has a cool unique game setup. The enemies only come toward you if you make move and make noise. Really polished game.

The Original Idea (Before)
darkskyoriginal
The Current Game (After)
darkskynew1

Game Demo and Controls

http://www.greenfoot.org/scenarios/11624

Left Arrow or A moves the player left.

Right Arrow or D moves the player right.

Up Arrow or W moves the player up.

Down Arrow or S moves the player down.

Holding Shift while moving allows you to “sneak”.

Pressing B when over a shop item allows you to purchase it.

Left/Right Click to fire your weapon.

Enemies and Bosses

The enemies of the game began as a simple graphic bug graphic as shown in the “Before” image and were only planned to be used for testing rather than actually being in the game. The bugs became the base for most enemies and the bosses of the game. The code for collision was spread to almost every enemy and modified to suit the enemy’s size. It would select a random direction and go a certain distance. If it hits a wall/enemy/portal, it turns in the opposite direction. If it goes the certain distance, it changes into a different random direction or continues on its path.

Example for Big enemy:

if (x < 50 && randdirection == 0) // Turns the Big left
{
if (Wallleft == null && Bigleft == null && Launcherleft == null && Portalleft == null) // Checks for collision
{
setLocation(getX() - speed,getY()); // Moves the Big left
setRotation(270); // Rotates the graphic to look to the left
}
else
{
rand = 1; //Turns the Big right
}
}

Some of the enemies also react to “sound”. The sound level changes depending on your movement. If you move without holding shift, the sound level is loud. If you hold shift, you move slower but the sound level is low. If you don’t move at all, there is no sound level. The Big enemy reacts if any sound is made, and stays stationary if no sound is made.

Example:

if (!Greenfoot.isKeyDown("shift"))
{
mode = 2;
if (!Greenfoot.isKeyDown("up") && !Greenfoot.isKeyDown("w") && !Greenfoot.isKeyDown("down") && !Greenfoot.isKeyDown("s") && !Greenfoot.isKeyDown("left") && !Greenfoot.isKeyDown("a") && !Greenfoot.isKeyDown("right") && !Greenfoot.isKeyDown("d"))
{
mode = 1;
}
}
else
{
mode = 3;
if (!Greenfoot.isKeyDown("up") && !Greenfoot.isKeyDown("w") && !Greenfoot.isKeyDown("down") && !Greenfoot.isKeyDown("s") && !Greenfoot.isKeyDown("left") && !Greenfoot.isKeyDown("a") && !Greenfoot.isKeyDown("right") && !Greenfoot.isKeyDown("d"))
{
mode = 1;
}
}

The Player

The player has the biggest amount of work put into it than any part of the game. The code for the player controls many aspects of the game including purchasing items, movement, going into different worlds, healthbar, etc. The design of the player graphic went through several iterations before becoming the blue robot that is in the present game. The player, as told below in the problems section and the before image, started off as a human. The weapons for the game were going to be things like a bow, sword, rock, and other things. Then I realized three things. One, making the weapons on the player would be infuriating as I would have to change the hands and the arms. Two, the footstep sound effect (Discussed in problems section) wasn’t working as well as I hoped. Three, the player graphic didn’t really look too much like a human. So I changed it into a robot due to it being easier to make, the weapons wouldn’t be as hard to put on, and the sound effects would be easier.

Weapons and Beginning Area

The weapons of the game have different characteristics but share some general code (Mostly collision code). The first weapon I give the player to use is the laser. It is meant to be a simple weapon with not very good range to start the player off. The weapon is also not given to the player at the start, as it is in pickup form in front of the player. This is to teach the player that when you move the enemies move. The bigs also usually go on ice which shows what ice does when you step on it.

Problems

When you run into a problem with your code, its like running into a brick wall. Whether that wall has two paths only a few feet away to proceed or one path that is three miles away depends on the problem.

Sounds

One of the very first and most persistent problems I ran into was sound. The most common was movement. There are two sounds for movement, which is for sneaking and for regular movement. When I first implemented these sounds, they were meant to be footsteps (Due to the player being a human at this point) but ended up being a continuous noise whenever I walked. I fixed the problem by putting in a “timing” system which basically plays a sound whenever an integer is divisible by a certain number.

wait = wait + 1;
if (wait % 14 == 0)
{
Greenfoot.playSound("moveslow.wav");
}

The problems didn’t stop there, as the sound began to sound annoying. Then, when I decided to change the player into the robot, I had to make new sounds. The sound for regular movement I made almost made my ears explode, but I used them for the time being and kept the sound on low. The sneaking one was great though. Eventually I decided that the sound for regular movement was too loud and I made it so the sneaking sound was used for both regular movement and sneaking until I made a new sound. The sneaking sound was kept until very recently (5/27/14) when I made a new sound which kind of sounded like running over rocks. That was made into the sneaking movement sound. The original regular movement sound was lowered and was made into the collision sound for the lightspike enemy.

Portals

The other thorn in my side was the portals. In the holes between two walls is a portal class that is meant to take you to the next level. Of course, the first time I tried to do this the portal didn’t work. I would briefly be in the second world but then it would kick me right back into the first world. The problem that I thought it was is that the getOneIntersectingObject() function was causing something to go wrong. Surprisingly, using a different collision function fixed it. The next problem was to transfer health, weapons, and other variables into the different world. It took about 2-3 days until I figured out I could just use a constructor to transfer the variables. As time went on, more and more variables had to be added to both the player constructor and the world constructor.  Then another problem arose. Putting more than one portal in a room did not work. I figured out a solution that I didn’t like using, but is still used now. The portals are rotated and those rotations decide where the portal is taking you depending on what world your in (Ex. 180 degrees would be the portal in the “after” image at the top). I also had to use an integer to specify where I wanted the world to put me (ex. 1 = put me in preset location 1).

Unused Content

Things are usually made to be used in a game but some aren’t ever put in due to problems with functionality or it no longer being relevant to the game. When I made the game, I had different ideas on what the enemies were going to be, how the game would work as a whole, and other functions and mechanics. These are some things that I never got around to using.

shieldpickup

shield

Shield

The Shield was going to be an essential part of the game along with the health bar. It would regenerate over time and would give you enough time to either get away or get more health. It wasn’t implemented because, due to the fact you could increase you health and a module idea(Adding effects like regeneration, speed boost, etc. to the player) I had, I decided it wasn’t necessary.

nosoundskill

 

Level-Up System

Before the store system was made, I was going to develop a level-up system. Basically, you would collect experience points from an enemy and each enemy would yield a different amount. After the player collects a certain amount of experience, the player could “purchase” a skill from the experience screen. It was never completed and was replaced with the store.

“Rock” Weapon

playern rockpickup

The “Rock” weapon was a weapon idea to drop from the special variation of the Giga boss. Ideas of what I was going to make this weapon be was a larger rocket/explosion, launching a huge rock, or firing a wave-looking projectile. It was never added and was replaced with the rocket launcher drop.

 

lightspikespecial

Special Graphic for the Lightspike 

Originally the lightspike had a special graphic that was bigger than the original sprite. This was too give the player a challenge and the special variety would appear 1/7 times. It was removed when the collision code was not working. The lightspike no longer has a special image and the special image was reworked into the lite enemy of the game.

enemyrobot

Enemy Robot

The enemy robot is an enemy that I just never got around to adding. It was to act like the player using both the laser weapon and the blaster weapon. Of course, it looks visually different that the player, making it seem it was more designed for battle than the player.

playere (Blaster weapon for player)

Also, the enemy was also going to have a shield with it as well.

launcher4

Alternative Constructor for Launcher Enemy

The Launcher enemy has a constructor to turn and change the way I wanted it to. (ex. 2-sided turret that is rotated 90-degrees). This constructor was used until a better and more efficient one was made.
public Launcher(int rot, boolean u , boolean d, boolean l, boolean r, int amt, int s, int wt) //amount of turret sides, rotation
{
rotate = rot;
setRotation(rotate);
if (rotate != 0 && rotate != 90 && rotate != 180 && rotate != 270 && rotate != 360)
{
System.out.println("The allowed rotations are 0,90,180,270,360. Setting to 0 degree rotation.");
setRotation(0);
}
(More variables equaling the constructor variables here)
if (amount == 5)
{
setImage("launcher2alt.png");
}
if (amount == 4)
{
setImage("launcher4.png");
}
(More setting images code here)
if (amount != 1 && amount != 2 && amount != 3 && amount != 4 && amount != 5)
{
System.out.println("Not an acceptable amount of sides. Set to default 4 sided mode.");
setImage("launcher4.png");
}

The current constructor also isn’t really used, as there is only one variation of the launcher present in any of the worlds at the moment.

160 – 3D Pong

For the rest of the year, I’m going to highlight some impressive final projects in Computer Programming and BC Calculus.
The computer programming students have had the majority of the term to work on their projects and one of the requirements was to write a blog post about their experience.
Here’s a crosspost of a implementation of 3D Pong in processing. Neat idea, and although there are some bugs, really fun:

The New and Improved Pong (Now in the Third Dimension)

Making the game, I personally thought was pretty fun. Given, there were a couple of rough patches, but what code doesn’t have any rough patches? In the end, the game turned out almost exactly like I wanted it to. Just pong (because who doesn’t like pong) in the third dimension with a couple of other game variables added in. There were a couple of things I would’ve liked to add in like optional two-player mode, but in the end, I hope whoever plays it gets a little bit of enjoyment out of it.

Old Pong                                            My Pong

This is the original version of pong (to the left) versus my first person version(to the right) next to each other so you can really see the difference of the two up close.

Playing the Code

If you don’t have processing downloaded on your computer yet, here is a link to the game here on openprocesing.com. Though the game does work a little bit better by just running it in processing. (also, when you’re in processing, you can change the size of the game and it’ll change corresponding to the size). So, you can just copy the code from the link.

Controls

The controls are quite simple. You can simply move the player paddle by using the W, A, S, and D keys. Then you can change the AI paddle speed/difficulty by using the Up and Down arrow keys while you are playing. I just used some booleans that would become true if the key was pressed and false if it was released. I did this same code for the other keys too.

void keyPressed()
//code recognizing that "W" is being pushed
{
 //setting the keys
 if (key == 'W' || key =='w'){
 r = true;
 }
}
void keyReleased()
//code recognizing that "W" is not being pushed
{
 //again setting the keys
 if (key == 'W' || key == 'w'){
 r = false;
 }
}

Problems with the code

There were a couple (probably more than a couple) of problems that I ran into during this project like I had previously mentioned. One of the biggest problems was when the ball would randomly hit any of the walls it would get stuck on that wall but could still move forward and backward. So the X ad Y coordinates of the ball were locked in place. I ended up fixing it by putting method in whenever the ball hit one of the walls:

void changingspeed()
{
 boolean ballspeedneg = false;
 boolean ballxspeedneg = false;
 boolean ballyspeedneg = false;
//these lines are making the next x, y, or z speed negative if the previous one was also negative
//so that the ball doesn't change direction out of nowhere when it hits a wall
 if (ballspeed < 0){
 ballspeedneg = true;
 }
 if (ballxspeed < 0){
 ballxspeedneg = true;
 }
 if (ballyspeed < 0){
 ballyspeedneg = true;
 }
 if (ballspeed > 0){
 ballspeedneg = false;
 }
 if (ballxspeed > 0){
 ballxspeedneg = false;
 }
 if (ballyspeed > 0){
 ballyspeedneg = false;
 }
//these three functions are pretty much finding the x, y, and z speed of the ball depending on the level
 ballxspeed = getballxspeed(level);
 ballyspeed = getballyspeed(level);
 ballspeed = getballzspeed(level);
 if (ballspeedneg == true){
 ballspeed *= -1;
 }
 if (ballxspeedneg == true){
 ballxspeed *= -1;
 }
 if (ballyspeedneg == true){
 ballyspeed *= -1;
 }
}

What these lines of code do is first make a boolean true if the ball’s speed was negative. Then, it would use some functions to figure out what the ball’s speed should be because it changes corresponding to the level. Then if the boolean said that the previous speed was negative it multiplies the new speed by -1 (because it turned out the ball’s speed was constantly being changed from negative to positive so it would stay in the same place).

Level System of the Game

To change the level in the game, all I did was first make a variable (I used “bounces”) that would increase by one whenever it hit the player’s paddle like so:

if (ballz >= 270)
 {
 //ball only bounces off paddle
 backward = true;
 forward = false;
 if (ballx >= paddlex - 75 && ballx <= paddlex + 75 && bally <= paddley + 40 && bally >= paddley - 40){
//counts the number of times the paddle has succesfully deflected the paddle
 bounces += 1;
 ballspeed *= -1;
 changingspeed();
}

Then there was a method I made called “levelincrease” that would change the level according to how many times the ball has been succesfully deflected off of the player’s paddle

void levelincrease()
//this is increasing the level as the number of succesful bounces increase
{
  if (bounces > 1){
    level = 2;
  }
  if (bounces > 2){
    level = 3;
  }
  if (bounces > 3){
    level = 4;
  }
  if (bounces > 4){
    level = 5;
  }
  if (bounces > 5){
    level = 6;
  }
  if (bounces > 6){
    level = 7;
  }
  if (bounces > 7){
    level = 8;
  }
  if (bounces > 8){
    level = 9;
  }
  if (bounces > 9){
    level = 10;
  }
  else{
    level = level;
  }
}

This part of the code is in fact very easy to change, so if you wanted to, you could substitute the numbers shown and make levels longer or shorter depending on what you wanted. I also made the level you are currently on be displayed on the top part of the screen while you are playing the game.

Project picture Andrew Shaw

 

Hardest part of the Project

Easily the hardest part of the project was utilizing the two commands;

pushMatrix();
//and 
popMatrix();

These two lines of code close off the translations for each shape you are adding in to the game. So, for example if you want to translate a cube 3 units to the left, without using the two commands, you would just end up moving the whole virtual world 3 units to the left. It also didn’t help that I did not understand this until half way through the project (mostly why it was so difficult for me). So basically to negate this movement of the whole world when you only intend for one shape to move, you just have to put “pushMatrix();” before you translate and fill a shape, and then “popMatrix();” once you draw the shape afterwards.

Switching to 2 Player Mode

Switching it to two player mode was not hard at all. All I did was put an “if” statement into the 2nd paddle’s code that says if “twoplayer” is true than, the second paddle uses the arrow keys and if  “nottwoplayer” is true than the paddle automatically follows to the balls location without leaving its “z” coordinate.

 if (start == true && level != 0 && nottwoplayer == true)
 {
 }

 if (start == true && level != 0 && twoplayer == true)
 {
 }

Although there isn’t a seperate mode or gametype for each of the game styles, while you are in game, pressing the “p” button will change to two player and pressing “o” will change to single player.

Reasons for this Project

Pong is usually seen as an “easy” or “simple” project, because it completely is. But, I like the idea of the game and how much you can change it. So for this project, I knew I wanted to do something in 3D, but I didn’t want to do something that could have some very large problems because I would probably not know how to fix them considering I am still relatively new to the whole “coding in more than 2 dimensions” area. So I did pong because people are familiar with the idea, it would be understandable to manipulate on larger scales, there are unlimited things you can do with this game, and its fun! Then, I chose to use processing because I knew the language very well, and its the only program that can run 3D things that we learned about this year. I also just like the format of it. But overall, I thought this was a really fun project to do, and I hope that others can have as much fun with it as I did.

By: Andrew Shaw

159 – Blackjack

For the rest of the year, I’m going to highlight some impressive final projects in Computer Programming and BC Calculus.
The computer programming students have had the majority of the term to work on their projects and one of the requirements was to write a blog post about their experience.
Here’s a crosspost of a implementation of Blackjack. Some really cool work with arrays of images was worked on here. The end result may not exactly look crazy impressive, but the guts are there to make this much prettier:

For my final project in computer programming, I decided that I wanted to create a simulation of blackjack, the popular card game. I thought that it would be a fun project to work on, as I felt that there would be enough portions of it that would challenge me, while at the same time not being insurmountable.

BlackJackScreenCap

Before you get a chance to try out what I have, blackjack does have somewhat flexible rules, my version only uses a single deck of cards and the house will stand on a soft 17. Additionally, I had planned for there to be a way to bet in the game, but I unfortunately did not have time to properly implement that. Now that I’ve talked about it, here is the link to my game.

Dealing Cards

The way in which I selected cards to deal was in part taken from an earlier program that I wrote for BlueJ, which I used in GreenFoot. I have a value between 1 and 52 for each card in a standard 52 card deck, and I made this chart to help clarify for me which card had which value:

0606141217

The next thing that I had to deal with was ensuring that the same card was never dealt out twice (ex. 2 cases of 6 of hearts in the same hand). To do this I added have the following code ahead of where I add the value of the card to the ArrayLists in which I had the players’ hands:

while ((house.contains(tempCard) == true) || (player1.contains(tempCard) == true))
{
   tempCard = dealCard();
}

This essentially just looks at the ArrayLists that have the values of the hands ( house and player1 respectively) and sees if the new value is already present. If it is, the program simply finds a new value through the dealCard() method, and will continue this until it finds a value that is not already present. The rest of the code is mostly adding the card to the necessary ArrayLists and creating the Card object:

//Deals give the card to the players based on whose turn it is.
if (playerTurn1 == true)
{
   //Puts the value out of 52 into an ArrayList
   player1.add(tempCard);

   //finds the value the card would have in blackjack, nad then adds it to another ArrayList
   if ((tempCard % 13 == 0) || (tempCard % 13 == 12) || (tempCard % 13 == 11))
   {
      playerVal1.add(10);
   }
   else if (tempCard % 13 == 1)
   {
      playerVal1.add(11);
   }
   else
   {
      playerVal1.add(tempCard % 13);
   }

   //Creates a Card object in the world, increases the deal count, and has a slight delay.
   addObject(new Card(tempCard), 0 + xPlayerAdd, getHeight()/4 + yAdd);
   xPlayerAdd +=(getWidth()/8);
   deal ++;
   Greenfoot.delay(5);
}
//the code here is the same as directly above, just for the house instead of player1.
else if (houseTurn == true)
{ 
   house.add(tempCard);
   if ((tempCard % 13 == 0) || (tempCard % 13 == 12) || (tempCard % 13 == 11))
   {
      houseVal.add(10);
   }
   else if (tempCard % 13 == 1)
   {
      houseVal.add(11);
   }
   else
   {
      houseVal.add(tempCard % 13);
   }
   addObject(new Card(tempCard), 0 + xHouseAdd, getHeight()/4 );
   xHouseAdd +=(getWidth()/8);
   deal ++;
   Greenfoot.delay(5);
 }

 

Images of Cards

As I decided to do my project in GreenFoot,  I also needed to create a visual representation of the cards. I immediately ruled out creating 52 separate classes for the cards, as that would be excessively long. I eventually decided to create an ArrayList of GreenFoot Images, and get the image from the list based on the value each card has. This was still rather long and tedious, even if it was better than the alternatives it was essentially the following code repeated 52 times with the file name changed:

GreenfootImage g = new GreenfootImage("40px-Playing_card_spade_A.svg.png");
images.add(g);

I had gotten this ArrayList sorted out but I then had another issue, and this ended up halting my progress for several days. I needed to find a way to have the Card class have access to both the ArrayList of images as well as the value that each specific card had when it was created. I first attempted to pass both the value of the card and the ArrayList of GreenFoot images to the Card class, however I ran into an issue where I needed the specific instance of the World class. I searched for a way to do this, but they few results I managed to find were fairly long and I did not understand them at all. I eventually abandoned this approach in favor creating an entirely new class, Methods, and making my Card and Deck classes subclasses of Methods. I thought that by doing this Deck and Card would have the values of any variable I had assigned in methods, but I later learned that this was not how the relationship between subclasses and superclass worked, and I had to change my approach again. Eventually, I went back to my original plan of attempting to pass information, and after refining my original searches I was successful. The second was that I did eventually find way to get the specific instance of my CardWorld class in a fairly concise manner:

((CardWorld) getWorld()).genericMethodHere();

This was able to solve my primary issue with this, however another soon appeared, specifically when I dealt the initial four cards of the round (2 for each player) all of the images were the same, even though their values in the ArrayLists were different. I finally found that this was a result of how I was passing the cards their values. The value was stored in a variable that I was passing, but because the cards were being created in the same method they could not ask for the variable until after they were all created, and so they all received the same variable value. I resolved this issue fairly simply by adding a constructor to my Card class, which allowed me to give the Card its value as soon as it was created. The final code to assign the cards their images is below, and I find that it now works extremely well for what I need:

images = ((CardWorld) getWorld()).GiveImages();
setImage(images.get(CardVal - 1));

This may seem like an extremely long long section on an issue that seems fairly simple to resolve, and I agree. This is due to the fact that what was in reality a few very simple to solve issues holding me up for a quite a few days. I am certain that if had resolved this earlier I could have made much more progress, and I regret that I was not able to.

The Game

After I had ensured that dealing cards was fully functional, I then set out to add in the rules of the game. The first thing that I worked out was the turns for the players (ex. the player chooses to hit or stand, then the house). This was somewhat tricky to work out, however in the end it eventually just came down to some variables being added to determine which player to deal to. After this I had to come up with a way to add up the total value of the cards in a player’s hand, rather than using multiple for loops, I just made the following function, with a parameter for the ArrayList to be added:

public int handSums(ArrayList<Integer> hand)
{
   int sum = 0;
   //add up the cards for the given hand.
   for (int i = 0; i < hand.size(); i++)
   {
      sum += hand.get(i);
   }
   return sum;
}

This function ended up being invaluable to me, as I continued with my project I used this many times I then created buttons that would allow the player to choose whether they wanted to hit, stand, or double down. The latter was added as an option because of the betting system I hoped to add, this would have dealt one more card to the player, doubled their bet,  It currently only deals one card and ends the turn.

ButtonsScreenCap

The code for the house was even simpler however, essentially just drawing until their hand total is over 17:

public void houseDeal()
{
   while (handSums(houseVal) < 17)
   {
      nextCard();
   }
   roundOver = true;
}

 

Winning and Losing

After I had the turns working correctly and players’ hands being added properly, the next thing I needed to do was determine whether the player won or lost. For the most part this was simply a lot of if statements for various circumstances, then running a method to pop up a message informing the player if they won, as well as if they or the house had gotten a blackjack (Ace and King/Queen/Jack/10). There was one portion of this that was somewhat tricky however. In Blackjack, the value of an Ace is normally 11, but if the hand an Ace is in has a total value of over 21, that Ace’s value can be changed to a one. Because of this I had to design a method to do this:

public void checkAce(ArrayList<Integer> hand)
{
   if ((handSums(hand) > 21) && (hand.contains(11) == true))
   {
      hand.set(hand.indexOf(11),1);
   }
}

The method itself was fairly simple, what was harder was determining where and when I needed to implement it. There were a number of places it was needed, and finding the correct spot to check for the Ace was very difficult at times.

Rounds

The final thing I implemented in my program was the ability to transition from one round to another. Before this the program would start, the players would hit or stand, the winner would be determined, and then the program would end; if you wanted to play another round you would have to restart the program entirely. I mainly accomplished this by passing some variables in order to tell the different classes to prepare for a new round, but I also had one main method which primarily clears the ArrayLists for the hands, reset some starting variables, and delete all of the cards on the screen:

public void clearHands()
{
   for (int i = (house.size() - 1); i >= 0; i--)
   {
      house.remove(i);
   }
   for (int i = (houseVal.size() - 1); i >= 0; i--)
   {
      houseVal.remove(i);
   }
   for (int i = (player1.size() - 1); i >= 0; i--)
   {
      player1.remove(i);
   }
   for (int i = (playerVal1.size() - 1); i >= 0; i--)
   {
      playerVal1.remove(i);
   }
   List<Card> cards = getObjects(Card.class);
   removeObjects(cards);
   removeObjects(getObjectsAt(getWidth()/2, getHeight()/2,RoundButton.class));
   xPlayerAdd = (getWidth()/8);
   xHouseAdd = (getWidth()/8);
   startRound = true;
   roundOver = false;
}

At first I had the round changing on its own after a brief delay, but I experienced some issues with this, namely the last card for the player, and any additional cards the house was dealt would not be assigned their images, instead the winner was announced and delay would happen, then the next round would start without assigning the images. I determined that this was basically because the program was stuck in a loop until the next round could start, and so the cards never had the opportunity to assign their images. I solved this issue by creating a new button instead of ending the round, effectively eliminating the loop before the next round started. When the player clicks the button the button then calls the function to end the round,clear the hands, and finally delete the button itself.

RoundButtonScreenCap

This not only solves the problem with the loop, but also allows the player to take as much time as they need to bring up the terminal to see who won, as well as to look at what cards they and the house had. The latter effect was not intended, but I find that I actually like the way this currently works much more.

Conclusion

I feel that my project went fairly well for me, and while I wish I could have done much more (betting, nicer images, making the whole program cleaner, etc.), I am still pleased with what I have accomplished. I had several challenges along the way, some of which caught me up far longer than they should have (passing information between classes), but beyond those, I feel the project went very well, and I had an enjoyable time creating, and hope to someday return to it.