Graham Weber
    • Create new note
    • Create a note from template
      • Sharing URL Link copied
      • /edit
      • View mode
        • Edit mode
        • View mode
        • Book mode
        • Slide mode
        Edit mode View mode Book mode Slide mode
      • Customize slides
      • Note Permission
      • Read
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Write
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Engagement control Commenting, Suggest edit, Emoji Reply
    • Invite by email
      Invitee

      This note has no invitees

    • Publish Note

      Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

      Your note will be visible on your profile and discoverable by anyone.
      Your note is now live.
      This note is visible on your profile and discoverable online.
      Everyone on the web can find and read all notes of this public team.
      See published notes
      Unpublish note
      Please check the box to agree to the Community Guidelines.
      View profile
    • Commenting
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
      • Everyone
    • Suggest edit
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
    • Emoji Reply
    • Enable
    • Versions and GitHub Sync
    • Note settings
    • Note Insights New
    • Engagement control
    • Make a copy
    • Transfer ownership
    • Delete this note
    • Save as template
    • Insert from template
    • Import from
      • Dropbox
      • Google Drive
      • Gist
      • Clipboard
    • Export to
      • Dropbox
      • Google Drive
      • Gist
    • Download
      • Markdown
      • HTML
      • Raw HTML
Menu Note settings Note Insights Versions and GitHub Sync Sharing URL Create Help
Create Create new note Create a note from template
Menu
Options
Engagement control Make a copy Transfer ownership Delete this note
Import from
Dropbox Google Drive Gist Clipboard
Export to
Dropbox Google Drive Gist
Download
Markdown HTML Raw HTML
Back
Sharing URL Link copied
/edit
View mode
  • Edit mode
  • View mode
  • Book mode
  • Slide mode
Edit mode View mode Book mode Slide mode
Customize slides
Note Permission
Read
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Write
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Engagement control Commenting, Suggest edit, Emoji Reply
  • Invite by email
    Invitee

    This note has no invitees

  • Publish Note

    Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

    Your note will be visible on your profile and discoverable by anyone.
    Your note is now live.
    This note is visible on your profile and discoverable online.
    Everyone on the web can find and read all notes of this public team.
    See published notes
    Unpublish note
    Please check the box to agree to the Community Guidelines.
    View profile
    Engagement control
    Commenting
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    • Everyone
    Suggest edit
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    Emoji Reply
    Enable
    Import from Dropbox Google Drive Gist Clipboard
       Owned this note    Owned this note      
    Published Linked with GitHub
    1
    • Any changes
      Be notified of any changes
    • Mention me
      Be notified of mention me
    • Unsubscribe
    # Rac-man Function Map ### Libraries ``` (require 2htdp/image) (require 2htdp/universe) (require 2htdp/iTunes) (require 2htdp/abstraction) ``` ### Constants ```racket ; Width of World (define DIAM 40) ; Create World (define playArea (rectangle (* DIAM 20) (* DIAM 20) "solid" "black")) ; Dot Image (define dotPic (circle (/ DIAM 10) "solid" "pink")) ; Cookie Image (define POWERUP (circle (/ DIAM 20) "solid" "white")) ; Ghost1 image (define ghost1 (rectangle 30 40 "solid" "blue")) ; Ghost2 image (define ghost2 (rectangle 30 40 "solid" "red")) ;Ghost3 image (define ghost3 (rectangle 30 40 "solid" "pink")) ;Ghost4 image (define ghost4 (rectangle 30 40 "solid" "orange")) ; Rac-man Image (define racman-pic (circle (/ DIAM 2.5) "solid" (color 255 223 0 255))) ``` ### Structures ```racket (define-struct racman [x y curdir nexdir]) ; A racman is a structure ; Interpretation represents current state of racman. x and y position, the directoin he currently is heading and the intended next direction of the user ; --- (make-racman 55 100 "up" "right") ; A **Speed** is a Number ; Interprtation represents the velocity of racman and ghosts at current state ; A **Dots** is a list of posns ; Represents the pellets that racman eats for points (define-struct gamestate [racman dots speed]) ; a gamestate is a structure ; Interpretion represents the current state of the entire game with racman dots on screen, and the current game speed --- (make-gamestate (make-racman 55 100 "up" "right") (define dotslist (list (make-posn 200 100) (make-posn 220 100))) 5) ``` ### Functions #### Wishlist Gamestate ```racket ; Wishlist gamestate structure ; A power-up is a an boolean ; Interpretation represents whether racman is in powerup state which allows him to eat ghosts ; A lives is a number ; Interpretation represents the remainng lives of racman ; --- initialzed to 3 ; Points is a number ; Interpretation represents that current points of racman player ;(define-struct gamestate [ rac-man ghosts maze dots speed power-up lives points]) ; Maze is a list? array? ; Interpretation represents the possible paths and boundries of where racman and ; ghosts are allowed to go (define (dotListGenerator DIAM) (list (make-posn 400 400))) ``` Menu ```racket ; Menu struct ; A highscores is a list-of numbers ; (define-struct menustate [highscores]) ; Menu function ; a gs is a menustate ; menustate -> menustate ; Displays high scores, starts game, quits (define (menu gs) (big-bang gs [on-tick checkClick] [to-draw renderMenu] [on-key menuKeys] [on-mouse menuClicks])) ; renderMenu ; a scores is a highschores ; scores -> image ; Renders the menu screen with a list of high scores (define (renderMenu scores) (overlay buttons (renderScores scores))) ; renderScores ; scores -> image ; Renders the list of high scores (define (renderScores scores) (for/list ([i (in-range scores)]) (text "1. "))) ; menuKeys ; An ms is a menustate, a key is a keyboard input ; menustate -> menustate ; calls the functions specified by key presses (define (menuSelections ms key) (cond [(string=? key " ") (main start)] [(string=? key "ESC") (quit)] [else ms])) ; menuClicks ; An ms is a menustate ; menustate -> menustate ; calls the functions specified by the buttons (define (menuSelections ms) (cond [(= (mouse-x)) (main start)] [(string=? key "ESC") (quit)] [else ms])) ``` ### Functional Functions Render ```racket ; gamestate -> image ; renders the current state of the game (define (render gs) (place-image racman-pic (racman-x (gamestate-racman gs)) (racman-y (gamestate-racman gs)) (renderDots (gamestate-dots gs) playArea))) ; [list-of dots] image -> image ; renders the current dots on background (define (renderDots lod im) (cond [(empty? lod) im] [else (place-image dotPic (posn-x (first lod)) (posn-y (first lod)) (renderDots (rest lod) im))])) ``` Move Functions ```racket ; gamestate -> gamestate ; moves Rac-Man (define (move gs) (make-gamestate (cond [(string=? "up" (racman-nexdir (gamestate-racman gs))) (moveWormUp (gamestate-racman gs))] [(string=? "down" (racman-nexdir (gamestate-racman gs))) (moveWormDown (gamestate-racman gs))] [(string=? "left" (racman-nexdir (gamestate-racman gs))) (moveWormLeft (gamestate-racman gs))] [(string=? "right" (racman-nexdir (gamestate-racman gs))) (moveWormRight (gamestate-racman gs))] [else (gamestate-racman gs)]) (eatDots2 (gamestate-dots gs) (gamestate-racman gs)) (gamestate-speed gs))) ``` ```racket ; NEW eatDots ; lod is a list-of dots, rman is a racman ; [list-of dots] rman -> [list-of dots] ; removes dot from dots if collision with racman (define (eatDots2 lod rman) (for/list ([i lod]) (if (and (< (abs (- (racman-x rman) (posn-x i))) 10) (< (abs (- (racman-y rman) (posn-y i))) 10)) (make-posn (random 800) (random 800)) i))) ``` ```racket ; rman is a racman ; racman -> racman ; moves rac-man up (define (moveWormUp rman) (make-racman (racman-x rman) (- (racman-y rman) 5) "up" (racman-nexdir rman))) ; rman is a racman ; racman -> racman ; moves rac-man down (define (moveWormDown rman) (make-racman (racman-x rman) (+ (racman-y rman) 5) "down" (racman-nexdir rman))) ; rman is a racman ; racman -> racman ; moves rac-man left (define (moveWormLeft rman) (make-racman (- (racman-x rman) 5) (racman-y rman) "left" (racman-nexdir rman))) ; rman is a racman ; racman -> racman ; moves rac-man right (define (moveWormRight rman) (make-racman (+ (racman-x rman) 5) (racman-y rman) "right" (racman-nexdir rman))) ``` Change Direction (on-key function) ```racket ; gs is a gamestate, key is a keyboard input ; gamestate, key -> gamestate ; Changes the next direction of racman (define (changeDir gs key) (make-gamestate (make-racman (racman-x (gamestate-racman gs)) (racman-y (gamestate-racman gs)) (racman-curdir (gamestate-racman gs)) (cond [(string=? key "left") "left"] [(string=? key "right") "right"] [(string=? key "up") "up"] [(string=? key "down") "down"] [else (racman-nexdir (gamestate-racman gs))])) (gamestate-dots gs) (gamestate-speed gs))) ``` ### End of Game Check This function needs to be modified to check for 0 lives left. ```racket ; gs is a gamestate ; gamestate -> boolean ; Checks for collision with the outside walls (define (gameOver? gs) (cond [(<= (racman-y (gamestate-racman gs)) 0) #true] [(>= (racman-y (gamestate-racman gs)) (image-height playArea)) #true] [(<= (racman-x (gamestate-racman gs)) 0) #true] [(>= (racman-x (gamestate-racman gs)) (image-width playArea)) #true] [else #false])) (define (stopScreen gs) (overlay/align "middle" "middle" (text "GAME OVER" 48 "black") (render gs))) ``` ```racket ; gs is a gamestate ; gamestate -> gamestate ; Runs the game (define (main gs) (big-bang gs [on-tick move] [to-draw render] [on-key changeDir] [stop-when gameOver? stopScreen])) ``` Running the program ```racket (define dotList (list (make-posn 200 100) (make-posn 220 100) (make-posn 240 100) (make-posn 260 100) (make-posn 200 120) (make-posn 200 140) (make-posn 200 160) (make-posn 200 180) (make-posn 200 200) (make-posn 220 200) (make-posn 240 200) (make-posn 260 200))) (define start (make-gamestate (make-racman 20 20 "right" "right") dotList 20)) (main start) ; (eatDots2 dotList (make-racman 20 20 "right" "right")) ```

    Import from clipboard

    Paste your markdown or webpage here...

    Advanced permission required

    Your current role can only read. Ask the system administrator to acquire write and comment permission.

    This team is disabled

    Sorry, this team is disabled. You can't edit this note.

    This note is locked

    Sorry, only owner can edit this note.

    Reach the limit

    Sorry, you've reached the max length this note can be.
    Please reduce the content or divide it to more notes, thank you!

    Import from Gist

    Import from Snippet

    or

    Export to Snippet

    Are you sure?

    Do you really want to delete this note?
    All users will lose their connection.

    Create a note from template

    Create a note from template

    Oops...
    This template has been removed or transferred.
    Upgrade
    All
    • All
    • Team
    No template.

    Create a template

    Upgrade

    Delete template

    Do you really want to delete this template?
    Turn this template into a regular note and keep its content, versions, and comments.

    This page need refresh

    You have an incompatible client version.
    Refresh to update.
    New version available!
    See releases notes here
    Refresh to enjoy new features.
    Your user state has changed.
    Refresh to load new user state.

    Sign in

    Forgot password

    or

    By clicking below, you agree to our terms of service.

    Sign in via Facebook Sign in via Twitter Sign in via GitHub Sign in via Dropbox Sign in with Wallet
    Wallet ( )
    Connect another wallet

    New to HackMD? Sign up

    Help

    • English
    • 中文
    • Français
    • Deutsch
    • 日本語
    • Español
    • Català
    • Ελληνικά
    • Português
    • italiano
    • Türkçe
    • Русский
    • Nederlands
    • hrvatski jezik
    • język polski
    • Українська
    • हिन्दी
    • svenska
    • Esperanto
    • dansk

    Documents

    Help & Tutorial

    How to use Book mode

    Slide Example

    API Docs

    Edit in VSCode

    Install browser extension

    Contacts

    Feedback

    Discord

    Send us email

    Resources

    Releases

    Pricing

    Blog

    Policy

    Terms

    Privacy

    Cheatsheet

    Syntax Example Reference
    # Header Header 基本排版
    - Unordered List
    • Unordered List
    1. Ordered List
    1. Ordered List
    - [ ] Todo List
    • Todo List
    > Blockquote
    Blockquote
    **Bold font** Bold font
    *Italics font* Italics font
    ~~Strikethrough~~ Strikethrough
    19^th^ 19th
    H~2~O H2O
    ++Inserted text++ Inserted text
    ==Marked text== Marked text
    [link text](https:// "title") Link
    ![image alt](https:// "title") Image
    `Code` Code 在筆記中貼入程式碼
    ```javascript
    var i = 0;
    ```
    var i = 0;
    :smile: :smile: Emoji list
    {%youtube youtube_id %} Externals
    $L^aT_eX$ LaTeX
    :::info
    This is a alert area.
    :::

    This is a alert area.

    Versions and GitHub Sync
    Get Full History Access

    • Edit version name
    • Delete

    revision author avatar     named on  

    More Less

    Note content is identical to the latest version.
    Compare
      Choose a version
      No search result
      Version not found
    Sign in to link this note to GitHub
    Learn more
    This note is not linked with GitHub
     

    Feedback

    Submission failed, please try again

    Thanks for your support.

    On a scale of 0-10, how likely is it that you would recommend HackMD to your friends, family or business associates?

    Please give us some advice and help us improve HackMD.

     

    Thanks for your feedback

    Remove version name

    Do you want to remove this version name and description?

    Transfer ownership

    Transfer to
      Warning: is a public team. If you transfer note to this team, everyone on the web can find and read this note.

        Link with GitHub

        Please authorize HackMD on GitHub
        • Please sign in to GitHub and install the HackMD app on your GitHub repo.
        • HackMD links with GitHub through a GitHub App. You can choose which repo to install our App.
        Learn more  Sign in to GitHub

        Push the note to GitHub Push to GitHub Pull a file from GitHub

          Authorize again
         

        Choose which file to push to

        Select repo
        Refresh Authorize more repos
        Select branch
        Select file
        Select branch
        Choose version(s) to push
        • Save a new version and push
        • Choose from existing versions
        Include title and tags
        Available push count

        Pull from GitHub

         
        File from GitHub
        File from HackMD

        GitHub Link Settings

        File linked

        Linked by
        File path
        Last synced branch
        Available push count

        Danger Zone

        Unlink
        You will no longer receive notification when GitHub file changes after unlink.

        Syncing

        Push failed

        Push successfully