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: 1 year ago

Preview 1 out of 2 pages

Reviews( 0 )

$5.50

Add to cart

Instant download

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

OR

GET ASSIGNMENT HELP
51
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 4 years

1086 Documents Sold


Additional information

This document has been written for:

Uploaded

Mar 20, 2021

Downloads

 0

Views

 51

Document Keyword Tags

Recommended For You

What is Browsegrades

In Browsegrades, 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 © Browsegrades · High quality services·