Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added to count Yummys and display it on title bar and set setResizable to false #9

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions src/ThreadsController.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,19 @@ public class ThreadsController extends Thread {
Tuple headSnakePos;
int sizeSnake=3;
long speed = 50;
int points = 0;
Window frame;
public static int directionSnake ;

ArrayList<Tuple> positions = new ArrayList<Tuple>();
Tuple foodPosition;

//Constructor of ControlleurThread
ThreadsController(Tuple positionDepart){
ThreadsController(Tuple positionDepart,Window parmFrame){
//Get all the threads
Squares=Window.Grid;

frame = parmFrame;

headSnakePos=new Tuple(positionDepart.x,positionDepart.y);
directionSnake = 1;

Expand All @@ -31,6 +34,7 @@ public class ThreadsController extends Thread {

//Important part :
public void run() {

while(true){
moveInterne(directionSnake);
checkCollision();
Expand Down Expand Up @@ -61,7 +65,8 @@ private void checkCollision() {

boolean eatingFood = posCritique.getX()==foodPosition.y && posCritique.getY()==foodPosition.x;
if(eatingFood){
System.out.println("Yummy!");
frame.setpoints(++points);
System.out.println("Yummy!");
sizeSnake=sizeSnake+1;
foodPosition = getValAleaNotInSnake();

Expand Down
11 changes: 8 additions & 3 deletions src/Window.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class Window extends JFrame{
public static int height = 20;
public Window(){


this.setResizable(false);
// Creates the arraylist that'll contain the threads
Grid = new ArrayList<ArrayList<DataOfSquare>>();
ArrayList<DataOfSquare> data;
Expand Down Expand Up @@ -40,7 +40,7 @@ public Window(){
// initial position of the snake
Tuple position = new Tuple(10,10);
// passing this value to the controller
ThreadsController c = new ThreadsController(position);
ThreadsController c = new ThreadsController(position,this);
//Let's start the game now..
c.start();

Expand All @@ -52,6 +52,11 @@ public Window(){
//Tuple position2 = new Tuple(13,13);
//ControlleurThreads c2 = new ControlleurThreads(position2);
//c2.start();

}

public void setpoints(int points) {
setTitle("Snake [Points: " + points + " ]");
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just an aesthetics thing; wouldn't score instead of points be a nicer display name?

}

}