{"action":"created","comment":{"url":"https://api.github.com/repos/raccoons-2014/Smackwangler/pulls/comments/22524187","id":22524187,"diff_hunk":"@@ -1,61 +1,87 @@\n module GameEngine\n   module Controller\n+\n+    def self.save_game_state(game_state)\n+      GameEngine::Cache.save_game_state(game_state)\n+    end\n+\n+    def self.fetch_game_state(game_data)\n+      GameEngine::Cache.fetch_game_state(game_data)\n+    end\n+\n+    def self.update_game_state_time(game_state)\n+      game_state.time = Time.now\n+    end\n+\n+    def self.output_player_data(game_state, player_id)\n+      GameEngine::IO.output_player_data(game_state, player_id)\n+    end\n+\n+    def self.selection_made?(player)\n+      !player.selection.empty?\n+    end\n+\n+    def self.gamestate_time_save_output(game_state, player_id)\n+      update_game_state_time(game_state)\n+      save_game_state(game_state)\n+      output_player_data(game_state, player_id)\n+    end\n+\n+    def self.phase_time_check(game_state, time_input)\n+      Time.now - game_state.time >= GAME_RULES[time_input]\n+    end\n+\n     def self.advance_game(game_data, player_id)\n       # This method is responsible for switching phases inside of the GameEngine::Game\n       # class when passed the ActiveRecord model of the game and the player_id for the\n-      # client that's making the request. This code is not very pretty and has a lot of\n-      # nested conditionals.\n-      # ===========================================\n-      # NEEDS TO BE REFACTORED BEFORE FINAL VERSION.\n-      # ===========================================\n-      game_state = GameEngine::Cache.fetch_game_state(game_data)\n+      # client that's making the request.\n+      game_state = fetch_game_state(game_data)\n       current_time = Time.now\n \n-      if game_state.phase == :setup\n-        if current_time - game_state.time >= GAME_RULES[:setup_time]\n+      current_player = game_state.target_player(player_id.to_i)\n+      player_one = game_state.player_one\n+      player_two = game_state.player_two\n+\n+      case game_state.phase\n+      when :setup\n+        if phase_time_check(game_state, :setup_time)\n           game_state.phase = :move\n-          game_state.time = Time.now\n           GameEngine::GameResolver.deal_cards(game_state)\n-          GameEngine::Cache.save_game_state(game_state)\n-          GameEngine::IO.output_player_data(game_state, player_id)\n+          gamestate_time_save_output(game_state, player_id)\n+\n         end\n-      elsif game_state.phase == :move\n-        if current_time - game_state.time >= GAME_RULES[:move_time]\n-          if game_state.target_player(player_id.to_i).selection.empty?\n-            game_state.target_player(player_id.to_i).selection << nil\n-            GameEngine::Cache.save_game_state(game_state)\n-            GameEngine::IO.output_player_data(game_state, player_id)\n-          end\n+      when :move\n+        if phase_time_check(game_state, :move_time) && !selection_made?(current_player)\n+            current_player.selection << nil\n+            save_game_state(game_state)\n+            output_player_data(game_state, player_id)\n         end\n \n-        if !game_state.player_one.selection.empty? && !game_state.player_two.selection.empty?\n+        if selection_made?(player_one) && selection_made?(player_two)","path":"app/game/game_engine/controller.rb","position":79,"original_position":79,"commit_id":"5c69bb736888ed5b310712f50dc78a7d0353c3a8","original_commit_id":"5c69bb736888ed5b310712f50dc78a7d0353c3a8","user":{"login":"wcstorey","id":6692265,"avatar_url":"https://avatars.githubusercontent.com/u/6692265?v=3","gravatar_id":"","url":"https://api.github.com/users/wcstorey","html_url":"https://github.com/wcstorey","followers_url":"https://api.github.com/users/wcstorey/followers","following_url":"https://api.github.com/users/wcstorey/following{/other_user}","gists_url":"https://api.github.com/users/wcstorey/gists{/gist_id}","starred_url":"https://api.github.com/users/wcstorey/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/wcstorey/subscriptions","organizations_url":"https://api.github.com/users/wcstorey/orgs","repos_url":"https://api.github.com/users/wcstorey/repos","events_url":"https://api.github.com/users/wcstorey/events{/privacy}","received_events_url":"https://api.github.com/users/wcstorey/received_events","type":"User","site_admin":false},"body":"bothplayersmoved?(player_one, player_two)","created_at":"2015-01-06T14:14:20Z","updated_at":"2015-01-06T14:14:20Z","html_url":"https://github.com/raccoons-2014/Smackwangler/pull/66#discussion_r22524187","pull_request_url":"https://api.github.com/repos/raccoons-2014/Smackwangler/pulls/66","_links":{"self":{"href":"https://api.github.com/repos/raccoons-2014/Smackwangler/pulls/comments/22524187"},"html":{"href":"https://github.com/raccoons-2014/Smackwangler/pull/66#discussion_r22524187"},"pull_request":{"href":"https://api.github.com/repos/raccoons-2014/Smackwangler/pulls/66"}}},"pull_request":{"url":"https://api.github.com/repos/raccoons-2014/Smackwangler/pulls/66","id":26870044,"html_url":"https://github.com/raccoons-2014/Smackwangler/pull/66","diff_url":"https://github.com/raccoons-2014/Smackwangler/pull/66.diff","patch_url":"https://github.com/raccoons-2014/Smackwangler/pull/66.patch","issue_url":"https://api.github.com/repos/raccoons-2014/Smackwangler/issues/66","number":66,"state":"open","locked":false,"title":"Refactor game controller","user":{"login":"wcstorey","id":6692265,"avatar_url":"https://avatars.githubusercontent.com/u/6692265?v=3","gravatar_id":"","url":"https://api.github.com/users/wcstorey","html_url":"https://github.com/wcstorey","followers_url":"https://api.github.com/users/wcstorey/followers","following_url":"https://api.github.com/users/wcstorey/following{/other_user}","gists_url":"https://api.github.com/users/wcstorey/gists{/gist_id}","starred_url":"https://api.github.com/users/wcstorey/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/wcstorey/subscriptions","organizations_url":"https://api.github.com/users/wcstorey/orgs","repos_url":"https://api.github.com/users/wcstorey/repos","events_url":"https://api.github.com/users/wcstorey/events{/privacy}","received_events_url":"https://api.github.com/users/wcstorey/received_events","type":"User","site_admin":false},"body":"@dm-istomin @matthewhuff89 ","created_at":"2015-01-06T04:57:36Z","updated_at":"2015-01-06T14:14:20Z","closed_at":null,"merged_at":null,"merge_commit_sha":"e52bf503715901bedcbb3a1b404c4c5fcc990787","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/raccoons-2014/Smackwangler/pulls/66/commits","review_comments_url":"https://api.github.com/repos/raccoons-2014/Smackwangler/pulls/66/comments","review_comment_url":"https://api.github.com/repos/raccoons-2014/Smackwangler/pulls/comments/{number}","comments_url":"https://api.github.com/repos/raccoons-2014/Smackwangler/issues/66/comments","statuses_url":"https://api.github.com/repos/raccoons-2014/Smackwangler/statuses/5c69bb736888ed5b310712f50dc78a7d0353c3a8","head":{"label":"raccoons-2014:refactor_game_controller","ref":"refactor_game_controller","sha":"5c69bb736888ed5b310712f50dc78a7d0353c3a8","user":{"login":"raccoons-2014","id":6732839,"avatar_url":"https://avatars.githubusercontent.com/u/6732839?v=3","gravatar_id":"","url":"https://api.github.com/users/raccoons-2014","html_url":"https://github.com/raccoons-2014","followers_url":"https://api.github.com/users/raccoons-2014/followers","following_url":"https://api.github.com/users/raccoons-2014/following{/other_user}","gists_url":"https://api.github.com/users/raccoons-2014/gists{/gist_id}","starred_url":"https://api.github.com/users/raccoons-2014/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/raccoons-2014/subscriptions","organizations_url":"https://api.github.com/users/raccoons-2014/orgs","repos_url":"https://api.github.com/users/raccoons-2014/repos","events_url":"https://api.github.com/users/raccoons-2014/events{/privacy}","received_events_url":"https://api.github.com/users/raccoons-2014/received_events","type":"Organization","site_admin":false},"repo":{"id":28188831,"name":"Smackwangler","full_name":"raccoons-2014/Smackwangler","owner":{"login":"raccoons-2014","id":6732839,"avatar_url":"https://avatars.githubusercontent.com/u/6732839?v=3","gravatar_id":"","url":"https://api.github.com/users/raccoons-2014","html_url":"https://github.com/raccoons-2014","followers_url":"https://api.github.com/users/raccoons-2014/followers","following_url":"https://api.github.com/users/raccoons-2014/following{/other_user}","gists_url":"https://api.github.com/users/raccoons-2014/gists{/gist_id}","starred_url":"https://api.github.com/users/raccoons-2014/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/raccoons-2014/subscriptions","organizations_url":"https://api.github.com/users/raccoons-2014/orgs","repos_url":"https://api.github.com/users/raccoons-2014/repos","events_url":"https://api.github.com/users/raccoons-2014/events{/privacy}","received_events_url":"https://api.github.com/users/raccoons-2014/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/raccoons-2014/Smackwangler","description":"The trading card game from the futuristic dystopia of your dreams.","fork":false,"url":"https://api.github.com/repos/raccoons-2014/Smackwangler","forks_url":"https://api.github.com/repos/raccoons-2014/Smackwangler/forks","keys_url":"https://api.github.com/repos/raccoons-2014/Smackwangler/keys{/key_id}","collaborators_url":"https://api.github.com/repos/raccoons-2014/Smackwangler/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/raccoons-2014/Smackwangler/teams","hooks_url":"https://api.github.com/repos/raccoons-2014/Smackwangler/hooks","issue_events_url":"https://api.github.com/repos/raccoons-2014/Smackwangler/issues/events{/number}","events_url":"https://api.github.com/repos/raccoons-2014/Smackwangler/events","assignees_url":"https://api.github.com/repos/raccoons-2014/Smackwangler/assignees{/user}","branches_url":"https://api.github.com/repos/raccoons-2014/Smackwangler/branches{/branch}","tags_url":"https://api.github.com/repos/raccoons-2014/Smackwangler/tags","blobs_url":"https://api.github.com/repos/raccoons-2014/Smackwangler/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/raccoons-2014/Smackwangler/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/raccoons-2014/Smackwangler/git/refs{/sha}","trees_url":"https://api.github.com/repos/raccoons-2014/Smackwangler/git/trees{/sha}","statuses_url":"https://api.github.com/repos/raccoons-2014/Smackwangler/statuses/{sha}","languages_url":"https://api.github.com/repos/raccoons-2014/Smackwangler/languages","stargazers_url":"https://api.github.com/repos/raccoons-2014/Smackwangler/stargazers","contributors_url":"https://api.github.com/repos/raccoons-2014/Smackwangler/contributors","subscribers_url":"https://api.github.com/repos/raccoons-2014/Smackwangler/subscribers","subscription_url":"https://api.github.com/repos/raccoons-2014/Smackwangler/subscription","commits_url":"https://api.github.com/repos/raccoons-2014/Smackwangler/commits{/sha}","git_commits_url":"https://api.github.com/repos/raccoons-2014/Smackwangler/git/commits{/sha}","comments_url":"https://api.github.com/repos/raccoons-2014/Smackwangler/comments{/number}","issue_comment_url":"https://api.github.com/repos/raccoons-2014/Smackwangler/issues/comments/{number}","contents_url":"https://api.github.com/repos/raccoons-2014/Smackwangler/contents/{+path}","compare_url":"https://api.github.com/repos/raccoons-2014/Smackwangler/compare/{base}...{head}","merges_url":"https://api.github.com/repos/raccoons-2014/Smackwangler/merges","archive_url":"https://api.github.com/repos/raccoons-2014/Smackwangler/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/raccoons-2014/Smackwangler/downloads","issues_url":"https://api.github.com/repos/raccoons-2014/Smackwangler/issues{/number}","pulls_url":"https://api.github.com/repos/raccoons-2014/Smackwangler/pulls{/number}","milestones_url":"https://api.github.com/repos/raccoons-2014/Smackwangler/milestones{/number}","notifications_url":"https://api.github.com/repos/raccoons-2014/Smackwangler/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/raccoons-2014/Smackwangler/labels{/name}","releases_url":"https://api.github.com/repos/raccoons-2014/Smackwangler/releases{/id}","created_at":"2014-12-18T15:22:43Z","updated_at":"2015-01-05T15:33:55Z","pushed_at":"2015-01-06T05:25:40Z","git_url":"git://github.com/raccoons-2014/Smackwangler.git","ssh_url":"git@github.com:raccoons-2014/Smackwangler.git","clone_url":"https://github.com/raccoons-2014/Smackwangler.git","svn_url":"https://github.com/raccoons-2014/Smackwangler","homepage":null,"size":6888,"stargazers_count":0,"watchers_count":0,"language":"Ruby","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":2,"forks":0,"open_issues":2,"watchers":0,"default_branch":"master"}},"base":{"label":"raccoons-2014:development","ref":"development","sha":"fdcb5c9f93497cd30954c5bd8c43a1630a22494b","user":{"login":"raccoons-2014","id":6732839,"avatar_url":"https://avatars.githubusercontent.com/u/6732839?v=3","gravatar_id":"","url":"https://api.github.com/users/raccoons-2014","html_url":"https://github.com/raccoons-2014","followers_url":"https://api.github.com/users/raccoons-2014/followers","following_url":"https://api.github.com/users/raccoons-2014/following{/other_user}","gists_url":"https://api.github.com/users/raccoons-2014/gists{/gist_id}","starred_url":"https://api.github.com/users/raccoons-2014/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/raccoons-2014/subscriptions","organizations_url":"https://api.github.com/users/raccoons-2014/orgs","repos_url":"https://api.github.com/users/raccoons-2014/repos","events_url":"https://api.github.com/users/raccoons-2014/events{/privacy}","received_events_url":"https://api.github.com/users/raccoons-2014/received_events","type":"Organization","site_admin":false},"repo":{"id":28188831,"name":"Smackwangler","full_name":"raccoons-2014/Smackwangler","owner":{"login":"raccoons-2014","id":6732839,"avatar_url":"https://avatars.githubusercontent.com/u/6732839?v=3","gravatar_id":"","url":"https://api.github.com/users/raccoons-2014","html_url":"https://github.com/raccoons-2014","followers_url":"https://api.github.com/users/raccoons-2014/followers","following_url":"https://api.github.com/users/raccoons-2014/following{/other_user}","gists_url":"https://api.github.com/users/raccoons-2014/gists{/gist_id}","starred_url":"https://api.github.com/users/raccoons-2014/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/raccoons-2014/subscriptions","organizations_url":"https://api.github.com/users/raccoons-2014/orgs","repos_url":"https://api.github.com/users/raccoons-2014/repos","events_url":"https://api.github.com/users/raccoons-2014/events{/privacy}","received_events_url":"https://api.github.com/users/raccoons-2014/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/raccoons-2014/Smackwangler","description":"The trading card game from the futuristic dystopia of your dreams.","fork":false,"url":"https://api.github.com/repos/raccoons-2014/Smackwangler","forks_url":"https://api.github.com/repos/raccoons-2014/Smackwangler/forks","keys_url":"https://api.github.com/repos/raccoons-2014/Smackwangler/keys{/key_id}","collaborators_url":"https://api.github.com/repos/raccoons-2014/Smackwangler/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/raccoons-2014/Smackwangler/teams","hooks_url":"https://api.github.com/repos/raccoons-2014/Smackwangler/hooks","issue_events_url":"https://api.github.com/repos/raccoons-2014/Smackwangler/issues/events{/number}","events_url":"https://api.github.com/repos/raccoons-2014/Smackwangler/events","assignees_url":"https://api.github.com/repos/raccoons-2014/Smackwangler/assignees{/user}","branches_url":"https://api.github.com/repos/raccoons-2014/Smackwangler/branches{/branch}","tags_url":"https://api.github.com/repos/raccoons-2014/Smackwangler/tags","blobs_url":"https://api.github.com/repos/raccoons-2014/Smackwangler/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/raccoons-2014/Smackwangler/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/raccoons-2014/Smackwangler/git/refs{/sha}","trees_url":"https://api.github.com/repos/raccoons-2014/Smackwangler/git/trees{/sha}","statuses_url":"https://api.github.com/repos/raccoons-2014/Smackwangler/statuses/{sha}","languages_url":"https://api.github.com/repos/raccoons-2014/Smackwangler/languages","stargazers_url":"https://api.github.com/repos/raccoons-2014/Smackwangler/stargazers","contributors_url":"https://api.github.com/repos/raccoons-2014/Smackwangler/contributors","subscribers_url":"https://api.github.com/repos/raccoons-2014/Smackwangler/subscribers","subscription_url":"https://api.github.com/repos/raccoons-2014/Smackwangler/subscription","commits_url":"https://api.github.com/repos/raccoons-2014/Smackwangler/commits{/sha}","git_commits_url":"https://api.github.com/repos/raccoons-2014/Smackwangler/git/commits{/sha}","comments_url":"https://api.github.com/repos/raccoons-2014/Smackwangler/comments{/number}","issue_comment_url":"https://api.github.com/repos/raccoons-2014/Smackwangler/issues/comments/{number}","contents_url":"https://api.github.com/repos/raccoons-2014/Smackwangler/contents/{+path}","compare_url":"https://api.github.com/repos/raccoons-2014/Smackwangler/compare/{base}...{head}","merges_url":"https://api.github.com/repos/raccoons-2014/Smackwangler/merges","archive_url":"https://api.github.com/repos/raccoons-2014/Smackwangler/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/raccoons-2014/Smackwangler/downloads","issues_url":"https://api.github.com/repos/raccoons-2014/Smackwangler/issues{/number}","pulls_url":"https://api.github.com/repos/raccoons-2014/Smackwangler/pulls{/number}","milestones_url":"https://api.github.com/repos/raccoons-2014/Smackwangler/milestones{/number}","notifications_url":"https://api.github.com/repos/raccoons-2014/Smackwangler/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/raccoons-2014/Smackwangler/labels{/name}","releases_url":"https://api.github.com/repos/raccoons-2014/Smackwangler/releases{/id}","created_at":"2014-12-18T15:22:43Z","updated_at":"2015-01-05T15:33:55Z","pushed_at":"2015-01-06T05:25:40Z","git_url":"git://github.com/raccoons-2014/Smackwangler.git","ssh_url":"git@github.com:raccoons-2014/Smackwangler.git","clone_url":"https://github.com/raccoons-2014/Smackwangler.git","svn_url":"https://github.com/raccoons-2014/Smackwangler","homepage":null,"size":6888,"stargazers_count":0,"watchers_count":0,"language":"Ruby","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":2,"forks":0,"open_issues":2,"watchers":0,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/raccoons-2014/Smackwangler/pulls/66"},"html":{"href":"https://github.com/raccoons-2014/Smackwangler/pull/66"},"issue":{"href":"https://api.github.com/repos/raccoons-2014/Smackwangler/issues/66"},"comments":{"href":"https://api.github.com/repos/raccoons-2014/Smackwangler/issues/66/comments"},"review_comments":{"href":"https://api.github.com/repos/raccoons-2014/Smackwangler/pulls/66/comments"},"review_comment":{"href":"https://api.github.com/repos/raccoons-2014/Smackwangler/pulls/comments/{number}"},"commits":{"href":"https://api.github.com/repos/raccoons-2014/Smackwangler/pulls/66/commits"},"statuses":{"href":"https://api.github.com/repos/raccoons-2014/Smackwangler/statuses/5c69bb736888ed5b310712f50dc78a7d0353c3a8"}}}}