public static Board_Element get_Free_Point() { Board_Element result = new Board_Element(); bool b = false; for (var index = 0; index < points_Count * 10; index++) { result = Board.Matrix[MyFunctions.get_Random_Int(0, x_Length - 1), MyFunctions.get_Random_Int(0, y_Length - 1)]; if (result.MyValue == MyValueType.free) { if (check_if_one_of_neighbors_if_free(result.Point.x, result.Point.y)) { b = true; break; } } } if (!b) { BGSnakeCJsInterop.Alert("Can't find free point!!!"); } return(result); }
public static void paint_Random_Target() { Board_Element free_Board_Element = get_Free_Point(); Board.Matrix[free_Board_Element.Point.x, free_Board_Element.Point.y].MyValue = MyValueType.target; target_position = new MyPoint(free_Board_Element.Point.x, free_Board_Element.Point.y); }
public static void initialize_Matrix() { Matrix = new Board_Element[Game.x_Length, Game.y_Length]; for (var index_x = 0; index_x < Game.x_Length; index_x++) { for (var index_y = 0; index_y < Game.y_Length; index_y++) { Matrix[index_x, index_y] = new Board_Element() { Point = new MyPoint(index_x, index_y), MyValue = MyValueType.free }; } } }
public static void reset() { Is_Enabled = false; Is_Started = false; Right_Path = new List <MyPoint>(); Board.initialize_Matrix(); Board.generate_walls(); paint_Random_Target(); paint_Score(); LocalData.Curr_Direction = DirectionType.empty; SnakeElements = new List <Snake_Element>(); Board_Element Free_Board_Element = get_Free_Point(); Board.Matrix[Free_Board_Element.Point.x, Free_Board_Element.Point.y].MyValue = MyValueType.snake; SnakeElements.Add(new Snake_Element { Point = new MyPoint(Free_Board_Element.Point.x, Free_Board_Element.Point.y), Is_Main = true }); if (Is_Bot_Mode) { Find_Right_Path(); } Is_Enabled = true; if (Is_Bot_Mode) { start(); } }