{"action":"created","comment":{"url":"https://api.github.com/repos/flower-os/flower/pulls/comments/243994935","pull_request_review_id":187894764,"id":243994935,"node_id":"MDI0OlB1bGxSZXF1ZXN0UmV2aWV3Q29tbWVudDI0Mzk5NDkzNQ==","diff_hunk":"@@ -0,0 +1,366 @@\n+use core::sync::atomic::{Ordering, AtomicU64};\n+use alloc::vec::Vec;\n+use crate::terminal::{TerminalOutput, TerminalCharacter, Point, STDOUT};\n+use crate::drivers::{pit, ps2};\n+use crate::drivers::keyboard::{Ps2Keyboard, Keyboard, KeyEventType, keymap::codes::*};\n+use crate::halt;\n+\n+const HEAD_CHAR: char = 2 as char;\n+lazy_static! {\n+    static ref RNG: Random = Random::new();\n+}\n+\n+struct Game<'a> {\n+    grid: Grid,\n+    snake: Snake,\n+    ups: usize,\n+    keyboard: &'a mut Ps2Keyboard<'a>,\n+    highscore: u16,\n+}\n+\n+impl<'a> Game<'a> {\n+    fn new(keyboard: &'a mut Ps2Keyboard<'a>) -> Game<'a> {\n+        let res = STDOUT.read().resolution();\n+\n+        Game {\n+            grid: Grid::empty(res.x as usize, res.y as usize),\n+            snake: Snake::new(),\n+            ups: 20,\n+            keyboard,\n+            highscore: 0,\n+        }\n+    }\n+\n+    fn run(&mut self) {\n+        STDOUT.write().clear().expect(\"Error clearing screen\");\n+        self.notification(\"Welcome to snake! Press any key to continue...\");\n+\n+        STDOUT.write().clear().expect(\"Error clearing screen\");\n+        self.grid.set(generate_apple_pos(&self.grid), Cell::Apple);\n+\n+        loop {\n+            pit::sleep(1000 / self.ups);\n+\n+            if let Ok(Some(event)) = self.keyboard.read_event() {\n+                if event.event_type != KeyEventType::Break {\n+\n+                    // Change direction of motion\n+                    let new_direction = match event.keycode {\n+                        UP_ARROW | W => Some(Direction::Up),\n+                        DOWN_ARROW | S => Some(Direction::Down),\n+                        LEFT_ARROW | A => Some(Direction::Left),\n+                        RIGHT_ARROW | D => Some(Direction::Right),\n+                        _ => None,\n+                    };\n+\n+                    if let Some(new_direction) = new_direction {\n+                        if new_direction != self.snake.direction.opposite() {\n+                            self.snake.direction = new_direction;\n+                        }\n+                    }\n+\n+                    // Make the UPS lower (to lower apparent velocity) snake is travelling up because\n+                    // the cells are higher than they are wide\n+                    self.ups = match self.snake.direction {\n+                        Direction::Up | Direction::Down => 10,\n+                        Direction::Left | Direction::Right => 20,\n+                    };\n+                }\n+            }\n+\n+            // See if the game is over and if so restart it\n+            let win = match self.snake.update(&mut self.grid) {\n+                MoveResult::Win => true,\n+                MoveResult::Lose => false,\n+                _ => continue,\n+            };\n+\n+            self.restart(win);\n+        }\n+    }\n+\n+    fn restart(&mut self, win: bool) {\n+        let won = if win { \"win\" } else { \"lose\" };\n+        let highscore = if self.snake.score() > self.highscore {\n+            self.highscore = self.snake.score();\n+            \" New highscore!\"\n+        } else {\n+            \"\"\n+        };\n+        self.notification(\n+            &format!(\"You {}! Final score: {}.{}\", won, self.snake.score(), highscore)\n+        );\n+\n+        self.snake = Snake::new();\n+        let _res = STDOUT.read().resolution();","path":"kernel/src/snake.rs","position":95,"original_position":95,"commit_id":"91af5cd45da9e7b890a80eee28661cdb005f21be","original_commit_id":"91af5cd45da9e7b890a80eee28661cdb005f21be","user":{"login":"gegy1000","id":5172118,"node_id":"MDQ6VXNlcjUxNzIxMTg=","avatar_url":"https://avatars3.githubusercontent.com/u/5172118?v=4","gravatar_id":"","url":"https://api.github.com/users/gegy1000","html_url":"https://github.com/gegy1000","followers_url":"https://api.github.com/users/gegy1000/followers","following_url":"https://api.github.com/users/gegy1000/following{/other_user}","gists_url":"https://api.github.com/users/gegy1000/gists{/gist_id}","starred_url":"https://api.github.com/users/gegy1000/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/gegy1000/subscriptions","organizations_url":"https://api.github.com/users/gegy1000/orgs","repos_url":"https://api.github.com/users/gegy1000/repos","events_url":"https://api.github.com/users/gegy1000/events{/privacy}","received_events_url":"https://api.github.com/users/gegy1000/received_events","type":"User","site_admin":false},"body":"Can this be removed?","created_at":"2018-12-26T13:18:17Z","updated_at":"2018-12-26T13:18:18Z","html_url":"https://github.com/flower-os/flower/pull/79#discussion_r243994935","pull_request_url":"https://api.github.com/repos/flower-os/flower/pulls/79","author_association":"MEMBER","_links":{"self":{"href":"https://api.github.com/repos/flower-os/flower/pulls/comments/243994935"},"html":{"href":"https://github.com/flower-os/flower/pull/79#discussion_r243994935"},"pull_request":{"href":"https://api.github.com/repos/flower-os/flower/pulls/79"}}},"pull_request":{"url":"https://api.github.com/repos/flower-os/flower/pulls/79","id":240976855,"node_id":"MDExOlB1bGxSZXF1ZXN0MjQwOTc2ODU1","html_url":"https://github.com/flower-os/flower/pull/79","diff_url":"https://github.com/flower-os/flower/pull/79.diff","patch_url":"https://github.com/flower-os/flower/pull/79.patch","issue_url":"https://api.github.com/repos/flower-os/flower/issues/79","number":79,"state":"open","locked":false,"title":"Snake & fixup","user":{"login":"Restioson","id":6688948,"node_id":"MDQ6VXNlcjY2ODg5NDg=","avatar_url":"https://avatars2.githubusercontent.com/u/6688948?v=4","gravatar_id":"","url":"https://api.github.com/users/Restioson","html_url":"https://github.com/Restioson","followers_url":"https://api.github.com/users/Restioson/followers","following_url":"https://api.github.com/users/Restioson/following{/other_user}","gists_url":"https://api.github.com/users/Restioson/gists{/gist_id}","starred_url":"https://api.github.com/users/Restioson/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Restioson/subscriptions","organizations_url":"https://api.github.com/users/Restioson/orgs","repos_url":"https://api.github.com/users/Restioson/repos","events_url":"https://api.github.com/users/Restioson/events{/privacy}","received_events_url":"https://api.github.com/users/Restioson/received_events","type":"User","site_admin":false},"body":"This PR adds a snake game (because why not?), as well as updating us to the latest nightly, and rust edition 2018.","created_at":"2018-12-26T12:57:28Z","updated_at":"2018-12-26T13:18:18Z","closed_at":null,"merged_at":null,"merge_commit_sha":"700a210483041a1a740fc92d1bb36465f43f9b9f","assignee":null,"assignees":[],"requested_reviewers":[],"requested_teams":[],"labels":[],"milestone":null,"commits_url":"https://api.github.com/repos/flower-os/flower/pulls/79/commits","review_comments_url":"https://api.github.com/repos/flower-os/flower/pulls/79/comments","review_comment_url":"https://api.github.com/repos/flower-os/flower/pulls/comments{/number}","comments_url":"https://api.github.com/repos/flower-os/flower/issues/79/comments","statuses_url":"https://api.github.com/repos/flower-os/flower/statuses/91af5cd45da9e7b890a80eee28661cdb005f21be","head":{"label":"flower-os:snake","ref":"snake","sha":"91af5cd45da9e7b890a80eee28661cdb005f21be","user":{"login":"flower-os","id":42934789,"node_id":"MDEyOk9yZ2FuaXphdGlvbjQyOTM0Nzg5","avatar_url":"https://avatars1.githubusercontent.com/u/42934789?v=4","gravatar_id":"","url":"https://api.github.com/users/flower-os","html_url":"https://github.com/flower-os","followers_url":"https://api.github.com/users/flower-os/followers","following_url":"https://api.github.com/users/flower-os/following{/other_user}","gists_url":"https://api.github.com/users/flower-os/gists{/gist_id}","starred_url":"https://api.github.com/users/flower-os/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/flower-os/subscriptions","organizations_url":"https://api.github.com/users/flower-os/orgs","repos_url":"https://api.github.com/users/flower-os/repos","events_url":"https://api.github.com/users/flower-os/events{/privacy}","received_events_url":"https://api.github.com/users/flower-os/received_events","type":"Organization","site_admin":false},"repo":{"id":109166201,"node_id":"MDEwOlJlcG9zaXRvcnkxMDkxNjYyMDE=","name":"flower","full_name":"flower-os/flower","private":false,"owner":{"login":"flower-os","id":42934789,"node_id":"MDEyOk9yZ2FuaXphdGlvbjQyOTM0Nzg5","avatar_url":"https://avatars1.githubusercontent.com/u/42934789?v=4","gravatar_id":"","url":"https://api.github.com/users/flower-os","html_url":"https://github.com/flower-os","followers_url":"https://api.github.com/users/flower-os/followers","following_url":"https://api.github.com/users/flower-os/following{/other_user}","gists_url":"https://api.github.com/users/flower-os/gists{/gist_id}","starred_url":"https://api.github.com/users/flower-os/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/flower-os/subscriptions","organizations_url":"https://api.github.com/users/flower-os/orgs","repos_url":"https://api.github.com/users/flower-os/repos","events_url":"https://api.github.com/users/flower-os/events{/privacy}","received_events_url":"https://api.github.com/users/flower-os/received_events","type":"Organization","site_admin":false},"html_url":"https://github.com/flower-os/flower","description":"A learning OS","fork":false,"url":"https://api.github.com/repos/flower-os/flower","forks_url":"https://api.github.com/repos/flower-os/flower/forks","keys_url":"https://api.github.com/repos/flower-os/flower/keys{/key_id}","collaborators_url":"https://api.github.com/repos/flower-os/flower/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/flower-os/flower/teams","hooks_url":"https://api.github.com/repos/flower-os/flower/hooks","issue_events_url":"https://api.github.com/repos/flower-os/flower/issues/events{/number}","events_url":"https://api.github.com/repos/flower-os/flower/events","assignees_url":"https://api.github.com/repos/flower-os/flower/assignees{/user}","branches_url":"https://api.github.com/repos/flower-os/flower/branches{/branch}","tags_url":"https://api.github.com/repos/flower-os/flower/tags","blobs_url":"https://api.github.com/repos/flower-os/flower/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/flower-os/flower/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/flower-os/flower/git/refs{/sha}","trees_url":"https://api.github.com/repos/flower-os/flower/git/trees{/sha}","statuses_url":"https://api.github.com/repos/flower-os/flower/statuses/{sha}","languages_url":"https://api.github.com/repos/flower-os/flower/languages","stargazers_url":"https://api.github.com/repos/flower-os/flower/stargazers","contributors_url":"https://api.github.com/repos/flower-os/flower/contributors","subscribers_url":"https://api.github.com/repos/flower-os/flower/subscribers","subscription_url":"https://api.github.com/repos/flower-os/flower/subscription","commits_url":"https://api.github.com/repos/flower-os/flower/commits{/sha}","git_commits_url":"https://api.github.com/repos/flower-os/flower/git/commits{/sha}","comments_url":"https://api.github.com/repos/flower-os/flower/comments{/number}","issue_comment_url":"https://api.github.com/repos/flower-os/flower/issues/comments{/number}","contents_url":"https://api.github.com/repos/flower-os/flower/contents/{+path}","compare_url":"https://api.github.com/repos/flower-os/flower/compare/{base}...{head}","merges_url":"https://api.github.com/repos/flower-os/flower/merges","archive_url":"https://api.github.com/repos/flower-os/flower/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/flower-os/flower/downloads","issues_url":"https://api.github.com/repos/flower-os/flower/issues{/number}","pulls_url":"https://api.github.com/repos/flower-os/flower/pulls{/number}","milestones_url":"https://api.github.com/repos/flower-os/flower/milestones{/number}","notifications_url":"https://api.github.com/repos/flower-os/flower/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/flower-os/flower/labels{/name}","releases_url":"https://api.github.com/repos/flower-os/flower/releases{/id}","deployments_url":"https://api.github.com/repos/flower-os/flower/deployments","created_at":"2017-11-01T18:12:14Z","updated_at":"2018-12-21T11:15:12Z","pushed_at":"2018-12-26T12:57:29Z","git_url":"git://github.com/flower-os/flower.git","ssh_url":"git@github.com:flower-os/flower.git","clone_url":"https://github.com/flower-os/flower.git","svn_url":"https://github.com/flower-os/flower","homepage":"https://gitter.im/flower-os/Lobby","size":354,"stargazers_count":33,"watchers_count":33,"language":"Rust","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":4,"mirror_url":null,"archived":false,"open_issues_count":23,"license":{"key":"apache-2.0","name":"Apache License 2.0","spdx_id":"Apache-2.0","url":"https://api.github.com/licenses/apache-2.0","node_id":"MDc6TGljZW5zZTI="},"forks":4,"open_issues":23,"watchers":33,"default_branch":"development"}},"base":{"label":"flower-os:development","ref":"development","sha":"d21f21254536d9ab6520ba2dd4088751906f4403","user":{"login":"flower-os","id":42934789,"node_id":"MDEyOk9yZ2FuaXphdGlvbjQyOTM0Nzg5","avatar_url":"https://avatars1.githubusercontent.com/u/42934789?v=4","gravatar_id":"","url":"https://api.github.com/users/flower-os","html_url":"https://github.com/flower-os","followers_url":"https://api.github.com/users/flower-os/followers","following_url":"https://api.github.com/users/flower-os/following{/other_user}","gists_url":"https://api.github.com/users/flower-os/gists{/gist_id}","starred_url":"https://api.github.com/users/flower-os/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/flower-os/subscriptions","organizations_url":"https://api.github.com/users/flower-os/orgs","repos_url":"https://api.github.com/users/flower-os/repos","events_url":"https://api.github.com/users/flower-os/events{/privacy}","received_events_url":"https://api.github.com/users/flower-os/received_events","type":"Organization","site_admin":false},"repo":{"id":109166201,"node_id":"MDEwOlJlcG9zaXRvcnkxMDkxNjYyMDE=","name":"flower","full_name":"flower-os/flower","private":false,"owner":{"login":"flower-os","id":42934789,"node_id":"MDEyOk9yZ2FuaXphdGlvbjQyOTM0Nzg5","avatar_url":"https://avatars1.githubusercontent.com/u/42934789?v=4","gravatar_id":"","url":"https://api.github.com/users/flower-os","html_url":"https://github.com/flower-os","followers_url":"https://api.github.com/users/flower-os/followers","following_url":"https://api.github.com/users/flower-os/following{/other_user}","gists_url":"https://api.github.com/users/flower-os/gists{/gist_id}","starred_url":"https://api.github.com/users/flower-os/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/flower-os/subscriptions","organizations_url":"https://api.github.com/users/flower-os/orgs","repos_url":"https://api.github.com/users/flower-os/repos","events_url":"https://api.github.com/users/flower-os/events{/privacy}","received_events_url":"https://api.github.com/users/flower-os/received_events","type":"Organization","site_admin":false},"html_url":"https://github.com/flower-os/flower","description":"A learning OS","fork":false,"url":"https://api.github.com/repos/flower-os/flower","forks_url":"https://api.github.com/repos/flower-os/flower/forks","keys_url":"https://api.github.com/repos/flower-os/flower/keys{/key_id}","collaborators_url":"https://api.github.com/repos/flower-os/flower/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/flower-os/flower/teams","hooks_url":"https://api.github.com/repos/flower-os/flower/hooks","issue_events_url":"https://api.github.com/repos/flower-os/flower/issues/events{/number}","events_url":"https://api.github.com/repos/flower-os/flower/events","assignees_url":"https://api.github.com/repos/flower-os/flower/assignees{/user}","branches_url":"https://api.github.com/repos/flower-os/flower/branches{/branch}","tags_url":"https://api.github.com/repos/flower-os/flower/tags","blobs_url":"https://api.github.com/repos/flower-os/flower/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/flower-os/flower/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/flower-os/flower/git/refs{/sha}","trees_url":"https://api.github.com/repos/flower-os/flower/git/trees{/sha}","statuses_url":"https://api.github.com/repos/flower-os/flower/statuses/{sha}","languages_url":"https://api.github.com/repos/flower-os/flower/languages","stargazers_url":"https://api.github.com/repos/flower-os/flower/stargazers","contributors_url":"https://api.github.com/repos/flower-os/flower/contributors","subscribers_url":"https://api.github.com/repos/flower-os/flower/subscribers","subscription_url":"https://api.github.com/repos/flower-os/flower/subscription","commits_url":"https://api.github.com/repos/flower-os/flower/commits{/sha}","git_commits_url":"https://api.github.com/repos/flower-os/flower/git/commits{/sha}","comments_url":"https://api.github.com/repos/flower-os/flower/comments{/number}","issue_comment_url":"https://api.github.com/repos/flower-os/flower/issues/comments{/number}","contents_url":"https://api.github.com/repos/flower-os/flower/contents/{+path}","compare_url":"https://api.github.com/repos/flower-os/flower/compare/{base}...{head}","merges_url":"https://api.github.com/repos/flower-os/flower/merges","archive_url":"https://api.github.com/repos/flower-os/flower/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/flower-os/flower/downloads","issues_url":"https://api.github.com/repos/flower-os/flower/issues{/number}","pulls_url":"https://api.github.com/repos/flower-os/flower/pulls{/number}","milestones_url":"https://api.github.com/repos/flower-os/flower/milestones{/number}","notifications_url":"https://api.github.com/repos/flower-os/flower/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/flower-os/flower/labels{/name}","releases_url":"https://api.github.com/repos/flower-os/flower/releases{/id}","deployments_url":"https://api.github.com/repos/flower-os/flower/deployments","created_at":"2017-11-01T18:12:14Z","updated_at":"2018-12-21T11:15:12Z","pushed_at":"2018-12-26T12:57:29Z","git_url":"git://github.com/flower-os/flower.git","ssh_url":"git@github.com:flower-os/flower.git","clone_url":"https://github.com/flower-os/flower.git","svn_url":"https://github.com/flower-os/flower","homepage":"https://gitter.im/flower-os/Lobby","size":354,"stargazers_count":33,"watchers_count":33,"language":"Rust","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":4,"mirror_url":null,"archived":false,"open_issues_count":23,"license":{"key":"apache-2.0","name":"Apache License 2.0","spdx_id":"Apache-2.0","url":"https://api.github.com/licenses/apache-2.0","node_id":"MDc6TGljZW5zZTI="},"forks":4,"open_issues":23,"watchers":33,"default_branch":"development"}},"_links":{"self":{"href":"https://api.github.com/repos/flower-os/flower/pulls/79"},"html":{"href":"https://github.com/flower-os/flower/pull/79"},"issue":{"href":"https://api.github.com/repos/flower-os/flower/issues/79"},"comments":{"href":"https://api.github.com/repos/flower-os/flower/issues/79/comments"},"review_comments":{"href":"https://api.github.com/repos/flower-os/flower/pulls/79/comments"},"review_comment":{"href":"https://api.github.com/repos/flower-os/flower/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/flower-os/flower/pulls/79/commits"},"statuses":{"href":"https://api.github.com/repos/flower-os/flower/statuses/91af5cd45da9e7b890a80eee28661cdb005f21be"}},"author_association":"MEMBER"}}
{"actor":{"display_login":"gegy1000"}}