-
Notifications
You must be signed in to change notification settings - Fork 50
1st draft README including flowchart and pseudo code #31
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
raywtham
wants to merge
34
commits into
wdi-sg:master
Choose a base branch
from
raywtham:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
34 commits
Select commit
Hold shift + click to select a range
bfd2c2b
1st draft README including flowchart and pseudo code
raywtham 15a7e81
First codes. Grid generator in place.
raywtham edadf50
Generate random color
raywtham 779a734
change comments and var for gameboard
raywtham 67d30d6
check rows
raywtham 7122399
horizontal && vertical match not working concurrently
raywtham 9c5d7a4
added basic html css elements
raywtham 588f80e
centre css
raywtham ac74bf6
colors in game logic matches css
raywtham 6cec1d2
clean up
raywtham f860931
still working on matching
raywtham 871643a
matching works
raywtham 2b66b63
player matching added
raywtham ed492b6
work on replenish
raywtham 5a4d445
top row changes
raywtham a44917a
to fix top row refresh
raywtham f2fc19d
drop tiles working only 1 layer at a time
raywtham 074556b
Working basic version
raywtham 509862f
no more matches alert done
raywtham 605c0df
change colors
raywtham 7bf729b
increased size. reload level if no matches working
raywtham 16570c1
matching bug solved
raywtham 2a8ad3d
css transition
raywtham f2c1f35
reset all button, score & css update
raywtham 927cdf2
background change interval changed
raywtham e615645
experimental file
raywtham 927275e
clean up code
raywtham 201f82f
working timer
raywtham fff5217
remove redundant "pos" var
raywtham 2fd7d32
clean up and working
raywtham 9ead082
updated readme
raywtham 2bb5d4a
updated flowchart
raywtham e39eda9
Create CNAME
raywtham 91b21c6
Delete CNAME
raywtham File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,96 +1,53 @@ | ||
| # Project Name (Start editing here) | ||
| # Project #1 | ||
| <!--- | ||
| Read Me Contents | ||
| --> | ||
|
|
||
| #  Project #1: The Game | ||
|
|
||
| ### Overview | ||
|
|
||
| Let's start out with something fun - **a game!** | ||
|
|
||
| Everyone will get a chance to **be creative**, and work through some really **tough programming challenges** – since you've already gotten your feet wet with Tic Tac Toe, it's up to you to come up with a fun and interesting game to build. | ||
|
|
||
| **You will be working individually for this project**, but we'll be guiding you along the process and helping as you go. Show us what you've got! | ||
|
|
||
|
|
||
| --- | ||
|
|
||
| ### Technical Requirements | ||
|
|
||
| Your app must: | ||
| # Cubix : The Matching Game | ||
|
|
||
| * **Render a game in the browser** | ||
| * **Any number of players** will be okay, switch turns will be great | ||
| * **Design logic for winning** & **visually display which player won** | ||
| * **Include separate HTML / CSS / JavaScript files** | ||
| * Stick with **KISS (Keep It Simple Stupid)** and **DRY (Don't Repeat Yourself)** principles | ||
| * Use **Javascript** for **DOM manipulation**, jQuery is not compulsory | ||
| * **Deploy your game online**, where the rest of the world can access it | ||
| * Use **semantic markup** for HTML and CSS (adhere to best practices) | ||
| * **No canvas** project will be accepted, only HTML5 + CSS3 + JS please | ||
| Live prototype here: https://raywtham.github.io/project-1/ | ||
|
|
||
| --- | ||
|
|
||
| ### Necessary Deliverables | ||
| ### Overview | ||
|
|
||
| * A **working game, built by you**, hosted somewhere on the internet | ||
| * A **link to your hosted working game** in the URL section of your GitHub repo | ||
| * A **git repository hosted on GitHub**, with a link to your hosted game, and frequent commits dating back to the very beginning of the project | ||
| * **A ``readme.md`` file** with explanations of the technologies used, the approach taken, installation instructions, unsolved problems, etc. | ||
| Cubix as the title suggests, is a matching game. | ||
|
|
||
| --- | ||
| The player is presented with a game board which is a 4 x 4 grid of cells. Each cell is one of 3 random colours. | ||
|
|
||
| ### Suggested Ways to Get Started | ||
| The goal of the game is to find matching sequences of 3 cells of the same colour. | ||
|
|
||
| * **Break the project down into different components** (data, presentation, views, style, DOM manipulation) and brainstorm each component individually. Use whiteboards! | ||
| * **Use your Development Tools** (console.log, inspector, alert statements, etc) to debug and solve problems | ||
| * Work through the lessons in class & ask questions when you need to! Think about adding relevant code to your game each night, instead of, you know... _procrastinating_. | ||
| * **Commit early, commit often.** Don’t be afraid to break something because you can always go back in time to a previous version. | ||
| * **Consult documentation resources** (MDN, jQuery, etc.) at home to better understand what you’ll be getting into. | ||
| * **Don’t be afraid to write code that you know you will have to remove later.** Create temporary elements (buttons, links, etc) that trigger events if real data is not available. For example, if you’re trying to figure out how to change some text when the game is over but you haven’t solved the win/lose game logic, you can create a button to simulate that until then. | ||
| ### How to play | ||
|
|
||
| --- | ||
| Click on the first cell in a row or column where 3 cells are of the same colour. Each matching triplet will score 3 points. | ||
|
|
||
| ### Potential Project Ideas | ||
| Progress to the next level when all possible matches on the grid are found. | ||
|
|
||
| ##### Blackjack | ||
| Make a one player game where people down on their luck can lose all their money by guessing which card the computer will deal next! | ||
| There is a time limit of 60 seconds. Once the time is up, the game will end. | ||
|
|
||
| ##### Self-scoring Trivia | ||
| Test your wits & knowledge with whatever-the-heck you know about (so you can actually win). Guess answers, have the computer tell you how right you are! | ||
| Try to get a higher score each time! | ||
|
|
||
| --- | ||
|
|
||
| ### Useful Resources | ||
|
|
||
| * **[MDN Javascript Docs](https://developer.mozilla.org/en-US/docs/Web/JavaScript)** _(a great reference for all things Vanilla Javascript)_ | ||
| * **[jQuery Docs](http://api.jquery.com)** _(if you're using jQuery)_ | ||
| * **[GitHub Pages](https://pages.github.com)** _(for hosting your game)_ | ||
| * **[How to write readme - Markdown CheatSheet](https://github.com/adam-p/markdown-here/wiki/Markdown-Cheatsheet)** _(for editing this readme)_ | ||
| * **[How to write a good readme for github repo!](https://gist.github.com/PurpleBooth/109311bb0361f32d87a2)** _(to make it better)_ | ||
| ### Flowchart | ||
|  | ||
|
|
||
| --- | ||
|
|
||
| ### Project Feedback + Evaluation | ||
|
|
||
| * __Project Workflow__: Did you complete the user stories, wireframes, task tracking, and/or ERDs, as specified above? Did you use source control as expected for the phase of the program you’re in (detailed above)? | ||
|
|
||
| * __Technical Requirements__: Did you deliver a project that met all the technical requirements? Given what the class has covered so far, did you build something that was reasonably complex? | ||
| ### Initial Project Planning : Pseudo codes | ||
|
|
||
| * __Creativity__: Did you add a personal spin or creative element into your project submission? Did you deliver something of value to the end user (not just a login button and an index page)? | ||
| * Use a function to create a 2D array “grid” which is an array with 16 null values to represent a 4 x 4 grid of cells. | ||
|
|
||
| * __Code Quality__: Did you follow code style guidance and best practices covered in class, such as spacing, modularity, and semantic naming? Did you comment your code as your instructors have in class? | ||
| * Function gameStart: Generate random numbers between 1 to 3 to populate the array. 1,2,3 will represent “Red”,”Yellow”, “Blue” cells respectively. | ||
| Function Scoring: a function to check scoring condition | ||
| check row: 2 adjacent cells on left or right are the same as active cell -> score | ||
| check column : 2 adjacent cells on top or bottom are the same as active cell - > score change values of cells which met scoring to 0 | ||
| call function isLevelOver | ||
|
|
||
| * __Deployment__: Did you deploy your application to a public url using GitHub Pages? | ||
| * On click on a cell, run check scoring function | ||
|
|
||
| * __Total__: Your instructors will give you a total score on your project between: | ||
| * Function to replenish cells : Loop: Check the array for any cells with value 0. Populate these with the value of the cell above it then change the value of the cell above it to 0. | ||
| If there is no cells above i.e top row, generate random numbers to populate cell | ||
|
|
||
| Score | Expectations | ||
| ----- | ------------ | ||
| **0** | _Incomplete._ | ||
| **1** | _Does not meet expectations._ | ||
| **2** | _Meets expectations, good job!_ | ||
| **3** | _Exceeds expectations, you wonderful creature, you!_ | ||
| * Function to check if game is over: check if there are any matching 3s left on the grid. If yes return false else return true. Add 1 to level counter. If level counter = 7, game ends. | ||
|
|
||
| This will serve as a helpful overall gauge of whether you met the project goals, but __the more important scores are the individual ones__ above, which can help you identify where to focus your efforts for the next project! | ||
| * Function to move to next level: Clears all values in the grid then calls function gameStart. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,71 @@ | ||
| body { | ||
| color: white; | ||
| background-color: #00AFC2; | ||
| transition: background-color 10s ease; | ||
| } | ||
|
|
||
| .container { | ||
| width: 330px; | ||
| margin: 0 auto; | ||
| text-align: center; | ||
| position: relative; | ||
| font-family: 'Helvetica', sans-serif; | ||
| display: block; | ||
|
|
||
| } | ||
|
|
||
| .wrapper { | ||
| margin: 0 auto; | ||
| border: 3px solid white; | ||
| width: 324px; | ||
| display: flex; | ||
| flex-flow: row wrap; | ||
| } | ||
|
|
||
| h1 { | ||
| font-family: 'Orbitron', sans-serif; | ||
| font-weight: bold; | ||
| font-size: 60px; | ||
| position: relative; | ||
| top: 30px | ||
| } | ||
|
|
||
| h3 { | ||
| font-family: 'Orbitron', sans-serif; | ||
| font-size: 30px; | ||
| display: block; | ||
| margin: 15px; | ||
| height: 30px; | ||
| } | ||
|
|
||
| h2 { | ||
| font-family: 'Orbitron', sans-serif; | ||
| margin: 20px 15px; | ||
| display: block; | ||
| height: 20px; | ||
| } | ||
|
|
||
| p { | ||
| font-size: 16px; | ||
| } | ||
|
|
||
| button { | ||
| font-family: 'Orbitron', sans-serif; | ||
| font-weight: bold; | ||
| border: none; | ||
| background-color: white; | ||
| padding: 10px 5px 8px 5px; | ||
| font-size: 15px; | ||
| } | ||
|
|
||
| button:hover { | ||
| background-color: #00AFC2; | ||
| color: white; | ||
| } | ||
|
|
||
| .cell { | ||
| width: 80px; | ||
| height: 80px; | ||
| border: 0.5px solid beige; | ||
| transition: background-color 0.1s linear; | ||
| } |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,198 @@ | ||
| $(function () { | ||
|
|
||
| var grid = [] //game board | ||
| var colorList =['#3772FF','#FED766','#FE5F55'] | ||
| var matrix = 4 //length & breadth of board | ||
| var $cell = $('.cell') | ||
| var score = 0 // starting score | ||
| var time = 60 // time limit of the game | ||
| var checker = [] //to store player matches | ||
| var gameChecker =[] //to store whole board matches | ||
|
|
||
| function generateLevel () { | ||
| //creates a new 2Darray specified by 'matrix' | ||
| //create rows then columns, grid can be accessed with grid[row][column] | ||
| for (i = 0; i < matrix; i++) { | ||
| grid.push([]) | ||
| for (j = 0; j < matrix; j++) { | ||
| grid[i].push(generateColor()) | ||
|
|
||
| //populate cells in css | ||
| var pos = i +","+ j | ||
| $('.cell[data-position= "'+ pos +'"]').css('backgroundColor', grid[i][j]) | ||
| } | ||
| } | ||
| if (checkForMatches() < 3 ) restart() //if less than 3 available moves, regenerate level | ||
| } | ||
|
|
||
| function playerMatchCells() { | ||
| //for player to make matches | ||
| var index = ($(this).data('position')) //index[0], index[2] | ||
| var index1 = parseInt(index[0]) | ||
| var index2 = parseInt(index[2]) | ||
|
|
||
| //check if cell and next 2 cells match, then push into checker array | ||
| //horizontal check | ||
| if( grid[index1][index2]===grid[index1][index2+1] && grid[index1][index2]===grid[index1][index2+2]) { | ||
| checker.push([index1, index2,'h']) | ||
| score +=3 | ||
| } | ||
| //vertical check | ||
| if(grid[index1+2]) { | ||
| if( grid[index1][index2]===grid[index1+1][index2] && grid[index1][index2]===grid[index1+2][index2]) { | ||
| checker.push([index1, index2,'v']) | ||
| score +=3 | ||
| } | ||
| } | ||
|
|
||
| //future functionality to check backwards | ||
| // if( grid[index1][index2]===grid[index1][index2-1] && grid[index1][index2]===grid[index1][index2-2]) { | ||
| // checker.push([index1, index2,'h']) | ||
| // } | ||
| // if(grid[index1-2]){ | ||
| // if( grid[index1][index2]===grid[index1-1][index2] && grid[index1][index2]===grid[index1-2][index2]) { | ||
| // checker.push([index1, index2,'v']) | ||
| // } | ||
| // } | ||
|
|
||
| //change cells to '0' when they match | ||
| if (checker.length > 0) { | ||
| for(var i = 0; i < checker.length; i++) { | ||
| if (checker[i][2] === 'h') { | ||
| grid[checker[i][0]][checker[i][1]] = 0 | ||
| grid[checker[i][0]][checker[i][1] + 1] = 0 | ||
| grid[checker[i][0]][checker[i][1] + 2] = 0 | ||
| } | ||
| if (checker[i][2] === 'v') { | ||
| grid[checker[i][0]][checker[i][1]] = 0 | ||
| grid[checker[i][0] + 1][checker[i][1]] = 0 | ||
| grid[checker[i][0] + 2][checker[i][1]] = 0 | ||
| } | ||
| } | ||
| //reset checker | ||
| checker = [] | ||
| } | ||
| replenishCells() | ||
| } | ||
|
|
||
|
|
||
| function checkForMatches() { | ||
| //checks if any matches exist on the whole board | ||
| gameChecker = [] | ||
| for (var x = 0 ; x < matrix; x++) { | ||
| for (var y = 0; y < matrix; y++) { | ||
|
|
||
| //check for horizontal matches | ||
| if (grid[x][y] === grid[x][y+1] && grid[x][y] === grid[x][y+2]) { | ||
| gameChecker.push([x,y,'h']) | ||
| } | ||
| //check for vertical matches | ||
| if (grid[x+2]) { | ||
| if (grid[x][y] === grid[x+1][y] && grid[x][y] === grid[x+2][y]) { | ||
| gameChecker.push([x,y,'v']) | ||
| } | ||
| } | ||
| } | ||
| } | ||
| return gameChecker.length | ||
| } | ||
|
|
||
| function replenishCells() { | ||
| //replenish the empty cells where matches were found by the player | ||
| var pos = x +","+ y | ||
|
|
||
| //replenish from bottom | ||
| for (var x = matrix - 1 ; x >= 0 ; x--) { | ||
| for (var y = matrix - 1; y >= 0 ; y--) { | ||
| if (grid[x-1] && grid[x][y] === 0) { | ||
| ;[ grid[x][y],grid[x-1][y] ] = [grid[x-1][y], grid[x][y] ] | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. May I know why did you put semicolone here? |
||
| pos = x +","+ y | ||
| $('.cell[data-position= "'+ pos +'"]').css('backgroundColor', grid[x][y]) | ||
| } | ||
| } | ||
| } | ||
| //run again to replenish adjacent empty | ||
| for (var x = 0 ; x < matrix ; x++) { | ||
| for (var y = 0; y < matrix ; y++) { | ||
| if (grid[x-1] && grid[x][y] === 0) { | ||
| ;[ grid[x][y],grid[x-1][y] ] = [grid[x-1][y], grid[x][y] ] | ||
| pos = x +","+ y | ||
| $('.cell[data-position= "'+ pos +'"]').css('backgroundColor', grid[x][y]) | ||
| } | ||
|
|
||
| } | ||
| } | ||
| //replenish last adjacent empty | ||
| for (var x = 0 ; x < matrix ; x++) { | ||
| for (var y = 0; y < matrix ; y++) { | ||
| if (grid[x][y] === 0) { | ||
| grid[x][y] = generateColor() | ||
| pos = x +","+ y | ||
| $('.cell[data-position= "'+ pos +'"]').css('backgroundColor', grid[x][y]) | ||
| } | ||
| } | ||
| } | ||
|
|
||
| if (checkForMatches() === 0 ) { | ||
| //if no matches remain on the board, start a new level | ||
| alert('Level Complete!') | ||
| restart() | ||
| } | ||
| } | ||
|
|
||
| function generateColor() { | ||
| return colorList[Math.floor(Math.random() * colorList.length)] | ||
| } | ||
|
|
||
| function restart() { | ||
| //restarts level | ||
| grid = [] | ||
| generateLevel() | ||
| } | ||
|
|
||
| function resetAll() { | ||
| //resets the game & starts a new game | ||
| clearInterval(timer) | ||
| time = 60 | ||
| score = 0 | ||
| scoreboard() | ||
| timer = setInterval(timerFn, 1000) | ||
| restart() | ||
| } | ||
|
|
||
| function scoreboard() { | ||
| //display score | ||
| $('h3').text('Score: ' + score) | ||
| } | ||
|
|
||
| function bgChanger(){ | ||
| //background color changer | ||
| var r = Math.floor(Math.random() * 255) | ||
| var g = Math.floor(Math.random() * 255) | ||
| var b = Math.floor(Math.random() * 255) | ||
| var $body = $('body') | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You may move line 173 to outside of the function. Then what will be the benefit? |
||
| var bgColorArray = "rgb("+r+","+g+","+b+")" | ||
| $body.css('backgroundColor', bgColorArray) | ||
| } | ||
|
|
||
| function timerFn () { | ||
| //countdown timer | ||
| if (time !==0) { | ||
| time-- | ||
| $('h2').text('Time left: ' + time +'s') | ||
| } | ||
| if(time === 0) { | ||
| alert('Time is up! Click ok to start new game.') | ||
| clearInterval(timer) | ||
| resetAll() | ||
| } | ||
| } | ||
|
|
||
| generateLevel() | ||
| $cell.on('click', playerMatchCells) | ||
| $('body').on('click', scoreboard) | ||
| $('button').on('click', resetAll) | ||
| setInterval(bgChanger,4000) | ||
| var timer = setInterval(timerFn, 1000) | ||
|
|
||
| }) | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You may try : https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Template_literals
and need double quote mark there?