Skip to content

Code review #1

Description

@tshemsedinov
  1. Instead of global variables you can group application state into abstractions like struct/object, classes, closures, functors:
    let cvs = document.getElementById("canvas");
    let ctx = cvs.getContext("2d");
    let frog = new Image();
    let background = new Image();
    let foreground = new Image();
    let fly = new Image();
    let pipeBottom = new Image();
  2. Multiple magic numbers and global variables, terrible approach for application state:
    function jump(){
    yPos -= 100;
    }
    let pipe = [];
    pipe[0] = {
    x: cvs.width,
    y: 300
    }
    let xPos = 10;
    let yPos = 490;
    let widthFrog = 90;
    let heightFrog = 80;
    let grav = 3;
    let max = 100;
    let gap = 90;
    let score = 0;
  3. Use intermediate variables and constants instead of hardcodes magic numbers:
    ctx.drawImage(fly, pipe[i].x, pipe[i].y - pipeBottom.height + gap, 50, 50);
  4. Decompose complex conditions/expressions:
    if (xPos + widthFrog >= pipe[i].x && yPos + heightFrog >= pipe[i].y) {
  5. Project is short and rude, no linting, not prettier, no tests, single commit (no work history)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions