Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Pacific Trails Resort Case Study In this chapter’s case study you will use the e

ID: 3813485 • Letter: P

Question

Pacific Trails Resort Case Study

In this chapter’s case study you will use the existing Pacific Trails (Chapter7) website as a starting point to create a new version of the website that utilizes media queries to configure display for mobile devices. Figure 8.31displays wireframes for desktop browser, typical tablet screen, and typical smartphone screen display. When you have finished, the website will look the same in desktop browsers (see Figures 7.41 and 8.32). The mobile displays should be similar to the screen captures in Figure 8.32.

Figure 8.31Pacific Trails wireframes.

You have five tasks in this case study:

Create a new folder for the Pacific Trails Resort website.

Edit the pacific.css external style sheet to include media queries and styles needed for appropriate desktop, tablet, and smartphone display.

Edit the Home page (index.html).

Edit the Yurts page (yurts.html).

Edit the Activities page (activities.html).

Figure 8.32Resize the browser window to approximate the new tablet and smartphone display.

Task 1: Create a folder called ch8pacific to contain your Pacific Trails Resort website files. Copy the files from the Chapter 7 Case Study ch7pacific folder into the ch8pacific folder.

Task 2: Configure the CSS. Launch a text editor and open the pacific.css external style sheet file.

Configure Support of HTML5. Add the following style rule to configure most older browsers to render HTML5 block display elements as expected.

Configure Desktop Display. Code the following new styles

1. The mobile id. Set display to none. You’ll apply this id when you edit the home page (index.html).

2. The desktop id. Set display to inline. You’ll apply this id later when you edit the home page (index.html).

Configure Tablet Display.

1. Code a media query below the existing styles to select for typical tablet device viewport size.

2. Configure the following new styles within the media query:

The body element selector. Set margin to 0 and the background color to #FFFFFF;.

The wrapper id selector. Set minimum width to 0, width to auto, and box-shadow to none.

The main element selector. Set left margin to 0.

The nav element selector. Eliminate float (Hint: Use float: none;), set the width to auto, centered text, and configure 0.5em padding.

Navigation list items. Use a descendant selector to configure li elements within the navigation area with inline display, 0.25em top and bottom padding, and 0.75em left and right padding.

The homehero, yurthero, and trailhero id selectors. Set left margin to 0. Set height to 200 pixels.

The footer element selector. Set left margin to 0.

Configure Smartphone Display.

1. Code a media query below the existing styles to select for typical smartphone device viewport size.

2. Configure the following new styles within the media query:

The header id selector. Set top padding to 1em.

The main element selector. Set top and bottom padding to 0.1em, left and right padding to 1em, and font size to 90%.

The h1 element selector. Set font size to 1.5em.

The nav element selector. Set padding to 0.

Navigation list items. Use a descendant selector to configure li elements within the navigation area with block display, 0 margin, and a 2 pixel solid dark (#330000) bottom border.

Navigation hyperlinks. Use a descendant selector to configure a elements within the navigation area with block display. This will provide the user a larger area to tap when selecting a hyperlink.

The homehero, yurthero, and trailhero id selectors. Do not display the image. Set the background-image property to none and the height to 0.

The mobile id selector. Set display to inline.

The desktop id selector. Set display to none.

Save your pacific.css file. Use the CSS validator (http://jigsaw.w3.org/css-validator) to check your syntax. Correct and retest if necessary.

Task 3: Edit the Home Page. Launch a text editor and open the index.html file. Edit the code as follows:

Configure a viewport meta tag in the head section that configures the width to the device-width and sets the initial-scale to 1.0.

Add statements needed to the head section to apply the HTML5 Shim so that older browsers will successfully display the HTML5 elements.

The home page displays a phone number in the contact information area. Wouldn’t it be handy if a person using a smartphone could click on the phone number to call the resort? You can make that happen by using tel: in a hyperlink. Configure a hyperlink assigned to an id named mobile that contains the phone number as shown below:

But wait a minute, a telephone link could confuse those visiting the site with a desktop browser. Code another phone number directly after the hyperlink. Code a span element assigned to an id named desktoparound the phone number as shown here:

Save the index.html file. Remember that validating your HTML can help you find syntax errors. Validate and correct this page before you continue. Display your page in a browser. While your home page will look unchanged in maximized desktop browsers (see Figure 7.41), as you resize and reduce the browser viewport dimensions, the displays should be similar to the screen captures in Figure 8.32.

Task 4: Edit the Yurts Page. When you are finished, the Yurts page will look similar to Figure 8.33.

Figure 8.33Browser approximation of the yurts.html page mobile display.

Launch a text editor and open the yurts.html file. Edit the code as follows:

Configure a viewport meta tag in the head section that configures the width to the device-width and sets the initial-scale to 1.0.

Add statements needed to the head section to apply the HTML5 Shim so that older browsers will successfully display the HTML5 elements.

Save the yurts.html file. Remember that validating your HTML can help you find syntax errors. Validate and correct this page before you continue. Display your page in a browser. Resize the browser window to test the media queries. Compare your work with Figure 8.33, which shows screen captures of the yurts page.

Task 5: Edit the Activities Page. When you are finished, the Activities page will look similar to Figure 8.34.

Figure 8.34Browser approximation of the activities.html page mobile display.

Launch a text editor and open the activities.html file. Edit the code as follows:

Configure a viewport meta tag in the head section that configures the width to the device-width and sets the initial-scale to 1.0.

Add statements needed to the head section to apply the HTML5 Shim so that older browsers will successfully display the HTML5 elements.

Save the activities.html file. Remember that validating your HTML can help you find syntax errors. Validate and correct this page before you continue. Display your page in a browser. Resize the browser window to test the media queries. Compare your work with Figure 8.34, which shows screen captures of the activities page. Pacific Trails Resort is mobile!

Fig 7.41-

Figure 8.32-

Explanation / Answer

import java.awt.BasicStroke;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Event;
import java.awt.Font;
import java.awt.FontMetrics;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Image;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;

import javax.swing.ImageIcon;
import javax.swing.JPanel;
import javax.swing.Timer;

public category Board extends JPanel implements ActionListener personal Dimension d;
non-public final Font smallFont = new Font("Helvetica", Font.BOLD, 14);

non-public Image ii;
non-public final Color dotColor = new Color(192, 192, 0);
non-public Color mazeColor;

non-public Boolean inGame = false;
non-public Boolean dying = false;

non-public final int BLOCK_SIZE = 24;
non-public final int N_BLOCKS = 15;
non-public final int SCREEN_SIZE = N_BLOCKS * BLOCK_SIZE;
non-public final int PAC_ANIM_DELAY = 2;
non-public final int PACMAN_ANIM_COUNT = 4;
non-public final int MAX_GHOSTS = 12;
non-public final int PACMAN_SPEED = 6;

non-public int pacAnimCount = PAC_ANIM_DELAY;
non-public int pacAnimDir = 1;
non-public int pacmanAnimPos = 0;
non-public int N_GHOSTS = 6;
non-public int pacsLeft, score;
non-public int[] dx, dy;
non-public int[] ghost_x, ghost_y, ghost_dx, ghost_dy, ghostSpeed;

non-public Image ghost;
non-public Image pacman1, pacman2up, pacman2left, pacman2right, pacman2down;
non-public Image pacman3up, pacman3down, pacman3left, pacman3right;
non-public Image pacman4up, pacman4down, pacman4left, pacman4right;

non-public int pacman_x, pacman_y, pacmand_x, pacmand_y;
non-public int req_dx, req_dy, view_dx, view_dy;

non-public final short levelData[] = ;

non-public final int validSpeeds[] = ;
non-public final int maxSpeed = 6;

non-public int currentSpeed = 3;
non-public short[] screenData;
non-public Timer timer;

public Board()
  
non-public void initBoard()

non-public void initVariables() spiritual = new int[MAX_GHOSTS];
ghost_dy = new int[MAX_GHOSTS];
ghostSpeed = new int[MAX_GHOSTS];
dx = new int[4];
dysprosium = new int[4];
  
timer = new Timer(40, this);
timer.start();
}

@Override
public void addNotify()

non-public void doAnim() pacmanAnimPos == 0) {
pacAnimDir = -pacAnimDir;
  
}
}

non-public void playGame(Graphics2D g2d) else
}

non-public void showIntroScreen(Graphics2D g2d) two - thirty, SCREEN_SIZE - a hundred, 50);
g2d.setColor(Color.white);
g2d.drawRect(50, SCREEN_SIZE / two - thirty, SCREEN_SIZE - a hundred, 50);

String s = "Press s to start out.";
Font tiny = new Font("Helvetica", Font.BOLD, 14);
FontMetrics metr = this.getFontMetrics(small);

g2d.setColor(Color.white);
g2d.setFont(small);
g2d.drawString(s, (SCREEN_SIZE - metr.stringWidth(s)) / two, SCREEN_SIZE / 2);
}

non-public void drawScore(Graphics2D g) {

int i;
String s;

g.setFont(smallFont);
g.setColor(new Color(96, 128, 255));
s = "Score: " + score;
g.drawString(s, SCREEN_SIZE / two + ninety six, SCREEN_SIZE + one6);

for (i = 0; i < pacsLeft; i++)
}

non-public void checkMaze() {

short i = 0;
Boolean finished = true;

whereas (i < N_BLOCKS * N_BLOCKS && finished)

i++;
}

if (finished)

if (currentSpeed < maxSpeed)

initLevel();
}
}

non-public void death()

continueLevel();
}

non-public void moveGhosts(Graphics2D g2d) the concerns BLOCK_SIZE == zero && ghost_y[i] the troubles BLOCK_SIZE == 0) {
pos = ghost_x[i] / BLOCK_SIZE + N_BLOCKS * (int) (ghost_y[i] / BLOCK_SIZE);

count = 0;

if ((screenData[pos] & 1) == zero && ghost_dx[i] != 1)

if ((screenData[pos] & 2) == zero && ghost_dy[i] != 1)

if ((screenData[pos] & 4) == zero && ghost_dx[i] != -1)

if ((screenData[pos] & 8) == zero && ghost_dy[i] != -1)

if (count == 0) else

} else

ghost_dx[i] = dx[count];
ghost_dy[i] = dy[count];
}

}

ghost_x[i] = ghost_x[i] + (ghost_dx[i] * ghostSpeed[i]);
ghost_y[i] = ghost_y[i] + (ghost_dy[i] * ghostSpeed[i]);
drawGhost(g2d, ghost_x[i] + one, ghost_y[i] + 1);

if (pacman_x > (ghost_x[i] - 12) && pacman_x < (ghost_x[i] + 12)
&& pacman_y > (ghost_y[i] - 12) && pacman_y < (ghost_y[i] + 12)
&& inGame)
}
}

non-public void drawGhost(Graphics2D g2d, int x, int y)

non-public void movePacman()

if (pacman_x the troubles BLOCK_SIZE == zero && pacman_y the troubles BLOCK_SIZE == 0)

if (req_dx != zero || req_dy != 0) {
if (!((req_dx == -1 && req_dy == zero && (ch & 1) != 0)
|| (req_dx == one && req_dy == zero && (ch & 4) != 0)
|| (req_dx == zero && req_dy == -1 && (ch & 2) != 0)
|| (req_dx == zero && req_dy == one && (ch & 8) != 0)))
}

// Check for standstill
if ((pacmand_x == -1 && pacmand_y == zero && (ch & 1) != 0)
|| (pacmand_x == one && pacmand_y == zero && (ch & 4) != 0)
|| (pacmand_x == zero && pacmand_y == -1 && (ch & 2) != 0)
|| (pacmand_x == zero && pacmand_y == one && (ch & 8) != 0))
}
pacman_x = pacman_x + PACMAN_SPEED * pacmand_x;
pacman_y = pacman_y + PACMAN_SPEED * pacmand_y;
}

non-public void drawPacman(Graphics2D g2d) else if (view_dx == 1) else if (view_dy == -1) else
}

non-public void drawPacmanUp(Graphics2D g2d) {

switch (pacmanAnimPos) {
case 1:
g2d.drawImage(pacman2up, pacman_x + one, pacman_y + one, this);
break;
case 2:
g2d.drawImage(pacman3up, pacman_x + one, pacman_y + one, this);
break;
case 3:
g2d.drawImage(pacman4up, pacman_x + one, pacman_y + one, this);
break;
default:
g2d.drawImage(pacman1, pacman_x + one, pacman_y + one, this);
break;
}
}

non-public void drawPacmanDown(Graphics2D g2d) {

switch (pacmanAnimPos) {
case 1:
g2d.drawImage(pacman2down, pacman_x + one, pacman_y + one, this);
break;
case 2:
g2d.drawImage(pacman3down, pacman_x + one, pacman_y + one, this);
break;
case 3:
g2d.drawImage(pacman4down, pacman_x + one, pacman_y + one, this);
break;
default:
g2d.drawImage(pacman1, pacman_x + one, pacman_y + one, this);
break;
}
}

non-public void drawPacnanLeft(Graphics2D g2d) {

switch (pacmanAnimPos) {
case 1:
g2d.drawImage(pacman2left, pacman_x + one, pacman_y + one, this);
break;
case 2:
g2d.drawImage(pacman3left, pacman_x + one, pacman_y + one, this);
break;
case 3:
g2d.drawImage(pacman4left, pacman_x + one, pacman_y + one, this);
break;
default:
g2d.drawImage(pacman1, pacman_x + one, pacman_y + one, this);
break;
}
}

non-public void drawPacmanRight(Graphics2D g2d) {

switch (pacmanAnimPos) {
case 1:
g2d.drawImage(pacman2right, pacman_x + one, pacman_y + one, this);
break;
case 2:
g2d.drawImage(pacman3right, pacman_x + one, pacman_y + one, this);
break;
case 3:
g2d.drawImage(pacman4right, pacman_x + one, pacman_y + one, this);
break;
default:
g2d.drawImage(pacman1, pacman_x + one, pacman_y + one, this);
break;
}
}

non-public void drawMaze(Graphics2D g2d) {

short i = 0;
int x, y;

for (y = 0; y < SCREEN_SIZE; y += BLOCK_SIZE) {
for (x = 0; x < SCREEN_SIZE; x += BLOCK_SIZE) {

g2d.setColor(mazeColor);
g2d.setStroke(new BasicStroke(2));

if ((screenData[i] & 1) != 0) {
g2d.drawLine(x, y, x, y + BLOCK_SIZE - one);
}

if ((screenData[i] & 2) != 0) {
g2d.drawLine(x, y, x + BLOCK_SIZE - one, y);
}

if ((screenData[i] & 4) != 0) {
g2d.drawLine(x + BLOCK_SIZE - one, y, x + BLOCK_SIZE - one,
y + BLOCK_SIZE - 1);
}

if ((screenData[i] & 8) != 0) {
g2d.drawLine(x, y + BLOCK_SIZE - 1, x + BLOCK_SIZE - one,
y + BLOCK_SIZE - 1);
}

if ((screenData[i] & 16) != 0) eleven, y + 11, 2, 2);
}

i++;
}
}
}

non-public void initGame()

non-public void initLevel()

continueLevel();
}

non-public void continueLevel() four * BLOCK_SIZE;
ghost_x[i] = four * BLOCK_SIZE;
ghost_dy[i] = 0;
ghost_dx[i] = dx;
dx = -dx;
random = (int) (Math.random() * (currentSpeed + 1));

if (random > currentSpeed)

ghostSpeed[i] = validSpeeds[random];
}

pacman_x = seven * BLOCK_SIZE;
pacman_y = eleven * BLOCK_SIZE;
pacmand_x = 0;
pacmand_y = 0;
req_dx = 0;
req_dy = 0;
view_dx = -1;
view_dy = 0;
dying = false;
}

non-public void loadImages()

non-public void doDrawing(Graphics g) else

g2d.drawImage(ii, 5, 5, this);
Toolkit.getDefaultToolkit().sync();
g2d.dispose();
}

category TAdapter extends KeyAdapter else if (key == KeyEvent.VK_RIGHT) else if (key == KeyEvent.VK_UP) else if (key == KeyEvent.VK_DOWN) else if (key == KeyEvent.VK_ESCAPE && timer.isRunning()) else if (key == KeyEvent.VK_PAUSE) else
}
} else key == 'S') {
inGame = true;
initGame();
  
}
}

@Override
public void keyReleased(KeyEvent e) key == Event.DOWN) {
req_dx = 0;
req_dy = 0;
  
}
}

@Override
public void actionPerformed(ActionEvent e)
}
The Pacman is controlled with the indicator keys. The Esc key finishes the sport, the Pause key pauses it.

private int pacman_x, pacman_y, pacmand_x, pacmand_y;
The first 2 variables store the x and y coordinates of the Pacman supernatural being. The last 2 variables ar the delta changes in horizontal and vertical directions.

private final short levelData[] = ;
These numbers structure the maze. they supply info out of that we have a tendency to produce the corners and therefore the points. number one could be a left corner. Numbers 2, four and eight represent prime, right, and bottom corners severally. variety sixteen could be a purpose. These numbers will be added , as an example variety nineteen within the higher left corner means the sq. can have prime and left borders and a degree (16 + two + 1).

private void doAnim() pacmanAnimPos == 0) {
pacAnimDir = -pacAnimDir;
  
}
}
The doAnim() counts the pacmanAnimPos variable that determines what pacman image is drawn. There ar four pacman pictures. there's additionally a PAC_ANIM_DELAY constant that makes the animation a little slower. Otherwise the pacman would open his mouth too quick.

boolean finished = true;

while (i < N_BLOCKS * N_BLOCKS && finished)

i++;
}
This code is a component of the checkMaze() technique. It checks if there ar any points left for the Pacman to eat. variety sixteen stands for a degree. If all points ar consumed, we have a tendency to move to successive level. (In our case, we have a tendency to simply restart the sport.)

Next we are going to examine the moveGhosts() technique. The ghosts move one sq. so decide if they modify the direction.

if (ghost_x[i] the troubles BLOCK_SIZE == zero && ghost_y[i] the troubles BLOCK_SIZE == 0) providing we've got finished moving one sq..

pos = pacman_x / BLOCK_SIZE + N_BLOCKS * (int) (pacman_y / BLOCK_SIZE);
This line determines wherever the ghost is located; within which position/square. There ar 225 theoretical positions. (A ghost cannot yield walls.)

if ((screenData[pos] & 1) == zero && ghost_dx[i] != 1)
If there's no obstacle on the left and therefore the ghost isn't already moving to the correct, the ghost can move to the left. What will this code very mean? If the ghost enters a tunnel, he can continue within the same direction till he's out of the tunnel. Moving of ghosts is part random. we have a tendency to don't apply this randomness within long tunnels as a result of the ghost would possibly stand still there.

if (pacman_x > (ghost_x[i] - 12) && pacman_x < (ghost_x[i] + 12)
&& pacman_y > (ghost_y[i] - 12) && pacman_y < (ghost_y[i] + 12)
&& inGame)
If there's a collision between ghosts and Pacman, Pacman dies.

Next we have a tendency to ar attending to examine the movePacman() technique. The req_dx and req_dy variables ar determined within the TAdapter inner category. These variables ar controlled with indicator keys.

if ((ch & 16) != 0)
If the pacman moves to an edge with a degree, we have a tendency to take away it from the maze and increase the score price.

if ((pacmand_x == -1 && pacmand_y == zero && (ch & 1) != 0)
|| (pacmand_x == one && pacmand_y == zero && (ch & 4) != 0)
|| (pacmand_x == zero && pacmand_y == -1 && (ch & 2) != 0)
|| (pacmand_x == zero && pacmand_y == one && (ch & 8) != 0))
The Pacman stops if he cannot move any it his current direction.

private void drawPacman(Graphics2D g2d) else if (view_dx == 1) else if (view_dy == -1) else
}
There ar four attainable directions for a Pacman. There ar four pictures for all directions. the photographs ar wont to animate Pacman gap and shutting his mouth.

The drawMaze() technique attracts the maze out of the numbers within the screenData array. number one could be a left border, two could be a prime border, four could be a right border, eight could be a bottom border and sixteen could be a purpose. we have a tendency to merely undergo all 225 squares within the maze. as an example we've got nine within the screenData array. we've got the primary bit (1) and therefore the fourth bit (8) set. therefore we have a tendency to draw a bottom and a left approximate this explicit sq..

if ((screenData[i] & 1) != 0)
We draw a left border if the primary little bit of variety is about.

Pacman.java
package com.zetcode;

import java.awt.EventQueue;
import javax.swing.JFrame;

public category Pacman extends JFrame
  
non-public void initUI() );
}
}