Religious Studies > SOPHIA Milestone > College of William & Mary - CS 1114 Food.java. (All)

College of William & Mary - CS 1114 Food.java.

Document Content and Description Below

import sofia.micro.*; import sofia.util.Random; */ public class Food extends SimpleActor { //~ Constructor ........................................................... // ------------------------... ---------------------------------- /** * Creates a new Food object. */ public Food() { super(); } //~ Methods ............................................................... // ---------------------------------------------------------- /** * Take one step, either forward or after turning left or right. */ public void act() { int random = Random.generator().nextInt(4); if (random == 0) { turn(LEFT); } else if (random == 1) { turn(RIGHT); } // stops the food from going outside the world. avoidEdges(); // is so the food can move around within the world. if ((this.getGridX() != 0) || (this.getGridY() != 0) && this.getGridX() != 11 || this.getGridY() != 11) { move(); } } /** * checks that the food doesn't go outside the world. */ public void avoidEdges() { while (this.getGridX() == 0 && (getDirection() == WEST) || this.getGridY() == 0 && (getDirection() == NORTH) || this.getGridX() == 11 && (getDirection() == EAST) || this.getGridY() == 11 && (getDirection() == SOUTH)) { https://www.coursehero.com/file/57230390/Foodjava/ This study resource was shared via CourseHero.comturn(RIGHT); [Show More]

Last updated: 2 years ago

Preview 1 out of 2 pages

Buy Now

Instant download

We Accept:

We Accept
document-preview

Buy this document to get the full access instantly

Instant Download Access after purchase

Buy Now

Instant download

We Accept:

We Accept

Reviews( 0 )

$5.50

Buy Now

We Accept:

We Accept

Instant download

Can't find what you want? Try our AI powered Search

102
0

Document information


Connected school, study & course


About the document


Uploaded On

Mar 20, 2021

Number of pages

2

Written in

Seller


seller-icon
QuizMaster

Member since 5 years

1184 Documents Sold

Reviews Received
185
56
29
11
17
Additional information

This document has been written for:

Uploaded

Mar 20, 2021

Downloads

 0

Views

 102

Document Keyword Tags


$5.50
What is Scholarfriends

In Scholarfriends, a student can earn by offering help to other student. Students can help other students with materials by upploading their notes and earn money.

We are here to help

We're available through e-mail, Twitter, Facebook, and live chat.
 FAQ
 Questions? Leave a message!

Follow us on
 Twitter

Copyright © Scholarfriends · High quality services·