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

Software Design Principle and Approach There was a popular mobile game called \'

ID: 3803756 • Letter: S

Question

Software Design Principle and Approach There was a popular mobile game called 'Flappy Bird' (Click the link to play the game). Here is a screen capture of the game. Now we would design a simplified version of the game, in which the bird is considered as a square with side length as 1. the pipe has a top position and a bottom position as shown in the picture, and the width of the pipe is 2. In every time unit, the bird drops by 1 space unit and the pipe moves leftward by 1 space unit. If you tap the screen of the mobile device, the bird will flap its wings and move up 1 space unit. Fly the bird as long as you can until it hits any pipes or goes beyond the height range of the screen, in which case the game is over. A new pipe will be generated immediately from the right end of the screen after the bird passes the old pipe. The pseudo code to initialize the game is given as follows: play a game birdPositionftop] = 5 birdPosition[bottom] = 4 birdPositionfleft] = 0 birdPositionfright] = 1 pipe[top] = 5 pipe[bottom] = 3 pipe[left] = 8 pipe[right] = 10 while (TRUE) PLAYING end play a game. The variables are defined as what their names imply. For example. birdPosition[top] is the top of the bird's position. Suppose both the height range and width range of the screen are [0, 10]. Answer the following questions. In the PLAYING module, what further functions/modules should be considered if we want to design the complete game? You can give simple names and provide brief comments for your functions/modules. Please write one line of pseudo code using the already-defined variables to check whether the game is over or not. Now we want to emphasize modularity which is an important software design principle. Please provide an architectural design of the game with "USES" relations, using your already-designed functions or modules. (Draw USES relations among the functions/modules whose names are identified.)

Explanation / Answer

package flappybird;
import java.awt.Image;
import java.awt.Rectangle;
import java.awt.event.KeyListener;
import javax.imageio.ImageIO;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.Timer;


public class FlappyBrd implements ActionListener, KeyListener
{
  
public static final int FPS = 80, WIDTH = 740, HEIGHT = 580;
  
private Bird brd;
private JFrame frame;
private JPanel panel;
private ArrayList<Rectangle> rects;
private int time, scroll;
private Timer t;
  
private boolean pused;
  
public void go()
{
frame = new JFrame("Flappy Brd");
brd = new Brd();
rects = new ArrayList<Rectangle>();
frame.add(panel);
  
frame.setSize(WIDTH, HEIGHT);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.addKeyListener(this);
  
paused = true;
  
}
public static void main(String[] args)
{
new FlappyBrd().go();
}
  

public void actionPerformed(ActionEvent e) {
panel.repaint();
if(!paused) {
bird.physics();
if(scroll % 90 == 0) {
Rectangle r2 = new Rectangle(WIDTH, HEIGHT - h2, GamePanel.PIPE_W, h2);
rects.add(r);

}
ArrayList<Rectangle> toRemove = new ArrayList<Rectangle>();
boolean game = true;
for(Rectangle r : rects) {
r.x-=3;
if(r.x + r.width <= 0) {
toRemove.add(r);
}
if(r.contains(bird.x, bird.y)) {
game = false;
}
}
rects.removeAll(toRemove);
time++;
scroll++;

if(brd.y > HEIGHT || brd.y+bird.RAD < 0) {
game = false;
}

if(!game)
{
rects.clear();
brd.reset();
time = 0;
scroll = 0;
paused = true;
}
}
else {
  
}
}
  
public int getScore() {
return time;
}
  
public void keyPressed(KeyEvent e) {
if(e.getKeyCode()==KeyEvent.VK_UP) {
brd.jump();
}
else if(e.getKeyCode()==KeyEvent.VK_SPACE)
{
paused = false;
}
}
public void keyRlsd(KeyEvent e)
{
  
}
public void keyTyped(KeyEvent e)
{
  
}
  
public boolean pused()
{
return pused;
}
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote