Kuangcp/JavaBase

View on GitHub
gui/src/main/java/com/github/kuangcp/tank/v1/MainPanelV1.java

Summary

Maintainability
C
1 day
Test Coverage

Method paint has 68 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    public void paint(Graphics g) {
        super.paint(g);

        if (Objects.isNull(hero)) {
            hero = new Hero(20, 20, 4);
Severity: Major
Found in gui/src/main/java/com/github/kuangcp/tank/v1/MainPanelV1.java - About 2 hrs to fix

    Method keyPressed has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
    Open

        public void keyPressed(KeyEvent e) {
            //加了if条件后 实现了墙的限制(如果是游戏中的道具,该怎么办)
            if (e.getKeyCode() == KeyEvent.VK_A) {
                hero.setDirect(2);
                if ((hero.getX() - 10) > 0)
    Severity: Minor
    Found in gui/src/main/java/com/github/kuangcp/tank/v1/MainPanelV1.java - About 1 hr to fix

    Cognitive Complexity

    Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

    A method's cognitive complexity is based on a few simple rules:

    • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
    • Code is considered more complex for each "break in the linear flow of the code"
    • Code is considered more complex when "flow breaking structures are nested"

    Further reading

    Similar blocks of code found in 4 locations. Consider refactoring.
    Open

            if (e.getKeyCode() == KeyEvent.VK_A) {
                hero.setDirect(2);
                if ((hero.getX() - 10) > 0)
                    hero.moveLeft();
    
    
    Severity: Major
    Found in gui/src/main/java/com/github/kuangcp/tank/v1/MainPanelV1.java and 3 other locations - About 35 mins to fix
    gui/src/main/java/com/github/kuangcp/tank/v1/MainPanelV1.java on lines 134..138
    gui/src/main/java/com/github/kuangcp/tank/v1/MainPanelV1.java on lines 140..145
    gui/src/main/java/com/github/kuangcp/tank/v1/MainPanelV1.java on lines 146..151

    Duplicated Code

    Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

    Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

    When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

    Tuning

    This issue has a mass of 44.

    We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

    The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

    If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

    See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

    Refactorings

    Further Reading

    Similar blocks of code found in 4 locations. Consider refactoring.
    Open

            if (e.getKeyCode() == KeyEvent.VK_D) {
                hero.setDirect(3);
                if ((hero.getX() + 15) < 405)
                    hero.moveRight();
            }
    Severity: Major
    Found in gui/src/main/java/com/github/kuangcp/tank/v1/MainPanelV1.java and 3 other locations - About 35 mins to fix
    gui/src/main/java/com/github/kuangcp/tank/v1/MainPanelV1.java on lines 128..133
    gui/src/main/java/com/github/kuangcp/tank/v1/MainPanelV1.java on lines 140..145
    gui/src/main/java/com/github/kuangcp/tank/v1/MainPanelV1.java on lines 146..151

    Duplicated Code

    Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

    Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

    When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

    Tuning

    This issue has a mass of 44.

    We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

    The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

    If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

    See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

    Refactorings

    Further Reading

    Similar blocks of code found in 4 locations. Consider refactoring.
    Open

            if (e.getKeyCode() == KeyEvent.VK_W) {
                hero.setDirect(0);
                if ((hero.getY() - 13) > 0)
                    hero.moveUp();
    
    
    Severity: Major
    Found in gui/src/main/java/com/github/kuangcp/tank/v1/MainPanelV1.java and 3 other locations - About 35 mins to fix
    gui/src/main/java/com/github/kuangcp/tank/v1/MainPanelV1.java on lines 128..133
    gui/src/main/java/com/github/kuangcp/tank/v1/MainPanelV1.java on lines 134..138
    gui/src/main/java/com/github/kuangcp/tank/v1/MainPanelV1.java on lines 146..151

    Duplicated Code

    Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

    Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

    When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

    Tuning

    This issue has a mass of 44.

    We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

    The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

    If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

    See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

    Refactorings

    Further Reading

    Similar blocks of code found in 4 locations. Consider refactoring.
    Open

            if (e.getKeyCode() == KeyEvent.VK_S) {
                hero.setDirect(1);
                if ((hero.getY() - 15) < 275)
                    hero.moveDown();
    
    
    Severity: Major
    Found in gui/src/main/java/com/github/kuangcp/tank/v1/MainPanelV1.java and 3 other locations - About 35 mins to fix
    gui/src/main/java/com/github/kuangcp/tank/v1/MainPanelV1.java on lines 128..133
    gui/src/main/java/com/github/kuangcp/tank/v1/MainPanelV1.java on lines 134..138
    gui/src/main/java/com/github/kuangcp/tank/v1/MainPanelV1.java on lines 140..145

    Duplicated Code

    Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

    Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

    When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

    Tuning

    This issue has a mass of 44.

    We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

    The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

    If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

    See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

    Refactorings

    Further Reading

    Identical blocks of code found in 2 locations. Consider refactoring.
    Open

            for (int i = 0; i < 9; i++) {
                g.fill3DRect(60, 60 + 10 * i, 20, 10, false);
            }
    Severity: Minor
    Found in gui/src/main/java/com/github/kuangcp/tank/v1/MainPanelV1.java and 1 other location - About 35 mins to fix
    gui/src/main/java/com/github/kuangcp/tank/v2/MainPanelV2.java on lines 90..92

    Duplicated Code

    Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

    Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

    When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

    Tuning

    This issue has a mass of 44.

    We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

    The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

    If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

    See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

    Refactorings

    Further Reading

    Similar blocks of code found in 4 locations. Consider refactoring.
    Open

            new Tank(80, 20, 0) {
                @Override
                public void drawSelf(Graphics g) {
                    g.setColor(new Color(93, 217, 41));
                    super.drawSelf(g);
    Severity: Major
    Found in gui/src/main/java/com/github/kuangcp/tank/v1/MainPanelV1.java and 3 other locations - About 35 mins to fix
    gui/src/main/java/com/github/kuangcp/tank/v1/MainPanelV1.java on lines 67..78
    gui/src/main/java/com/github/kuangcp/tank/v1/MainPanelV1.java on lines 79..90
    gui/src/main/java/com/github/kuangcp/tank/v1/MainPanelV1.java on lines 91..102

    Duplicated Code

    Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

    Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

    When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

    Tuning

    This issue has a mass of 43.

    We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

    The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

    If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

    See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

    Refactorings

    Further Reading

    Similar blocks of code found in 4 locations. Consider refactoring.
    Open

            new Tank(170, 20, 0) {
                @Override
                public void drawSelf(Graphics g) {
                    g.setColor(new Color(240, 57, 23));
                    super.drawSelf(g);
    Severity: Major
    Found in gui/src/main/java/com/github/kuangcp/tank/v1/MainPanelV1.java and 3 other locations - About 35 mins to fix
    gui/src/main/java/com/github/kuangcp/tank/v1/MainPanelV1.java on lines 55..66
    gui/src/main/java/com/github/kuangcp/tank/v1/MainPanelV1.java on lines 67..78
    gui/src/main/java/com/github/kuangcp/tank/v1/MainPanelV1.java on lines 79..90

    Duplicated Code

    Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

    Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

    When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

    Tuning

    This issue has a mass of 43.

    We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

    The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

    If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

    See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

    Refactorings

    Further Reading

    Similar blocks of code found in 4 locations. Consider refactoring.
    Open

            new Tank(110, 20, 0) {
                @Override
                public void drawSelf(Graphics g) {
                    g.setColor(new Color(34, 155, 234));
                    super.drawSelf(g);
    Severity: Major
    Found in gui/src/main/java/com/github/kuangcp/tank/v1/MainPanelV1.java and 3 other locations - About 35 mins to fix
    gui/src/main/java/com/github/kuangcp/tank/v1/MainPanelV1.java on lines 55..66
    gui/src/main/java/com/github/kuangcp/tank/v1/MainPanelV1.java on lines 79..90
    gui/src/main/java/com/github/kuangcp/tank/v1/MainPanelV1.java on lines 91..102

    Duplicated Code

    Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

    Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

    When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

    Tuning

    This issue has a mass of 43.

    We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

    The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

    If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

    See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

    Refactorings

    Further Reading

    Similar blocks of code found in 4 locations. Consider refactoring.
    Open

            new Tank(140, 20, 0) {
                @Override
                public void drawSelf(Graphics g) {
                    g.setColor(new Color(155, 62, 202));
                    super.drawSelf(g);
    Severity: Major
    Found in gui/src/main/java/com/github/kuangcp/tank/v1/MainPanelV1.java and 3 other locations - About 35 mins to fix
    gui/src/main/java/com/github/kuangcp/tank/v1/MainPanelV1.java on lines 55..66
    gui/src/main/java/com/github/kuangcp/tank/v1/MainPanelV1.java on lines 67..78
    gui/src/main/java/com/github/kuangcp/tank/v1/MainPanelV1.java on lines 91..102

    Duplicated Code

    Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

    Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

    When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

    Tuning

    This issue has a mass of 43.

    We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

    The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

    If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

    See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

    Refactorings

    Further Reading

    There are no issues that match your filters.

    Category
    Status