{"action":"created","comment":{"url":"https://api.github.com/repos/vikingeducation/project_tdd_minesweeper/pulls/comments/29714573","id":29714573,"diff_hunk":"@@ -0,0 +1,172 @@\n+# Class for manipulating and outputting the \n+# board itself.\n+\n+class Board\n+\tattr_reader :flags_remaining, :board, :mine_coords\n+\t\n+\tdef initialize(size, num_mines)\n+\t\t@size = size\n+\t\t@board = create_board(size,num_mines)\n+\t\t@flags_remaining = num_mines\n+\t\t@mine_coords = get_all_mines\n+\t\tadd_surrounding_mines\n+\tend\n+\n+\t# Will create the board nested array\n+\tdef create_board(size, num_mines)\n+\t\tfinal_board = []\n+\t\t# Create outer loop\n+\t\t1.upto(size) do |row|\n+\t\t\trow_buffer = []\n+\t\t\t# Create inner loop\n+\t\t\t1.upto(size) do |column|\n+\t\t\t\trow_buffer << Square.new([column,((size+1)-row)], size)\n+\t\t\tend\n+\t\t\t# Once each row is composed add it to \n+\t\t\t# the final board.\n+\t\t\tfinal_board << row_buffer\n+\t\tend\n+\t\tset_mines(final_board, num_mines) # Now that we have the board, lets add some mines\n+\t\tfinal_board\n+\tend\n+\n+\t# Add some mines to the board\n+\tdef set_mines(board, num_mines)\n+\t\tuntil num_mines == 0\n+\t\t\tselection = board.sample.sample\n+\t\t\tif selection.mine \t\t\t\t# If the selection is already a mine\n+\t\t\t\tredo\n+\t\t\telse\t\t\t\t\t\t\t\t\t\t\t# If the selection isn't a mine\n+\t\t\t\tselection.make_mine \t\t# then make it a mine\n+\t\t\t\tnum_mines -= 1\t\t\t\t\t# and decrement the number of mines left.\n+\t\t\tend\n+\t\tend \n+\tend\n+\n+\t# Add the surrounding_mines variable to each Square instance\n+\tdef add_surrounding_mines\n+\t\t@board.flatten.each do |square|\n+\t\t\tmine_count = 0\n+\t\t\tsquare.adjacent_squares.each do |adj_square|\n+\t\t\t\tmine_count += 1 if get_square(adj_square).mine == true\n+\t\t\tend\n+\t\t\tsquare.surrounding_mines=(mine_count)\n+\t\tend\n+\tend\n+\n+\t# Return a square object based on the coordinates\n+\tdef get_square(test_coords)\n+\t\t@board.flatten.each do |square|\n+\t\t\treturn square if square.coords == test_coords\n+\t\tend\n+\tend\n+\n+\t# Add or remove a flag\n+\tdef switch_flag(coords)\n+\t\tsquare = get_square(coords)\n+\t\tif square.flag == false \t\t# If Square isn't flagged already\n+\t\t\tsquare.switch_flag\n+\t\t\t@flags_remaining -= 1\n+\t\telsif square.flag == true \t# If Square is flagged already\n+\t\t\tsquare.switch_flag\n+\t\t\t@flags_remaining += 1\n+\t\tend\n+\tend\n+\n+\t# Display a square\n+\tdef display_square(coords)\n+\t\tsquare = get_square(coords)\n+\t\tif square.displayed == false\n+\t\t\tsquare.display_square\n+\t\t\tif square.surrounding_mines == 0\n+\t\t\t\tsquare.adjacent_squares.each do |coords|\n+\t\t\t\t\tsquare = get_square(coords)\n+\t\t\t\t\tdisplay_square(square.coords) unless square.mine == true\n+\t\t\t\tend\n+\t\t\tend\n+\t\tend\n+\tend\n+\n+\t# Get coords of all mines\n+\tdef get_all_mines\n+\t\tall_mines = []\n+\t\t@board.flatten.each do |square|\n+\t\t\tall_mines << square.coords if square.mine == true\n+\t\tend\n+\t\tall_mines\n+\tend\n+\n+\tdef get_all_flags\n+\t\tall_flags = []\n+\t\t@board.flatten.each do |square|\n+\t\t\tall_flags << square.coords if square.flag == true\n+\t\tend\n+\t\tall_flags\n+\tend\n+\n+\t# Is loss?\n+\tdef is_loss?(coords)\n+\t\tsquare = get_square(coords)\n+\t\tsquare.mine ? true : false\n+\tend\n+\n+\t# Is victory?\n+\tdef is_victory? \n+\t\tall_flags = get_all_flags\n+\t\t@mine_coords.all?{|mine_coord| all_flags.include?(mine_coord)} ? true : false\n+\tend\n+\n+\t# Show all mines\n+\tdef show_all_mines\n+\t\t@board.flatten.each do |square|\n+\t\t\tif square.mine == true\n+\t\t\t\tsquare.displayed = true\n+\t\t\tend\n+\t\tend\n+\tend\n+\n+\t# Clear the screen\n+\tdef clear\n+\t\tsystem \"clear\"\n+\tend\n+\t\n+\t# Render the actual board\n+\tdef render\n+\t\tclear\n+\t\toutput = \"MINESWEEPER\\n-----------\\n#{@flags_remaining} Flags Remaining\\n-----------\\n\"\n+\t\t# This will iterate through each row\n+\t\t# on the board.\n+\t\t@board.each_with_index do |row, index|\n+\t\t\tindex == 0 ? output << \"#{@size - index} | \" : output << \"#{@size - index}  | \"\n+\t\t\t# This will iterate over each square\n+\t\t\trow.each do |square|\n+\t\t\t\tif square.displayed == false && square.flag == false","path":"lib/board.rb","position":143,"original_position":143,"commit_id":"e3b4345d6e1000015d37a6bc7f9e97fd80161f36","original_commit_id":"e3b4345d6e1000015d37a6bc7f9e97fd80161f36","user":{"login":"nicoNaN","id":7397825,"avatar_url":"https://avatars.githubusercontent.com/u/7397825?v=3","gravatar_id":"","url":"https://api.github.com/users/nicoNaN","html_url":"https://github.com/nicoNaN","followers_url":"https://api.github.com/users/nicoNaN/followers","following_url":"https://api.github.com/users/nicoNaN/following{/other_user}","gists_url":"https://api.github.com/users/nicoNaN/gists{/gist_id}","starred_url":"https://api.github.com/users/nicoNaN/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/nicoNaN/subscriptions","organizations_url":"https://api.github.com/users/nicoNaN/orgs","repos_url":"https://api.github.com/users/nicoNaN/repos","events_url":"https://api.github.com/users/nicoNaN/events{/privacy}","received_events_url":"https://api.github.com/users/nicoNaN/received_events","type":"User","site_admin":false},"body":"The outputs of the squares could be merged into the `square` class - would slim this method down quite a bit","created_at":"2015-05-05T21:23:02Z","updated_at":"2015-05-05T21:23:02Z","html_url":"https://github.com/vikingeducation/project_tdd_minesweeper/pull/5#discussion_r29714573","pull_request_url":"https://api.github.com/repos/vikingeducation/project_tdd_minesweeper/pulls/5","_links":{"self":{"href":"https://api.github.com/repos/vikingeducation/project_tdd_minesweeper/pulls/comments/29714573"},"html":{"href":"https://github.com/vikingeducation/project_tdd_minesweeper/pull/5#discussion_r29714573"},"pull_request":{"href":"https://api.github.com/repos/vikingeducation/project_tdd_minesweeper/pulls/5"}}},"pull_request":{"url":"https://api.github.com/repos/vikingeducation/project_tdd_minesweeper/pulls/5","id":33314990,"html_url":"https://github.com/vikingeducation/project_tdd_minesweeper/pull/5","diff_url":"https://github.com/vikingeducation/project_tdd_minesweeper/pull/5.diff","patch_url":"https://github.com/vikingeducation/project_tdd_minesweeper/pull/5.patch","issue_url":"https://api.github.com/repos/vikingeducation/project_tdd_minesweeper/issues/5","number":5,"state":"open","locked":false,"title":"And, we're off.","user":{"login":"telwell","id":736897,"avatar_url":"https://avatars.githubusercontent.com/u/736897?v=3","gravatar_id":"","url":"https://api.github.com/users/telwell","html_url":"https://github.com/telwell","followers_url":"https://api.github.com/users/telwell/followers","following_url":"https://api.github.com/users/telwell/following{/other_user}","gists_url":"https://api.github.com/users/telwell/gists{/gist_id}","starred_url":"https://api.github.com/users/telwell/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/telwell/subscriptions","organizations_url":"https://api.github.com/users/telwell/orgs","repos_url":"https://api.github.com/users/telwell/repos","events_url":"https://api.github.com/users/telwell/events{/privacy}","received_events_url":"https://api.github.com/users/telwell/received_events","type":"User","site_admin":false},"body":"","created_at":"2015-04-15T01:13:50Z","updated_at":"2015-05-05T21:23:02Z","closed_at":null,"merged_at":null,"merge_commit_sha":"4096c7b86505ccc2399ba6bad8f8417a130a9188","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/vikingeducation/project_tdd_minesweeper/pulls/5/commits","review_comments_url":"https://api.github.com/repos/vikingeducation/project_tdd_minesweeper/pulls/5/comments","review_comment_url":"https://api.github.com/repos/vikingeducation/project_tdd_minesweeper/pulls/comments{/number}","comments_url":"https://api.github.com/repos/vikingeducation/project_tdd_minesweeper/issues/5/comments","statuses_url":"https://api.github.com/repos/vikingeducation/project_tdd_minesweeper/statuses/e3b4345d6e1000015d37a6bc7f9e97fd80161f36","head":{"label":"telwell:master","ref":"master","sha":"e3b4345d6e1000015d37a6bc7f9e97fd80161f36","user":{"login":"telwell","id":736897,"avatar_url":"https://avatars.githubusercontent.com/u/736897?v=3","gravatar_id":"","url":"https://api.github.com/users/telwell","html_url":"https://github.com/telwell","followers_url":"https://api.github.com/users/telwell/followers","following_url":"https://api.github.com/users/telwell/following{/other_user}","gists_url":"https://api.github.com/users/telwell/gists{/gist_id}","starred_url":"https://api.github.com/users/telwell/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/telwell/subscriptions","organizations_url":"https://api.github.com/users/telwell/orgs","repos_url":"https://api.github.com/users/telwell/repos","events_url":"https://api.github.com/users/telwell/events{/privacy}","received_events_url":"https://api.github.com/users/telwell/received_events","type":"User","site_admin":false},"repo":{"id":33965512,"name":"project_tdd_minesweeper","full_name":"telwell/project_tdd_minesweeper","owner":{"login":"telwell","id":736897,"avatar_url":"https://avatars.githubusercontent.com/u/736897?v=3","gravatar_id":"","url":"https://api.github.com/users/telwell","html_url":"https://github.com/telwell","followers_url":"https://api.github.com/users/telwell/followers","following_url":"https://api.github.com/users/telwell/following{/other_user}","gists_url":"https://api.github.com/users/telwell/gists{/gist_id}","starred_url":"https://api.github.com/users/telwell/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/telwell/subscriptions","organizations_url":"https://api.github.com/users/telwell/orgs","repos_url":"https://api.github.com/users/telwell/repos","events_url":"https://api.github.com/users/telwell/events{/privacy}","received_events_url":"https://api.github.com/users/telwell/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/telwell/project_tdd_minesweeper","description":"Code go boom!","fork":true,"url":"https://api.github.com/repos/telwell/project_tdd_minesweeper","forks_url":"https://api.github.com/repos/telwell/project_tdd_minesweeper/forks","keys_url":"https://api.github.com/repos/telwell/project_tdd_minesweeper/keys{/key_id}","collaborators_url":"https://api.github.com/repos/telwell/project_tdd_minesweeper/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/telwell/project_tdd_minesweeper/teams","hooks_url":"https://api.github.com/repos/telwell/project_tdd_minesweeper/hooks","issue_events_url":"https://api.github.com/repos/telwell/project_tdd_minesweeper/issues/events{/number}","events_url":"https://api.github.com/repos/telwell/project_tdd_minesweeper/events","assignees_url":"https://api.github.com/repos/telwell/project_tdd_minesweeper/assignees{/user}","branches_url":"https://api.github.com/repos/telwell/project_tdd_minesweeper/branches{/branch}","tags_url":"https://api.github.com/repos/telwell/project_tdd_minesweeper/tags","blobs_url":"https://api.github.com/repos/telwell/project_tdd_minesweeper/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/telwell/project_tdd_minesweeper/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/telwell/project_tdd_minesweeper/git/refs{/sha}","trees_url":"https://api.github.com/repos/telwell/project_tdd_minesweeper/git/trees{/sha}","statuses_url":"https://api.github.com/repos/telwell/project_tdd_minesweeper/statuses/{sha}","languages_url":"https://api.github.com/repos/telwell/project_tdd_minesweeper/languages","stargazers_url":"https://api.github.com/repos/telwell/project_tdd_minesweeper/stargazers","contributors_url":"https://api.github.com/repos/telwell/project_tdd_minesweeper/contributors","subscribers_url":"https://api.github.com/repos/telwell/project_tdd_minesweeper/subscribers","subscription_url":"https://api.github.com/repos/telwell/project_tdd_minesweeper/subscription","commits_url":"https://api.github.com/repos/telwell/project_tdd_minesweeper/commits{/sha}","git_commits_url":"https://api.github.com/repos/telwell/project_tdd_minesweeper/git/commits{/sha}","comments_url":"https://api.github.com/repos/telwell/project_tdd_minesweeper/comments{/number}","issue_comment_url":"https://api.github.com/repos/telwell/project_tdd_minesweeper/issues/comments{/number}","contents_url":"https://api.github.com/repos/telwell/project_tdd_minesweeper/contents/{+path}","compare_url":"https://api.github.com/repos/telwell/project_tdd_minesweeper/compare/{base}...{head}","merges_url":"https://api.github.com/repos/telwell/project_tdd_minesweeper/merges","archive_url":"https://api.github.com/repos/telwell/project_tdd_minesweeper/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/telwell/project_tdd_minesweeper/downloads","issues_url":"https://api.github.com/repos/telwell/project_tdd_minesweeper/issues{/number}","pulls_url":"https://api.github.com/repos/telwell/project_tdd_minesweeper/pulls{/number}","milestones_url":"https://api.github.com/repos/telwell/project_tdd_minesweeper/milestones{/number}","notifications_url":"https://api.github.com/repos/telwell/project_tdd_minesweeper/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/telwell/project_tdd_minesweeper/labels{/name}","releases_url":"https://api.github.com/repos/telwell/project_tdd_minesweeper/releases{/id}","created_at":"2015-04-15T01:09:27Z","updated_at":"2015-04-19T16:22:42Z","pushed_at":"2015-04-19T16:22:42Z","git_url":"git://github.com/telwell/project_tdd_minesweeper.git","ssh_url":"git@github.com:telwell/project_tdd_minesweeper.git","clone_url":"https://github.com/telwell/project_tdd_minesweeper.git","svn_url":"https://github.com/telwell/project_tdd_minesweeper","homepage":null,"size":111,"stargazers_count":0,"watchers_count":0,"language":"Ruby","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"vikingeducation:master","ref":"master","sha":"3957b0000d9a8528af63d4e130c95fe50116ddd0","user":{"login":"vikingeducation","id":7231832,"avatar_url":"https://avatars.githubusercontent.com/u/7231832?v=3","gravatar_id":"","url":"https://api.github.com/users/vikingeducation","html_url":"https://github.com/vikingeducation","followers_url":"https://api.github.com/users/vikingeducation/followers","following_url":"https://api.github.com/users/vikingeducation/following{/other_user}","gists_url":"https://api.github.com/users/vikingeducation/gists{/gist_id}","starred_url":"https://api.github.com/users/vikingeducation/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/vikingeducation/subscriptions","organizations_url":"https://api.github.com/users/vikingeducation/orgs","repos_url":"https://api.github.com/users/vikingeducation/repos","events_url":"https://api.github.com/users/vikingeducation/events{/privacy}","received_events_url":"https://api.github.com/users/vikingeducation/received_events","type":"Organization","site_admin":false},"repo":{"id":29702479,"name":"project_tdd_minesweeper","full_name":"vikingeducation/project_tdd_minesweeper","owner":{"login":"vikingeducation","id":7231832,"avatar_url":"https://avatars.githubusercontent.com/u/7231832?v=3","gravatar_id":"","url":"https://api.github.com/users/vikingeducation","html_url":"https://github.com/vikingeducation","followers_url":"https://api.github.com/users/vikingeducation/followers","following_url":"https://api.github.com/users/vikingeducation/following{/other_user}","gists_url":"https://api.github.com/users/vikingeducation/gists{/gist_id}","starred_url":"https://api.github.com/users/vikingeducation/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/vikingeducation/subscriptions","organizations_url":"https://api.github.com/users/vikingeducation/orgs","repos_url":"https://api.github.com/users/vikingeducation/repos","events_url":"https://api.github.com/users/vikingeducation/events{/privacy}","received_events_url":"https://api.github.com/users/vikingeducation/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/vikingeducation/project_tdd_minesweeper","description":"Code go boom!","fork":false,"url":"https://api.github.com/repos/vikingeducation/project_tdd_minesweeper","forks_url":"https://api.github.com/repos/vikingeducation/project_tdd_minesweeper/forks","keys_url":"https://api.github.com/repos/vikingeducation/project_tdd_minesweeper/keys{/key_id}","collaborators_url":"https://api.github.com/repos/vikingeducation/project_tdd_minesweeper/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/vikingeducation/project_tdd_minesweeper/teams","hooks_url":"https://api.github.com/repos/vikingeducation/project_tdd_minesweeper/hooks","issue_events_url":"https://api.github.com/repos/vikingeducation/project_tdd_minesweeper/issues/events{/number}","events_url":"https://api.github.com/repos/vikingeducation/project_tdd_minesweeper/events","assignees_url":"https://api.github.com/repos/vikingeducation/project_tdd_minesweeper/assignees{/user}","branches_url":"https://api.github.com/repos/vikingeducation/project_tdd_minesweeper/branches{/branch}","tags_url":"https://api.github.com/repos/vikingeducation/project_tdd_minesweeper/tags","blobs_url":"https://api.github.com/repos/vikingeducation/project_tdd_minesweeper/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/vikingeducation/project_tdd_minesweeper/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/vikingeducation/project_tdd_minesweeper/git/refs{/sha}","trees_url":"https://api.github.com/repos/vikingeducation/project_tdd_minesweeper/git/trees{/sha}","statuses_url":"https://api.github.com/repos/vikingeducation/project_tdd_minesweeper/statuses/{sha}","languages_url":"https://api.github.com/repos/vikingeducation/project_tdd_minesweeper/languages","stargazers_url":"https://api.github.com/repos/vikingeducation/project_tdd_minesweeper/stargazers","contributors_url":"https://api.github.com/repos/vikingeducation/project_tdd_minesweeper/contributors","subscribers_url":"https://api.github.com/repos/vikingeducation/project_tdd_minesweeper/subscribers","subscription_url":"https://api.github.com/repos/vikingeducation/project_tdd_minesweeper/subscription","commits_url":"https://api.github.com/repos/vikingeducation/project_tdd_minesweeper/commits{/sha}","git_commits_url":"https://api.github.com/repos/vikingeducation/project_tdd_minesweeper/git/commits{/sha}","comments_url":"https://api.github.com/repos/vikingeducation/project_tdd_minesweeper/comments{/number}","issue_comment_url":"https://api.github.com/repos/vikingeducation/project_tdd_minesweeper/issues/comments{/number}","contents_url":"https://api.github.com/repos/vikingeducation/project_tdd_minesweeper/contents/{+path}","compare_url":"https://api.github.com/repos/vikingeducation/project_tdd_minesweeper/compare/{base}...{head}","merges_url":"https://api.github.com/repos/vikingeducation/project_tdd_minesweeper/merges","archive_url":"https://api.github.com/repos/vikingeducation/project_tdd_minesweeper/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/vikingeducation/project_tdd_minesweeper/downloads","issues_url":"https://api.github.com/repos/vikingeducation/project_tdd_minesweeper/issues{/number}","pulls_url":"https://api.github.com/repos/vikingeducation/project_tdd_minesweeper/pulls{/number}","milestones_url":"https://api.github.com/repos/vikingeducation/project_tdd_minesweeper/milestones{/number}","notifications_url":"https://api.github.com/repos/vikingeducation/project_tdd_minesweeper/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/vikingeducation/project_tdd_minesweeper/labels{/name}","releases_url":"https://api.github.com/repos/vikingeducation/project_tdd_minesweeper/releases{/id}","created_at":"2015-01-22T21:58:09Z","updated_at":"2015-01-22T21:58:09Z","pushed_at":"2015-04-19T16:22:42Z","git_url":"git://github.com/vikingeducation/project_tdd_minesweeper.git","ssh_url":"git@github.com:vikingeducation/project_tdd_minesweeper.git","clone_url":"https://github.com/vikingeducation/project_tdd_minesweeper.git","svn_url":"https://github.com/vikingeducation/project_tdd_minesweeper","homepage":null,"size":252,"stargazers_count":0,"watchers_count":0,"language":null,"has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":7,"mirror_url":null,"open_issues_count":5,"forks":7,"open_issues":5,"watchers":0,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/vikingeducation/project_tdd_minesweeper/pulls/5"},"html":{"href":"https://github.com/vikingeducation/project_tdd_minesweeper/pull/5"},"issue":{"href":"https://api.github.com/repos/vikingeducation/project_tdd_minesweeper/issues/5"},"comments":{"href":"https://api.github.com/repos/vikingeducation/project_tdd_minesweeper/issues/5/comments"},"review_comments":{"href":"https://api.github.com/repos/vikingeducation/project_tdd_minesweeper/pulls/5/comments"},"review_comment":{"href":"https://api.github.com/repos/vikingeducation/project_tdd_minesweeper/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/vikingeducation/project_tdd_minesweeper/pulls/5/commits"},"statuses":{"href":"https://api.github.com/repos/vikingeducation/project_tdd_minesweeper/statuses/e3b4345d6e1000015d37a6bc7f9e97fd80161f36"}}}}