public God() { life = 5; score = 0; isCrash = false; isTurn = false; MainMatrix = new nodeM[Constants.MAT_W, Constants.MAT_H]; for (int ii = 0; ii < Constants.MAT_W; ii++) { for (int jj = 0; jj < Constants.MAT_H; jj++) { MainMatrix[ii, jj] = new nodeM(); } } Snakes = new snake[Constants.NUM_SNAKES]; for (int ii = 0; ii < Constants.NUM_SNAKES; ii++) { Snakes[ii] = new snake(); Snakes[ii].id = ii; } snakeBool = new int[Constants.NUM_SNAKES]; for (int ii = 0; ii < Constants.NUM_SNAKES; ii++) { snakeBool[ii] = 0; } }
void tailHandle() { snake temp = tail; tail = tail.getNext(); temp.removeTail(); }
void Start() { s = snake.GetComponent <snake> (); spawned_points = new List <Vector2>(); add_food(); }
//Attaches body part to head public void attachSnakeHead() { GameObject body = new GameObject("snake1", typeof(SpriteRenderer)); body.GetComponent <SpriteRenderer>().sprite = GameAssets.i.snake; snake tempSnake; //Set to one space before snake head if (arrowDirection == 1) { tempSnake = new snake(gridPosition.x, gridPosition.y - 5, arrowDirection); } else if (arrowDirection == 2) { tempSnake = new snake(gridPosition.x, gridPosition.y + 5, arrowDirection); } else if (arrowDirection == 3) { tempSnake = new snake(gridPosition.x + 5, gridPosition.y, arrowDirection); } else if (arrowDirection == 4) { tempSnake = new snake(gridPosition.x - 5, gridPosition.y, arrowDirection); } else { tempSnake = null; } snake.Add(body); snakePos.Add(tempSnake); body.transform.position = new Vector3Int(tempSnake.gridPosition.x, tempSnake.gridPosition.y, 0); }
void TailFunction() { snake tempSnake = tail; tail = tail.Getnext(); tempSnake.RemoveTail(); }
//Attaches body part to another body part public void attachSnakeBody() { GameObject body = new GameObject("snake" + (snake.Count + 1), typeof(SpriteRenderer)); body.GetComponent <SpriteRenderer>().sprite = GameAssets.i.snake; snake tempSnake; //Set to one space before snake head if (((snake)snakePos[snakePos.Count - 1]).direction == 1) { tempSnake = new snake(((snake)snakePos[snakePos.Count - 1]).gridPosition.x, ((snake)snakePos[snakePos.Count - 1]).gridPosition.y - 5, 1); } else if (((snake)snakePos[snakePos.Count - 1]).direction == 2) { tempSnake = new snake(((snake)snakePos[snakePos.Count - 1]).gridPosition.x, ((snake)snakePos[snakePos.Count - 1]).gridPosition.y + 5, 2); } else if (((snake)snakePos[snakePos.Count - 1]).direction == 3) { tempSnake = new snake(((snake)snakePos[snakePos.Count - 1]).gridPosition.x + 5, ((snake)snakePos[snakePos.Count - 1]).gridPosition.y, 3); } else if (((snake)snakePos[snakePos.Count - 1]).direction == 4) { tempSnake = new snake(((snake)snakePos[snakePos.Count - 1]).gridPosition.x - 5, ((snake)snakePos[snakePos.Count - 1]).gridPosition.y, 4); } else { tempSnake = null; } snake.Add(body); snakePos.Add(tempSnake); body.transform.position = new Vector3Int(tempSnake.gridPosition.x, tempSnake.gridPosition.y, 0); }
void movment() { GameObject temp; nextPos = head.transform.position; switch (direction) { case 0: nextPos = new Vector2(nextPos.x, nextPos.y + 0.6f); break; case 1: nextPos = new Vector2(nextPos.x + 0.6f, nextPos.y); break; case 2: nextPos = new Vector2(nextPos.x, nextPos.y - 0.6f); break; case 3: nextPos = new Vector2(nextPos.x - 0.6f, nextPos.y); break; default: break; } temp = (GameObject)Instantiate(snakePrefab, nextPos, transform.rotation); head.setNext(temp.GetComponent <snake>()); head = temp.GetComponent <snake>(); }
private void spawnSnakes() { for (int i = 0; i < 5; i++) { int x = r.Next(this.Width - 100); int y = r.Next(this.Height - 100); snake etemp = new snake(x, y); enemies.Add(etemp); this.Refresh(); } }
void Start() { all_count = 0; game_man = game_manager.GetComponent <game_manager> (); M_camera = GameObject.FindWithTag("MainCamera"); // get the snake class to cll add function when the snake eat fruit snake_cla = snake.GetComponent <snake> (); // spawn a new fruit after eating the last one game_man.spawn_fruit(); }
public Form1() { InitializeComponent(); setLayer(); scoreBox = new Rectangle(this.Width - 100, 0, 150, 60); player = new snake(); enemies = new List <snake>(); foods = new List <food>(); this.MouseMove += Form1_MouseMove; this.Paint += Form1_Paint; tuniversal.Tick += Tuniversal_Tick; spawnFood(); spawnSnakes(); tuniversal.Start(); }
void Movement() { GameObject temp; nextPos = head.transform.position; switch (NESW) { case 0: nextPos = new Vector3(nextPos.x, nextPos.y + 0.5f, nextPos.z); break; case 1: nextPos = new Vector3(nextPos.x + 0.5f, nextPos.y, nextPos.z); break; case 2: nextPos = new Vector3(nextPos.x, nextPos.y - 0.5f, nextPos.z); break; case 3: nextPos = new Vector3(nextPos.x - 0.5f, nextPos.y, nextPos.z); break; } temp = (GameObject)Instantiate(snakePrefab, nextPos, transform.rotation); head.Setnext(temp.GetComponent <snake>()); head = temp.GetComponent <snake>(); return; }
public void Setnext(snake IN) { next = IN; }
void Start(){ s = snake.GetComponent<snake> (); }
//Исследуемый граф //Функция поиска кратчайшего пути, возвращает грани, которые можно вывести на экран static List<Connection> get_path( Connection _start_end, //Начальная и конечная точки Graph _g) { //Список вершин графа со стоимостью List<S_point> ch_pnts = new List<S_point>(); foreach (S_point p in _g.Nodes) ch_pnts.Add(new S_point(p.pnt,0,p.name)); List<Connection> result = new List<Connection>(); double fin_cost = 0; //Сформируем начальный путь snake first = new snake(get_pathes(_start_end.p1, _g.Lines), 0); first.head = _start_end.p1; List<snake> snakes = new List<snake>(); snakes.Add(first); /* * Цикл формирует все возможные пути. Когда будет найден первый путь до конечной точки, будет назначена цена пути. * Оставшиеся пути будут продолжать формироваться до тех пор, пока стоимость каждого из них не превысит * стоимость уже найденного пути. */ do { int i = snakes.Count-1; if (snakes.Count > 0) do { int j = snakes[i].pathes.Count-1; if (snakes[i].pathes.Count>0) do { Point cur_pnt = new Point(); double tmp_cost = snakes[i].cost + snakes[i].pathes[j].cost; if (snakes[i].pathes[j].p1 == snakes[i].head) cur_pnt = snakes[i].pathes[j].p2; else cur_pnt = snakes[i].pathes[j].p1; if ((get_s_point(cur_pnt, ch_pnts).cost > tmp_cost || get_s_point(cur_pnt, ch_pnts).cost == 0) && (tmp_cost<fin_cost || fin_cost==0)) { if (cur_pnt == _start_end.p2 && (fin_cost > tmp_cost || fin_cost==0)) { fin_cost = tmp_cost; result = snakes[i].body; result.Add(snakes[i].pathes[j]); } else if (cur_pnt != snakes[i].neck) { snake tmp_snake = new snake(get_pathes(cur_pnt, _g.Lines), tmp_cost); foreach (Connection c in snakes[i].body) tmp_snake.body.Add(c); tmp_snake.body.Add(snakes[i].pathes[j]); tmp_snake.neck = snakes[i].head; tmp_snake.head = cur_pnt; set_s_point_cost(cur_pnt, tmp_cost, ch_pnts); snakes.Add(tmp_snake); } } snakes[i].pathes.RemoveAt(j); j--; } while(j>=0); snakes.RemoveAt(i); i--; } while(i>=0); } while (snakes.Count!=0); return result; }
void Start() { s = snake.GetComponent <snake> (); f = food.GetComponent <food> (); gm = game_manager.GetComponent <game_manager> (); }
public void setNext(snake here) { next = here; }