Skip to content

Instantly share code, notes, and snippets.

View NatashaTheRobot's full-sized avatar

Natasha Murashev NatashaTheRobot

View GitHub Profile
@NatashaTheRobot
NatashaTheRobot / HailstoneSolution
Created November 2, 2011 01:46
This is the solution to the Hailstone problem from Assignment 2 of the Stanford CS106A Introduction to Programming Methodology Class
/*
* File: Hailstone.java
* Name:
* Section Leader:
* --------------------
* This file is the starter file for the Hailstone problem.
*/
import acm.program.*;
@NatashaTheRobot
NatashaTheRobot / FibonacciSequenceSolution
Created November 2, 2011 20:18
This is the solution to the Fibonacci Sequence problem from Section Assignment 2 of the Stanford CS106A Introduction to Programming Methodology Class
/*
* This is the solution to the Section Handout #2 from the
* Stanford CS106A online class
*/
import acm.program.*;
public class FibonacciSequence extends ConsoleProgram {
private static final int MAX_TERM_VALUE = 10000;
@NatashaTheRobot
NatashaTheRobot / RobotFaceSolution
Created November 3, 2011 00:00
This is the solution to the Robot Face problem from Section Assignment 2 of the Stanford CS106A Introduction to Programming Methodology Class
import acm.graphics.*;
import acm.program.*;
import java.awt.*;
public class DrawFace extends GraphicsProgram {
private static final int head_width = 100;
private static final int head_height = 200;
@NatashaTheRobot
NatashaTheRobot / BreakoutBrickSetup
Created November 9, 2011 06:28
This is the solution to step 1 of the Stanford CS106A Breakout game assignment, setting up the bricks.
//adding an individual brick object
private GRect brick;
//drawing all the bricks necessary for the game
private void drawBricks(double cx, double cy) {
/*need to have several columns in each row
* so there need to be two for loops,
* one for loop for the rows and one for loop for the columns.
*/
@NatashaTheRobot
NatashaTheRobot / BreakoutCreatePaddle
Created November 9, 2011 06:38
This is the solution to step 2 of the Stanford CS106A Breakout game assignment, creating a paddle and making it track with the mouse.
//adding individual paddle object
private GRect paddle;
private double lastX;
//paddle set-up
private void drawPaddle() {
//starting the paddle in the middle of the screen
double x = getWidth()/2 - PADDLE_WIDTH/2;
//the paddle height stays consistent throughout the game
//need to make sure to subtract the PADDLE_HEIGHT,
@NatashaTheRobot
NatashaTheRobot / BreakoutCreateBounceBall
Created November 9, 2011 23:05
This is the solution to step 3 of the Stanford CS106A Breakout game assignment, creating a ball and making it bounce off the walls
//These are declared outside the method, but in the class.
/**Ball velocity*/
private double vx, vy;
/**Random number generator for vx*/
private RandomGenerator rgen = RandomGenerator.getInstance();
/** Animation delay or paust time between ball moves */
private static final int DELAY = 10;
@NatashaTheRobot
NatashaTheRobot / BreakoutCheckCollisions
Created November 10, 2011 05:42
This is the solution to step 4 of the Stanford CS106A Breakout game assignment, checking for collisions off the paddle and brick
private void moveBall() {
ball.move(vx, vy);
//check for walls
//need to get vx and vy at the point closest to 0 or the other edge
if ((ball.getX() - vx <= 0 && vx < 0 )|| (ball.getX() + vx >= (getWidth() - BALL_RADIUS*2) && vx>0)) {
vx = -vx;
}
//We don't need to check for the bottom wall, since the ball can fall through the wall at that point
if ((ball.getY() - vy <= 0 && vy < 0 )) {
vy = -vy;
@NatashaTheRobot
NatashaTheRobot / BreakoutBallPaddleUnstuck
Created November 10, 2011 22:37
This is the solution to prevent the Breakout game ball to get "glued" to the "sticky" paddle for the Stanford CS106A Class
if (collider == paddle) {
/* We need to make sure that the ball only bounces off the top part of the paddle
* and also that it doesn't "stick" to it if different sides of the ball hit the paddle quickly and get the ball "stuck" on the paddle.
* I ran "println ("vx: " + vx + ", vy: " + vy + ", ballX: " + ball.getX() + ", ballY: " +ball.getY());"
* and found that the ball.getY() changes by 4 every time, instead of 1,
* so it never reaches exactly the the height at which the ball hits the paddle (paddle height + ball height),
* therefore, I estimate the point to be greater or equal to the height at which the ball hits the paddle,
* but less than the height where the ball hits the paddle minus 4.
*/
@NatashaTheRobot
NatashaTheRobot / HangmanConsole
Created November 12, 2011 08:04
This is the solution for part 1 of the Stanford CS106A Hangman Game, the Console - Based Hangman Game
/*
* File: Hangman.java
* ------------------
* This program will eventually play the Hangman game from
* Assignment #4.
*/
import acm.graphics.*;
import acm.program.*;
import acm.util.*;
@NatashaTheRobot
NatashaTheRobot / HangmanLexicon
Created November 17, 2011 22:50
This is the solution for part 3 of the Stanford CS106A Hangman Game, the HangmanLexicon Solution
/*
* File: HangmanLexicon.java
* -------------------------
* This file contains a stub implementation of the HangmanLexicon
* class that you will reimplement for Part III of the assignment.
*/
import acm.util.*;
import java.io.*;
import java.util.*;