Coder Social home page Coder Social logo

connect-four's Introduction

Project-05

Portfolio website built in React

This was a website built to showcase my technical skills, web design skills.

Project timeline and technologies used

Build a React website in 24 hours to showcase the following:

  • My technical skill set
  • My web design skill set
  • My projects

Technologies Used

  • HTML5
  • CSS3
  • JavaScript (ES6)
  • SCSS
  • Git
  • GitHub
  • React
  • Webpack
  • Bulma
  • Node JS
  • Babel

Homepage visuals

Imgur Imgur Imgur Imgur Imgur Imgur

Skill set visuals

Imgur

connect-four's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

connect-four's Issues

Getting rid of the fixed array

Hi Ania, thank you very much for the JS course!

In this game though I think that rather than using a fixed array to find winning combinations it would be better to calculate the position of the selected cell, then look for the three adjacent cells in the available directions for matching cells dynamically.

These functions do that with basic arithmetics. You'll need to invoke checkWinner() with the position of the clicked cell (its index in the squares array) and the player that is performing the play (so invoke the function before changing currentPlayer, or store it for later use).

Best,
Proteo.

function checkCandidates(index, cssName, callbackId) {
    // Look for the three adjacent cells, as defined by callbackId().
    for (let i = 1; i <= 3; i++) {
      let id = callbackId(index, i);
      if (!squares[id].classList.contains(cssName)) {
        return false;
      }
    }
    return true;
  }

  function checkWinner(index, player) {
    const cssName = (player == 2) ? 'player-two' : 'player-one';
    const cellPos = (index + 1);
    const cellRow = Math.ceil(cellPos / 7);
    const cellCol = Math.ceil(cellPos - ((cellRow - 1) * 7));

    // Check bottom cells (after, in the same column).
    if (cellRow < 4 && checkCandidates(index, cssName, (index, i) => index + (7 * i))) {
      return true;
    }
    // Check left cells (before, in the same row).
    if (cellCol >= 4 && checkCandidates(index, cssName, (index, i) => index - i)) {
      return true;
    }
    //  Check top cells (before, in the same column).
    if (cellRow >= 4 && checkCandidates(index, cssName, (index, i) => index - (7 * i))) {
      return true;
    }
    //  Check right cells (after, in the same column).
    if (cellCol <= 4 && checkCandidates(index, cssName, (index, i) => index + i)) {
      return true;
    }

    // No winner yet!
    return false;
  }

Winners

In the winningArrays, we have:

[11, 7, 23, 29]

But that should be:

[11, 17, 23, 29]

All the best,

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.