Welcome, Guest: Register On Nairaland / LOGIN! / Trending / Recent / New
Stats: 3,152,735 members, 7,817,019 topics. Date: Friday, 03 May 2024 at 11:12 PM

Resolved already - Programming - Nairaland

Nairaland Forum / Science/Technology / Programming / Resolved already (287 Views)

Resolved already / Backend Developer Needed For A Quick Job (Resolved) / resolved (2) (3) (4)

(1) (Reply) (Go Down)

Resolved already by Etinosa1234: 12:57pm On Sep 15, 2020
Its an online course I've been following and the topic is what I'm supposed to do

But I've been trying my best and its not working

I was told to set the snake direction to be equal to snake direction to SnakeDirection.down
The code:
public class Room {
//creating description for the snake and room
private int width;
private int height;
private static Snake snake;
private Mouse mouse;
public static Room game;

public int getWidth(){
return width;
}
public int getHeight(){
return height;
}
public Snake getSnake(){
return snake;
}
public Mouse getMouse(){
return mouse;
}

public void setWidth(int width){
this.width = width;
}
public void setHeight(int height){
this.height = height;
}
public void setSnake(Snake snake){
this.snake = snake;
}
public void setMouse(Mouse mouse){
this.mouse = mouse;
}

public Room(int width,int height, Snake snake){
this.width = width;
this.height = height;
this.snake = snake;
}
public void run(){

}
public void print(){

}
public static void main(String[] args) {
Snake snakes = new Snake(0,0);
game = new Room(10,10,snake);
snakes.setDirection(DOWN); //setting the direction of the snake

}
}
Re: Resolved already by Nobody: 1:08pm On Sep 15, 2020
Where is the definition for the snake object, by the way you should have just dumped a screenshot of your laptop or something.
Re: Resolved already by Etinosa1234: 1:26pm On Sep 15, 2020
SegFault:
Where is the definition for the snake object, by the way you should have just dumped a screenshot of your laptop or something.

I'll try and copy it... Screenshotting it won't cover the pagw
Re: Resolved already by Etinosa1234: 1:27pm On Sep 15, 2020
The snake class

public class Snake {
private List<SnakeSection> sections;
private boolean isAlive;
private SnakeDirection direction;
private int x;
private int y;

public Snake(int x, int y){
//creating first piece and add it to the sections list
sections = new ArrayList<SnakeSection>();
isAlive = true;
sections.add(new SnakeSection(x,y));
}

public List<SnakeSection> getSections(){
return sections;
}
public boolean isAlive(){
return isAlive;
}
public SnakeDirection getDirection(){
return direction;
}
public void setDirection(SnakeDirection direction){
this.direction = direction;
}
// create and implement the method. The method should return the x or y-coordinate of the snake's head.
public int getX(){
return sections.get(0).getX();
}
public int getY(){
return sections.get(0).getY();
}
public void move(){

}
}
Re: Resolved already by Nobody: 1:28pm On Sep 15, 2020
Etinosa1234:


I'll try and copy it... Screenshotting it won't cover the pagw
Okay, dump the error here too.
Re: Resolved already by Etinosa1234: 1:28pm On Sep 15, 2020
The snake direction enum

public enum SnakeDirection {
UP,
DOWN,
LEFT,
RIGHT
}

Segfault
Re: Resolved already by Etinosa1234: 1:33pm On Sep 15, 2020
The requirements is to set the snakes direction to be equal to SnakeDirection.DOWN

(1) (Reply)

Linux Installment / Students Portal On Plain PHP Project / Pls I Need A Tutor In Backend Dev.i Don't Know D Use Case Scenario. Getting Disc

(Go Up)

Sections: politics (1) business autos (1) jobs (1) career education (1) romance computers phones travel sports fashion health
religion celebs tv-movies music-radio literature webmasters programming techmarket

Links: (1) (2) (3) (4) (5) (6) (7) (8) (9) (10)

Nairaland - Copyright © 2005 - 2024 Oluwaseun Osewa. All rights reserved. See How To Advertise. 17
Disclaimer: Every Nairaland member is solely responsible for anything that he/she posts or uploads on Nairaland.