public void reset() { List <int[]> part = sn.getPart(); int size = part.Count; for (int i = 1; i < size; i++) { matrix[part[i][1], part[i][0]] = 0; } sn = null; small = null; big = null; timeToSnakeGrow = 0; count = 0; bigTime = 0; GameOver = false; }
public void addSnake(UserSnake n) { n.fx = x; n.fy = y; n.setDir(direction); List <int[]> part = n.getPart(); int size = part.Count; int a, b; switch (direction) { case Snake.DOWN: a = 0; b = -1; break; case Snake.UP: a = 0; b = 1; break; case Snake.RIGHT: a = -1; b = 0; break; default: a = 1; b = 0; break; } for (int i = 0; i < size; i++) { part[i][0] = x + a * i; part[i][1] = y + b * i; matrix[part[i][1], part[i][0]] = 2; } n.lx = part[size - 1][0]; n.ly = part[size - 1][1]; sn = n; }
//lam gi khi co phim nhap vao private bool reactKey() { if (key == '\0') { return(false); } UserSnake n = canvas.getSnake; int dir = n.getDir; switch (key) { //di len case Game.UP_KEY: if (st == Game.PLAY && dir != Snake.UP && dir != Snake.DOWN) { n.setDir(Snake.UP); } break; //di xuong case Game.DOWN_KEY: if (st == Game.PLAY && dir != Snake.UP && dir != Snake.DOWN) { n.setDir(Snake.DOWN); } break; //qua trai case Game.LEFT_KEY: if (st == Game.PLAY && dir != Snake.RIGHT && dir != Snake.LEFT) { n.setDir(Snake.LEFT); } break; //qua phai case Game.RIGHT_KEY: if (st == Game.PLAY && dir != Snake.RIGHT && dir != Snake.LEFT) { n.setDir(Snake.RIGHT); } break; case Game.ZERO_KEY: if (st == Game.G_OVER) //choi lai { reset(); workFirst(); } else if (st == Game.PAUSE) //tiep tuc { if (canvas.isGameOver) { st = Game.G_OVER; cpu.addInfomation(InfoTable.TYPE.STATE, Game.G_OVER_DESCRIPTION, ConsoleColor.Red); } else { st = Game.PLAY; cpu.addInfomation(InfoTable.TYPE.STATE, Game.PLAY_DESCRIPTION, ConsoleColor.Magenta); } } else if (st == Game.PLAY) //tam ngung { st = Game.PAUSE; cpu.addInfomation(InfoTable.TYPE.STATE, Game.PAUSE_DESCRIPTION, ConsoleColor.Magenta); } break; case Game.BACK_KEY: //Mo bang option Poster p = new Poster(cpu.blankPoster); Option ntf = new Option(p, cpu, "Option"); cpu.pushStack(ntf); cpu.topOfStackWork(); key = '\0'; return(true); case Game.REFRESH_KEY: //ve lai toan bo game cpu.drawInfoFrame(); drawAll(); break; } key = '\0'; return(false); }