public void OnEnable() { //Przypisanie własności do zmiennych mNormalSquare = (NormalSquare)target; value = serializedObject.FindProperty("value"); type = serializedObject.FindProperty("Type"); isDestructable = serializedObject.FindProperty("IsDestructable"); }
/// <summary> /// Wykonuje się gdy wejdziemy na finishowy kwadrat /// </summary> public void StepOnFinishSquare(NormalSquare finishSquare) { //Nasz kwadrat i finishowy mają tą samą wartość if (this.value == finishSquare.value) { int finishSquareCount = 0; foreach (var square in Game.Squares) { if (square is NormalSquare && (square as NormalSquare).Type == SquareType.Finish) { finishSquareCount++; } } //Jeżeli wszystkie finishowe kwadraty zostały ukończone, to kończymy poziom if (finishSquareCount == 1) { if (Game.GetLevel() >= Game.GameProgress) { Game.ProgressHasBeenMade = true; } //Jeżeli ukończyliśmy całą grę if (Game.GetLevel() == 20) { var message = Game.ShowMessageBox("Congratulations! You've beat my first game. That's why it's so short by the way, but hope you enjoyed it :)"); message.SetButtonClick(() => { Initiate.Fade("Scenes/MainMenu", Color.black, 8f); }); } else { Game.LevelCompleteMessage(); } } } //Nasz kwadrat nie ma tej samej wartości co finishowy else { Game.LevelNotCompleteMessage(); } }
public MapSection[][] GenerateMap() { //fill a basic level with different squares const int mapHeight = 10; const int mapLength = mapHeight; var map = new MapSection[mapHeight][]; var squareNumber = 1; //The start square and end square will be added right under the for's var counter = 0; var bonusCounter = 0; for (int i = 0; i < mapHeight; i++) { map[i] = new MapSection[mapLength]; for (int j = 0; j < mapLength; j++) { if (bonusCounter == 7 && counter != 5) { var rnd = new Random(); if (rnd.Next(0, 10) % 2 == 0) { map[i][j] = new MysterySquare(i, j); bonusCounter++; } else { map[i][j] = new BonusSquare(i, j); bonusCounter++; } map[i][j].Number = squareNumber; squareNumber++; bonusCounter = 0; counter++; } else if (counter == 5) { var rnd = new Random(); if (rnd.Next(0, 4) % 2 == 0) { map[i][j] = new GoForwardSquare(i, j); counter++; } else { map[i][j] = new GoBackSquare(i, j); counter++; } counter = 0; map[i][j].Number = squareNumber; squareNumber++; } else { map[i][j] = new NormalSquare(i, j); map[i][j].Number = squareNumber; squareNumber++; counter++; bonusCounter++; } } } //this is the start square, can be different then 0,0 -> depends on the map map[0][0] = new StartSquare(0, 0); map[0][0].Number = 1; //this is the final square, who goes there first wins the game -> again depends on the map map[mapHeight - 1][mapLength - 1] = new FinishSquare(mapHeight - 1, mapLength - 1); map[mapHeight - 1][mapLength - 1].Number = 100; return(map); }
public override void Update() { base.Update(); //Przechwytywanie naciśnięcia klawiszy if (squareToMove == null) //Upewniamy się że nasz kwadrat akurat się nie porusza { if (Input.GetKeyDown(KeyCode.UpArrow) && topSquare != null) { Move(MoveDirection.Up); } else if (Input.GetKeyDown(KeyCode.RightArrow) && rightSquare != null) { Move(MoveDirection.Right); } else if (Input.GetKeyDown(KeyCode.DownArrow) && bottomSquare != null) { Move(MoveDirection.Down); } else if (Input.GetKeyDown(KeyCode.LeftArrow) && leftSquare != null) { Move(MoveDirection.Left); } } //Jeżeli kwadrat się porusza if (squareToMove != null) { this.gameObject.transform.position = Vector2.MoveTowards(this.gameObject.transform.position, squareToMove.gameObject.transform.position, Time.deltaTime * 5); //Jeeli kwadrat dotarł do celu if (this.gameObject.transform.position == squareToMove.gameObject.transform.position) { //Jeżeli powstała liczba ujemna if (negativeNumber) { Game.NegativeNumberMessage(); } //Jeżeli powstała liczba niepodzielna if (badDivision) { Game.BadDivisionMessage(); } //Jeżeli kwadrat na który wchodzimy jest finishujący if (squareToMove.Type == SquareType.Finish) { StepOnFinishSquare(squareToMove); } //Jeżeli poprzedni kwadrat nie był niezniszczalny, zamieniamy go na szary if (squareToMove.IsDestructable) { squareToMove.DisableSquare(); } //Odświeżanie naszego kwadratu squareToMove = null; this.valueText.text = value.ToString(); } } }
/// <summary> /// Cała operacja związana z ruchem naszego kwadratu rozpoczynająca animacje ruchu /// </summary> /// <param name="square">Square we are operating on</param> public void PerformAction(Square square) { //Nie poruszamy się w miejsce ścian if ((square as NormalSquare).Type == SquareType.Wall) { return; } //Przypisanie głównemu kwadratowi nowych sąsiadów this.topSquare = square.topSquare; this.rightSquare = square.rightSquare; this.bottomSquare = square.bottomSquare; this.leftSquare = square.leftSquare; //Kwadrat w kierunku którego się poruszamy squareToMove = square as NormalSquare; NormalSquare sq = square as NormalSquare; //Nowa wartość dla głównego kwadratu switch (sq.Type) { case SquareType.Empty: break; case SquareType.Adding: this.value += square.value; break; case SquareType.Subtracting: if (this.value - square.value < 0) { negativeNumber = true; } else { this.value -= square.value; } break; case SquareType.Multiplicating: this.value *= square.value; break; case SquareType.Dividing: if (this.value % square.value != 0) { badDivision = true; } else { this.value /= square.value; } break; case SquareType.NumAdding: this.value = this.value * 10 + square.value; break; case SquareType.Powering: this.value = (int)Mathf.Pow((float)value, (float)square.value); break; } }
public Square CreatePlayGround(string[] rows) { // From string [] to square[][] Square[][] squares = new Square[rows.Length][]; int arrayIndex = 0; foreach (string row in rows) { squares[arrayIndex] = new Square[row.Length]; int rowIndex = 0; foreach (char square in row) { Square currentSquare = null; PlayElement playElement = null; switch (square) { case 'R': currentSquare = new NormalSquare(); playElement = new Rockford(currentSquare); PlayElements["Players"].Add(playElement); break; case 'M': currentSquare = new MudSquare(); break; case 'B': currentSquare = new NormalSquare(); playElement = new Boulder(currentSquare); break; case 'D': currentSquare = new NormalSquare(); playElement = new Diamond(currentSquare); PlayElements["Gatherables"].Add(playElement); break; case 'W': currentSquare = new NormalSquare(); playElement = new NormalWall(currentSquare); break; case 'S': currentSquare = new NormalSquare(); playElement = new SteelWall(currentSquare); break; case 'F': currentSquare = new NormalSquare(); playElement = new FireFly(currentSquare); PlayElements["Enemies"].Add(playElement); break; case 'E': currentSquare = new ExitSquare(); break; case ' ': currentSquare = new NormalSquare(); break; } if (playElement != null) { currentSquare.AddPlayElement(playElement); } squares[arrayIndex][rowIndex] = currentSquare; rowIndex++; } arrayIndex++; } AssignPlayersToEnemies(); AssignToCollectItemsToPlayers(); AssignSideSquares(squares); return(squares[0][0]); // return first square of the sequence }
public void GenerateLevel(int level) { currLevel = level; var projectPath = Path.GetDirectoryName(Path.GetDirectoryName(Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase))); var fullPath = new Uri(projectPath + @"\Doolhof\doolhof" + level + ".txt").LocalPath; // Bevat het level(speelveld) textFile = File.ReadAllLines(fullPath); int row = 0; int column = 0; char[] squares; Square newSquare = null; foreach (string line in textFile) { squares = line.ToCharArray(); foreach (char square in squares) { switch (square) { case '#': newSquare = new WallSquare(row, column); row++; break; case '.': newSquare = new NormalSquare(row, column); row++; break; case '@': newSquare = new NormalSquare(row, column); newSquare.addMovableObject(Spike); Spike.Square = newSquare; Spike.Square.CalculateShape(); row++; break; case 'x': newSquare = new GoalSquare(row, column); row++; break; case 'o': newSquare = new NormalSquare(row, column); Box box = new Box(); newSquare.addMovableObject(box); box.Square = newSquare; box.Square.CalculateShape(); Boxes.Add(box); // add box to the array row++; break; case '~': newSquare = new PitFallSquare(row, column); row++; break; case '$': newSquare = new NormalSquare(row, column); newSquare.addMovableObject(Collaborator); Collaborator.Square = newSquare; Collaborator.Square.CalculateShape(); row++; CollaboratorActive = true; break; default: // add empty square PlayField.Add("e" + row + ":" + column, null); // indicate an emty square should be written row++; break; } // end switch if (newSquare != null) { PlayField.Add(newSquare.ID, newSquare); } newSquare = null; } // end for-loop -> for each char in string column++; row = 0; PlayField.Add("n" + row + ":" + column, null); // indicate an enter has to be written } // end for-loop -> for each string in string[] gameController.PrintField(PlayField); }
public MapSection[][] GenerateFirstMap() { //map coordinates: const int mapHeight = 5; const int mapLength = 10; var map = new MapSection[mapHeight][]; for (int i = 0; i < mapHeight; i++) { map[i] = new MapSection[mapLength]; for (int j = 0; j < mapLength; j++) { map[i][j] = new NormalSquare(i, j); } } AddCoordinates(map); var mapSquares = new List <MapSection>(); var squareNumber = 1; var counter = 0; var bonusCounter = 0; for (int i = 0; i < mapHeight; i++) { for (int j = 0; j < mapLength; j++) { if (i == 0 && j == 0) { map[i][j] = new StartSquare(i, j); } else if (i == map.Length - 1 && j == map[i].Length - 1) { map[i][j] = new FinishSquare(i, j); } else if (bonusCounter > 6) { if ((counter / 2 + bonusCounter) % 2 == 0) { map[i][j] = new BonusSquare(i, j); } else { map[i][j] = new MysterySquare(i, j); } bonusCounter = 0; } else if (counter > 5 && (bonusCounter + 1) % 2 == 0) { map[i][j] = new GoForwardSquare(i, j); counter = 1; } else if (counter > 5) { map[i][j] = new GoBackSquare(i, j); counter = 1; } else { map[i][j] = new NormalSquare(i, j); } map[i][j].Number = squareNumber; squareNumber++; counter++; bonusCounter++; AddCoordinates(map); mapSquares.Add(map[i][j]); if (squareNumber == 51) { break; } } } var json = Serializer.ExportFirstMapCoordinates(mapSquares); Console.WriteLine(json); return(map); }
public static List <MapSection> GetMapPath() { //Used for the map path service const int mapHeight = 5; const int mapLength = 10; var map = new MapSection[mapHeight][]; for (int i = 0; i < mapHeight; i++) { map[i] = new MapSection[mapLength]; for (int j = 0; j < mapLength; j++) { map[i][j] = new NormalSquare(i, j); } } AddCoordinates(map); var mapSquares = new List <MapSection>(); var squareNumber = 1; var counter = 0; var bonusCounter = 0; for (int i = 0; i < mapHeight; i++) { for (int j = 0; j < mapLength; j++) { if (i == 0 && j == 0) { map[i][j] = new StartSquare(i, j); } else if (i == map.Length - 1 && j == map[i].Length - 1) { map[i][j] = new FinishSquare(i, j); } else if (bonusCounter > 6) { if ((counter / 2 + bonusCounter) % 2 == 0) { map[i][j] = new BonusSquare(i, j); } else { map[i][j] = new MysterySquare(i, j); } bonusCounter = 0; } else if (counter > 5 && (bonusCounter + 1) % 2 == 0) { map[i][j] = new GoForwardSquare(i, j); counter = 1; } else if (counter > 5) { map[i][j] = new GoBackSquare(i, j); counter = 1; } else { map[i][j] = new NormalSquare(i, j); } map[i][j].Number = squareNumber; squareNumber++; counter++; bonusCounter++; AddCoordinates(map); mapSquares.Add(map[i][j]); if (squareNumber == 51) { break; } } } return(mapSquares); }