Skip to content

πŸ€ A basketball-themed Connect Four game built with vanilla JS, CSS and HTML. Users can choose between the one-player or two-player mode, and can track their score and start a new 'tournament'. Also featuring a landing page. GA Project 1

Notifications You must be signed in to change notification settings

emilydaykin/Basketball-Connect4

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

80 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Basketball Connect 4

The traditional Connect Four game with a basketball twist. Play it here!

Game Visual

Game walkthrough:

Landing Page:

1-player vs 2-player Mode:

Win Condition:

Responsive Design:

Tech Stack used:

HTML, CSS and vanilla Javascript; Git; GitHub Pages for deployment.

Game Features:

MVP (v0):

  • βœ”οΈ A working game of connect 4 (with correct logic to check for a win) in an 8x5 grid.
  • βœ”οΈ The counters will be orange and blue basketballs.
  • βœ”οΈ The balls going into the grid are animated to slide down the grid, rather than just appear in the correct cell.
  • βœ”οΈ '2-player' mode and a '1-player v computer' mode. Computer will not be intelligent, will only be randomised moves.
  • βœ”οΈ Scoring: multiple games within a tournament (game score & tournament score).
  • βœ”οΈ Buttons: start new game, or start new tournament (scoreboard (tracks game wins) is only cleared after new tournament starts).

Version 1 (v1):

  • βœ–οΈ Animation of ball being shot (a perfect arc) from player images to the selected column of the grid.
  • βœ”οΈ Hoop & backboard images above each column.
  • βœ–οΈ Swish sound when each ball goes in each column (didn't like the effect in the end).
  • βœ”οΈ Grid background will be a basketball court on page load, then each cell will appear to fill out the grid.
  • βœ”οΈ Either side of the grid will display player images (MJ/Kobe/Lebron) shooting. For the 1-player mode, one of the players will be a silhouette shooting.
  • βœ”οΈ Computer to make calculated moves rather than random ones.

V2:

  • Users select which hoop they want to drop the ball down via clicking on the players.
  • The longer users hold down the click for, the further the ball shoots.

Code Base:

  • Entire game functionality wrapped in a class.

Tree:

.
β”œβ”€β”€ index.html
β”œβ”€β”€ game.html
β”œβ”€β”€ styles
β”‚   β”œβ”€β”€ main.css
β”‚   └── start.css
└── scripts
 Β Β  β”œβ”€β”€ app.js
 Β Β  β”œβ”€β”€ start.js
 Β Β  └── components
 Β Β   Β Β  β”œβ”€β”€ game.js
 Β Β   Β Β  └── gridOverview.js

Approach Taken:

  • Pseudocoded 90% the JS before beginning any coding (comments in app.js and excalidraw). The 10% with event listeners interacting were too complicated to picture without any code, so that part was figured out along the way.
  • Minimal HTML and CSS to begin with; prioritised JS.
  • Had a functioning version of the game in JS first before doing a whole codebase refactor into classes.

Project Overview:

  • Day 1 (Fri): All day pseudocoding and whiteboarding JS logic. Browsed game images.
  • Day 2-3 (Sat-Sun): Coded up logic, event listeners, scoring system, 2-player & 1-player modes.
  • Day 4 (Mon): Added ball slide animation with setInterval, and fixed bugs all day.
  • Day 5 (Tues): Refactoring JS into classes and styling.
  • Day 6 (Weds): Responsive design and more styling (added new start page upon browser load).
  • Day 7 (Thurs): Attemping the shot arc; adding a tiny bit of AI to the 1-player game, and cleaning up code.

Bugs:

  • If mouse is inside grid as the grid is fading in, ball hover over the hoops will be opaque, rather than translucent as it should be. (Once mouse leaves grid, and comes back in, styling works.)

Wins & Ideals:

Wins:

  • Refactored code base into classes, keeping the functions and methods organised and compartmentalised.
  • setInterval challenges overcome: working animation and then embedded in a class.
  • Foolproof logic to check for a winner of the game.

Ideals:

  • Animate each turn to have the ball shooting from the players' hands to each corresponding hoop clicked on (shot arc before sliding down each column).
  • Computer AI to be even smarter.
  • More responsive design to allow for mobile/tablet mode.

About

πŸ€ A basketball-themed Connect Four game built with vanilla JS, CSS and HTML. Users can choose between the one-player or two-player mode, and can track their score and start a new 'tournament'. Also featuring a landing page. GA Project 1

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published