/// <summary> /// Method moves snake's head and tail if needed. it also put a new food if it was eaten /// </summary> /// <param name="snake">snake to be moves</param> /// <param name="dir">direction that snake should follow</param> /// <param name="im">array of images for the snake</param> private void makemove(Snake snake, int dir, Image[] im) { Coordinates c = snake.moveHead(dir); if (c.inRange()) { //doesn't allow outofboundsexception if (picb[c.getX(), c.getY()].Image == null) { //if head ocupies empty cell, then move tail setHeadLabel(snake.getHead().getBone(), im); setBoneLabel(snake.getHead().getNext().getBone(), im); c = snake.moveTail(); picb[c.getX(), c.getY()].Image = null; if (snake.getHead() != snake.getTail()) { setTailLabel(snake.getTail().getBone(), im); } } else if (picb[c.getX(), c.getY()].Image == images[10]) {// if head occupies cell with food, then tail should not be moved to inctease snake's length. put new food setHeadLabel(snake.getHead().getBone(), im); if (points == 0) { setTailLabel(snake.getTail().getBone(), im); } else { setBoneLabel(snake.getHead().getNext().getBone(), im); } points++; if (iftwo) { label3.Text = "Yellow " + (this.snake.getLength() - 1).ToString() + ":" + (this.snake2.getLength() - 1).ToString() + " Red"; } else { label3.Text = points.ToString(); } if (sound != null) { sound.Play(); } putFood(); switch (points) { case 5: step.Interval = 400; break; case 10: step.Interval = 350; break; case 20: step.Interval = 300; break; case 40: step.Interval = 250; break; case 66: step.Interval = 200; break; case 88: step.Interval = 100; break; } } // snake pumps into a rock else if ((picb[c.getX(), c.getY()].Image == rock)) { gameOver("OUPS! One silly snake but bumped into the rock! Do you want to try with another one? Otherwise you return to menu."); } // snake eats itself else { gameOver("OUPS! One snake is not in mood today. It tries to bite itself or others. Do you want to try with another one? Otherwise you return to menu."); } } // snake bumps into the wall else { gameOver("OUPS! One cunning snake tryed to escape, but bumped into the wall! Do you want to try with another one? Otherwise you return to menu."); } }
/// <summary> /// Method to check if two objects of Coordinates class point to the same position, i.e. has the same coordinates /// </summary> /// <param name="c">Coordinates object for comparison</param> /// <returns>true if objects points to the same coordinates</returns> public Boolean equal(Coordinates c) { return(c.getX() == x && c.getY() == y); }