Really confused on how to even begin this. Reply with your price please.
In the grid game you create, the screen is divided into a grid of squares, each 20 × 20 pixels. The player (I will use a ladybug here as an example, but you can re-theme the game as you like) wanders around the grid collecting good things while avoiding the bad ones. If the ladybug moves onto a bad thing or off the screen, then the player loses. After collecting 5 good things, the player wins.
The game starts when the mouse is pressed: your setUp() method can call noLoop() and you can write a mousePressed() function that calls loop() to start the game. At every point in time, the ladybug has a current direction (up, down, left, right) and moves one square in that direction every 1/3 second or so. (You can change the timing to make a more interesting game, but make sure it is easy to test). The current direction is changed by the arrow keys. Perhaps the best way to do is to check frameCount % 20 and only re-draw the screen if this is 0 (or perhaps 19, so that the ladybug doesn’t move right away). When the ladybug moves onto a square with a ”good thing” the score is increased and the ”good thing” teleports to a new square (Don’t worry if the good thing occasionally teleports onto the After collecting 5 good things (or perhaps 10 if they are worth varying amounts of points) the game ends with a “congratulation, you won!” message. If the ladybug ever moves off the screen on onto a bad thing, the game ends with a “You lost” message.
The version you turn in should be reasonable small, say 10 squares by 10 squares (200x200 pixels). You should have about 10 bad things to run into, and their positions should be stored in an array.
Program Specifications
Your program must have a GridPos class. The provided sample will get you started, but you will have to add methods to the class. See the comments in the provided sample.
The x and y instance variables should not be used directly outside of the class. Feel free to structure your program with additional classes.
Grading: 10 pts total Required (0-8 pts)
• (1 pt) following submission guidelines and pair programming log 1
• (2 pts) following the program style handout, this includes: a block comment at the beginning with program description and authors, user instructions, and acknowledging any extra help; good indentation; descriptive variable names in camelCase: overall code organization and blank lines to separate different code chunks; and helpful comments indicating what each chunk is doing.
• (3 pts) for completing and properly using the GridPos class, and using an array to hold the bad things.
• (1 pt) for only accessing the GridPos instance variables within the GridPos class. You may use functions like verb+myPos.getX()+ that return the x-value of a GridPos object myPos.
• (1 pt) for making sure good things don’t teleport onto either the ladybug or the bad things (use a while loop as indicated in the hints below).
Optional parts (at most 2 optional points total)
• (1pt)forcreatingandusingaLadybugclass(orwhateveris appropriateforyourtheme) that uses instance variables to keep track of the ladybug’s position and direction, and contains the method for printing the ladybug.
• (1 pt) if the ladybug faces or points towards the direction it is moving.
• (1 pt) for creating another helpful class for the program (perhaps good things and/or
bad things).
• (1 pt) for having the good/bad things have different positive and negative values and adjusting the score appropriately. In this case the player loses if their score drops below zero.
• (1 pt) grader discretionary for an interesting/pleasing/fun sketch.
This is what I have so far:
class GridPos { static final int GRIDSIZE = 20; int x; int y; GridPos (int initX, int initY) { x = initX; y = initY; } public String toString() { return ( "(" + x + ", " + y + ")" ); } void setTo (int xval, int yval) { x = xval; y = yval; } boolean equals (GridPos p) { return (this.x == p.x && this.y == p.y); } boolean onScreen() { return (x >= 0 && y >= 0 && x*GRIDSIZE < width && y*GRIDSIZE < height); } void paint (color c) { rectMode(CORNER); stroke(255); fill(c); rect(x*GRIDSIZE, y*GRIDSIZE, GRIDSIZE, GRIDSIZE); } } GridPos myPos = new GridPos(0,0); void setup() { size(200,200); println("in setup"); println("the new GridPos is: " + myPos); myPos.setTo(1,1); println("myPos now is; " + myPos); } void draw() { println("Now in draw()"); myPos.paint( color(0,0,255) ); GridPos yourPos = new GridPos(1,1); GridPos theirPos = yourPos; if (theirPos == yourPos) { println("TheirPos and yourPos are the same object"); } if ( myPos.equals(yourPos) ) { println("myPos is:" + myPos + " and yourPos is:" + yourPos); println(" myPos and yourPos have the same values"); } if (myPos == yourPos) { println("this if is false -- myPos and yourPos refer to different objects"); } GridPos[] manyPos = new GridPos[5]; for (int i=0; i < manyPos.length; i++) { println("manyPos[" +i+ "] is: " + manyPos[i]); } for (int i=0; i< manyPos.length; i++) { manyPos[i] = new GridPos(i,i); } for (int i=0; i < manyPos.length; i++) { println("now manyPos[" +i+ "] is: " + manyPos[i]); } for (int i=0; i < manyPos.length; i++) { manyPos[i].paint( color(255,0,0) ); } noLoop(); }