example.turtlelogo.KeyboardControl   A
last analyzed

Complexity

Total Complexity 9

Size/Duplication

Total Lines 38
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 0
loc 38
c 1
b 0
f 0
rs 10
wmc 9

8 Methods

Rating   Name   Duplication   Size   Complexity  
A keyPressed(KeyEvent) 0 15 5
A keyReleased(KeyEvent) 0 2 1
keyTyped 0 2 ?
A main(String[]) 0 1 1
A keyTyped(KeyEvent) 0 2 1
keyReleased 0 2 ?
keyPressed 0 15 ?
A KeyboardControl() 0 4 1
1
package example.turtlelogo;
2
3
import org.gannacademy.cdf.turtlelogo.AnimatedTurtle;
4
5
import java.awt.event.KeyEvent;
6
import java.awt.event.KeyListener;
7
8
public class KeyboardControl implements KeyListener {
9
  private AnimatedTurtle scooter;
10
11
  public KeyboardControl() {
12
    scooter = new AnimatedTurtle(1);
13
    scooter.getTerrarium().addKeyListener(this);
14
    scooter.getTerrarium().requestFocus();
15
  }
16
17
  @Override
18
  public void keyTyped(KeyEvent e) {
0 ignored issues
show
Bug introduced by
An empty method may be confusing. Add a nested comment explaining why this method is empty, throw an UnsupportedOperationException or complete the implementation.
Loading history...
19
20
  }
21
22
  @Override
23
  public void keyPressed(KeyEvent e) {
24
    switch (e.getKeyCode()) {
0 ignored issues
show
Code Smell introduced by
You may want to add a default case to this switch to deal with unforseen inputs.

Default branches should deal with the unexpected. At a minimum, they should log the error and if applicable, return a default value (null, empty collection). If you really do not expect the default branch to ever be use, throw a RuntimeException when it is.

Loading history...
25
      case KeyEvent.VK_A:
26
        scooter.left(15);
27
        break;
28
      case KeyEvent.VK_D:
29
        scooter.right(15);
30
        break;
31
      case KeyEvent.VK_W:
32
        scooter.forward(10);
33
        break;
34
      case KeyEvent.VK_S:
35
        scooter.back(10);
36
        break;
37
    }
38
  }
39
40
  @Override
41
  public void keyReleased(KeyEvent e) {
0 ignored issues
show
Bug introduced by
An empty method may be confusing. Add a nested comment explaining why this method is empty, throw an UnsupportedOperationException or complete the implementation.
Loading history...
42
43
  }
44
45
  public static void main(String[] args) {
46
    new KeyboardControl();
47
  }
48
}
49