-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPortalPair.java
67 lines (67 loc) · 2.43 KB
/
PortalPair.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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
///////////////////////////////////////////////////////////////////////////////
// ALL STUDENTS COMPLETE THESE SECTIONS
// Main Class File: Game.java
// File: PortalPair.java
// Semester: Fall 2015
//
// Author: Nawal Dua
// CS Login: nawal
// Lecturer's Name: Deb Deppler
// Lab Section: 311
//
///////////////////////////////////////////////////////////////////////////////
/**
* This class constructs the portal pair and includes the method that teleports
* snake to the other portal.
*
* <p>Bugs: None that are known
*
* @author Nawal Dua
*/
public class PortalPair
{
private GraphicObject bluePortal;
private GraphicObject orangePortal;
// Create private field to hold the GraphicObject associated with the blue portal
// Create private field to hold the GraphicObject associated with the orange portal
/**
* Constructs the portal pair
*
* @param name - The name of the portal pair
* @param blueX - the x coordinate of the blue portal
* @param blueY - the y coordinate of the blue portal
* @param orangeX - the x coordinate of the orange portal
* @param orangeY - the y coordinate of the orange portal
*/
public PortalPair(String name, float blueX, float blueY,
float orangeX, float orangeY)
{
// Initialize the GraphicObjects associated with the blue and orange
// portals, setting the type to "BLUE_PORTAL_name" or
// "ORANGE_PORTAL_name", respectively, and setting their x and y
// coordinates appropriately
bluePortal = new GraphicObject ("BLUE_PORTAL_"+name, blueX, blueY);
orangePortal = new GraphicObject ("ORANGE_PORTAL_"+name, orangeX,
orangeY);
}
/**
* teleports the snake from one of the portals to the other
*
* @param snake - an instance of the Snake class
* @return void
*/
public void teleportSnakeIfColliding(Snake snake)
{
// If the blue portal is colliding with the snake's head's GraphicObject,
// move the snake's head's GraphicObject past the orange portal
if (bluePortal.isCollidingWith(snake.getGraphicObject())){
snake.getGraphicObject().movePast(orangePortal);
}
// If the orange portal is colliding with the snake's head's
// GraphicObject, move the snake's head's GraphicObject past the
// blue portal
if (orangePortal.isCollidingWith(snake.getGraphicObject())){
snake.getGraphicObject().movePast(bluePortal);
}
}
}