December 5, 2014
Battleship is a game that let player guess the position of enemies's battleships. Player guess first then computer will guess player's battleships position and again and again until all the available ships down on either side.
- let*: each button and computer attack will be using this: .
- Data get set: these are the modifiers.
- list, car, cdr: these happens when data are being modifying or the debug code.
- Recursion or tail-recursion: both are used for main code like buttons to run.
External Technology and Libraries
We have used The Racket Graphical Interface Toolkit (http://docs.racket-lang.org/gui/index.html) library.
Favorite Lines of Code
Each partner should identify a favorite line of code, Scheme expression, or entire procedure written by himself / herself in the entire project, and explain what it does. E.g.:
- Takyiu Lo:
;; who wins (define (playerWins) (new message% [label "YOU WIN"] [parent frame]) #t) (define (computerWins) (new message% [label "YOU LOSE"] [parent frame]) #t) (define (whoWins) (if (> numOfShipsForPlayer numOfShipsForComputer) (playerWins) (computerWins))) (define (checkGameover) (if (or (= 0 numOfShipsForComputer) (= 0 numOfShipsForPlayer)) (whoWins);(display "gameover") #f))
This determine if the game is over yet, and if it is over then who wins and send the message to the frame. Simply, we could modify this code to add more animation to frame at here.
- Mihir Patel:
(define button1 (new button% (parent panelh1) (label " ") [callback (lambda (button event) (let* ((y 0) (x 0) (z (grid-get! y x playerStepsGrid))) (if (or (eq? 'x z) (= 1 z)) (displayln " error: you already clicked this") (if (eq? 1 (grid-get! y x computerBSgrid)) (hb1 y x) (hbx1 y x)))) )]))
The button that can start everything. When a use clicked, everything like checking, modifying data, and computer attacks will start.
Technology Used Block Diagram
There are not much GUI going on.
Since the label of each button are bitmap, we can actually use pictures to represent steps and hit.
To modify each button, we created a .c file so that it won't be tedious.