-
Notifications
You must be signed in to change notification settings - Fork 0
/
Rock.java
52 lines (51 loc) · 1.46 KB
/
Rock.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
///////////////////////////////////////////////////////////////////////////////
// ALL STUDENTS COMPLETE THESE SECTIONS
// Main Class File: Game.java
// File: Rock.java
// Semester: Fall 2015
//
// Author: Nawal Dua
// CS Login: nawal
// Lecturer's Name: Deb Deppler
// Lab Section: 311
//
///////////////////////////////////////////////////////////////////////////////
/**
* This class constructs the rock and has the method that kills the snake when
* the snake collides with the rock.
*
* <p>Bugs: None that are known
*
* @author Nawal Dua
*/
public class Rock
{
private GraphicObject rock;
// Create private field to hold the GraphicObject associated with this rock
/**
* constructor for the rocks
*
* @param x - the X coordinate for the rock
* @param y - the Y coordinate for the rock
*/
public Rock(float x, float y)
{
this.rock = new GraphicObject ("ROCK", x, y);
// Initialize this rock's associated GraphicObject with type "ROCK" at
// this rock's x and y coordinates
}
/**
* Kills the snake if it collides with rock by calling the die() method
*
* @param snake - an instance of the Snake class
* @return void
*/
public void killSnakeIfColliding(Snake snake)
{
// If this rock is colliding with the snake's head's GraphicObject, kill
// the snake
if (rock.isCollidingWith(snake.getGraphicObject())){
snake.die();
}
}
}