From d3a0cc3a8ba6dfeb64d3faeffdeb6845b60e5840 Mon Sep 17 00:00:00 2001 From: Yuchen Pei Date: Sat, 20 Jan 2018 15:41:49 +0100 Subject: rearranged the dir for github - removed tools and pdfs - rearranged the projects dirs - added md files - other minor changes --- projects/11/Pong/Bat.jack | 103 ---------------------------------------------- 1 file changed, 103 deletions(-) delete mode 100644 projects/11/Pong/Bat.jack (limited to 'projects/11/Pong/Bat.jack') diff --git a/projects/11/Pong/Bat.jack b/projects/11/Pong/Bat.jack deleted file mode 100644 index 340760f..0000000 --- a/projects/11/Pong/Bat.jack +++ /dev/null @@ -1,103 +0,0 @@ -// This file is part of www.nand2tetris.org -// and the book "The Elements of Computing Systems" -// by Nisan and Schocken, MIT Press. -// File name: projects/11/Pong/Bat.jack - -/** - * A graphical Pong bat. - * Displayed as a filled horizontal rectangle that has - * a screen location, a width and a height. - * Has methods for drawing, erasing, moving left and right, - * and changing its width (to make the hitting action more challenging). - * This class should have been called "paddle", following the - * standard Pong terminology. But, unaware of this terminology, - * we called it "bat", and then decided to stick to it. - */ -class Bat { - - field int x, y; // the bat's screen location - field int width, height; // the bat's width and height - field int direction; // direction of the bat's movement (1 = left, 2 = right) - - /** Constructs a new bat with the given location and width. */ - constructor Bat new(int Ax, int Ay, int Awidth, int Aheight) { - let x = Ax; - let y = Ay; - let width = Awidth; - let height = Aheight; - let direction = 2; - do show(); - return this; - } - - /** Deallocates the object's memory. */ - method void dispose() { - do Memory.deAlloc(this); - return; - } - - /** Shows the bat. */ - method void show() { - do Screen.setColor(true); - do draw(); - return; - } - - /** Hides the bat. */ - method void hide() { - do Screen.setColor(false); - do draw(); - return; - } - - /** Draws the bat. */ - method void draw() { - do Screen.drawRectangle(x, y, x + width, y + height); - return; - } - - /** Sets the bat's direction (0=stop, 1=left, 2=right). */ - method void setDirection(int Adirection) { - let direction = Adirection; - return; - } - - /** Returns the bat's left edge. */ - method int getLeft() { - return x; - } - - /** Returns the bat's right edge. */ - method int getRight() { - return x + width; - } - - /** Sets the bat's width. */ - method void setWidth(int Awidth) { - do hide(); - let width = Awidth; - do show(); - return; - } - - /** Moves the bat one step in the bat's direction. */ - method void move() { - if (direction = 1) { - let x = x - 4; - if (x < 0) { let x = 0; } - do Screen.setColor(false); - do Screen.drawRectangle((x + width) + 1, y, (x + width) + 4, y + height); - do Screen.setColor(true); - do Screen.drawRectangle(x, y, x + 3, y + height); - } - else { - let x = x + 4; - if ((x + width) > 511) { let x = 511 - width; } - do Screen.setColor(false); - do Screen.drawRectangle(x - 4, y, x - 1, y + height); - do Screen.setColor(true); - do Screen.drawRectangle((x + width) - 3, y, x + width, y + height); - } - return; - } -} -- cgit v1.2.3