Monday, September 30, 2013

Trick the Turtle: Adding Sound

Today we will be playing with adding sound to our program.

Video #11:  Adding Sound


Some sources of WAV or MP3 sound files:
A tool that you can get to play with sounds is called BP Minus (which was written by Jacob Johnson, a former student).  You can download the software here (http://bpminus.com/) for your home computers, but we already have it installed on our systems.

Spend today adding sounds to your program.

Friday, September 27, 2013

Trick the Turtle: Adding Control

Today we will be adding keyboard control to our programs so we can "drive" the turtle around, and then we will be changing the graphics to customize our programs.

Video #10: http://www.youtube.com/watch?v=1nbpdro6gP4 (Add Keyboard Control)
Video #11: http://www.youtube.com/watch?v=GXO3V5-lbzk (Customize Graphics)

Updated Code: http://www.greenfoot.org/static/joc/material/trick-the-turtle-v3.zip
(This code includes the snakes and some keyboard control)

Thursday, September 26, 2013

Trick the Turtle: Cleaning Up the Code and Adding Bad Guys

Continue with Trick the Turtle

A fresh copy of the Trick the Turtle Source Code:
http://www.greenfoot.org/static/joc/material/trick-the-turtle-v2.zip

Video #8: http://youtu.be/Ep6Z7oxM7V8 (Cleaning Up Code)
Video #9: http://youtu.be/prpvOqWOo7M (Adding "Bad Guys")

Wednesday, September 25, 2013

Coding with Greenfoot: Trick the Turtle (Continued)

Today we will watch and follow the video series:

We will be building in random movement and then adding a food source for our turtle.

Tuesday, September 24, 2013

Coding with Greenfoot: Trick the Turtle

We will view [and work through] two parts of the series today:


You can download the source for this project here:


In this session Mik will be discussing:
  • method call
  • method definition
  • parameter
Please follow along with him using the source code.  This will be the foundation for our first "graphic game".

Monday, September 23, 2013

Beginning Greenfoot: Objects and Classes

Today we will begin a series of videos by Michael Koelling -- a programmer, instructor and developer of the Greenfoot JAVA IDE.  His blog can be found here: http://blogs.kent.ac.uk/mik/category/joy-of-code/page/2/

We will be working with the following "Scenario": http://www.greenfoot.org/static/joc/material/hedgehogs.zip

Some of the topics Mik will cover in this video include (and please take notes on this):
  • class
  • object
  • method
  • instance
  • return value
  • return type
  • void
  • int
  • boolean
Some of these concepts may already be familiar to you, but they are crucial to fully understand JAVA.

Video #3 of the series: http://youtu.be/tZNnYeqm5BU

Friday, September 20, 2013

Case Study: Rock, Paper, Scissors

I want to look at the following code before you begin building your own.  Copy the code below to a new Class (RockPaperScissors) and then "Auto Format" the code to see how that works.

This is a VERY different approach than what we've been doing so far.  They use a few codes we haven't seen before (i.e. boolean, String, while, nextLine, toLowerCase, ||, concat, etc.).  What are they doing?  What is "broken" in the code below?

Rock, Paper, Scissors:

import java.util.Scanner;
public class RockPaperScissors {
public static void main(String[] args) {
CPU cpu1 = new CPU();
Scanner sc1 = new Scanner(System.in);
boolean validmove = false;
String userMove = "";
while(!validmove){
System.out.println("Input your move (rock, paper or scissors): ");
userMove = sc1.nextLine();
userMove = userMove.toLowerCase();
if(userMove.equals("rock") || userMove.equals("paper")||userMove.equals("scissors")){
validmove = true;
}
}
String CPUMove = cpu1.getCPUMove();
cpu1.comparemoves(CPUMove, userMove);
}
}
class CPU{
public void comparemoves(String CPUMove, String userMove){
if(userMove.equals("rock")){
if(CPUMove.equals("rock")){
outputmoves("rock", "Tie!");
}
if(CPUMove.equals("paper")){
outputmoves("paper", "I win!");
}
if(CPUMove.equals("scissors")){
outputmoves("scissors", "You win!");
}
}
if(userMove.equals("paper")){
if(CPUMove.equals("rock")){
outputmoves("rock", "You win!");
}
if(CPUMove.equals("paper")){
outputmoves("paper", "Tie!");
}
if(CPUMove.equals("scissors")){
outputmoves("scissors", "I win!");
}
}
if(userMove.equals("scissors")){
if(CPUMove.equals("rock")){
outputmoves("rock", "I win!");
}
if(CPUMove.equals("paper")){
outputmoves("paper", "You win!");
}
if(CPUMove.equals("Scissors")){
outputmoves("scissors", "Tie!");
}
}
}
public void outputmoves(String cpuout, String status){
String output = "I played ".concat(cpuout).concat(".").concat(status);
System.out.println(output);
}
public String getCPUMove(){
int choice = (int) Math.floor(Math.random()*3);
String rpsmove = "";
switch(choice){
case 0: rpsmove = "rock"; break;
case 1: rpsmove = "paper"; break;
default: rpsmove = "scissors"; break;
}
return rpsmove;
}
}