void Awake() { if (GAME == null) { GAME = this; } else if (GAME != this) { Destroy(this); } DontDestroyOnLoad(gameObject); Debug.Log("INITILIZING GAMEMANAGER (should only be once"); MAZE = this.GetComponent <MazeObject>(); }
private void RenderMap() { var modelList = new List <_2DModel>(); var graphics = Global.Instance.Graphics; var unit = Global.Instance.Unit; var colors = new Color[] { new Color(246, 215, 152), new Color(222, 182, 104) }; int colorIndex = 0; for (int i = 0; i < mapWidth; i++) { for (int j = 0; j < mapHeight; j++) { var realPosition = MazeObject.MapToRealPosition(i, j); if (matrix[i, j] == 1) { modelList.Add(new _2DModel(ResManager.Instance.Wall, new Rectangle(realPosition.X, realPosition.Y, unit, unit), Color.White)); } else { var cell = new Texture2D(graphics, 1, 1); cell.SetData(new Color[] { colors[colorIndex] }); modelList.Add(new _2DModel(cell, new Rectangle(realPosition.X, realPosition.Y, unit, unit), Color.White)); } colorIndex = 1 - colorIndex; } } mazeModels = modelList.ToArray(); }
/// <summary> /// Build a maze with previously passed parameters. /// </summary> /// <returns>Matrix where [row, col] points to a MazeObject.</returns> public MazeObject[,] Build() { MazeObject[,] maze = new MazeObject[size, size]; int rowMax = maze.GetUpperBound(0); int columnMax = maze.GetUpperBound(1); for (int row = 0; row <= rowMax; row++) { for (int col = 0; col <= columnMax; col++) { if (row < emptyPosition + emptySize && row > emptyPosition - emptySize && col < emptyPosition + emptySize && col > emptyPosition - emptySize) { continue; } if (row == 0 || col == 0 || row == rowMax || col == columnMax) { // Create the borders maze[row, col] = MazeObject.Wall; } else if (row % 2 == 0 && col % 2 == 0) { if (rand.NextDouble() > placementThreshold) { maze[row, col] = MazeObject.Wall; int a = rand.NextDouble() < .5 ? 0 : (rand.NextDouble() < .5 ? -1 : 1); int b = a != 0 ? 0 : (rand.NextDouble() < .5 ? -1 : 1); maze[row + a, col + b] = MazeObject.Wall; } } else if (rand.NextDouble() < bombChance) { maze[row, col] = MazeObject.Bomb; } else if (rand.NextDouble() < fireChance) { maze[row, col] = MazeObject.Fire; } else if (rand.NextDouble() < clockChance) { maze[row, col] = MazeObject.Clock; } else if (rand.NextDouble() < jumpChance) { maze[row, col] = MazeObject.Jump; } } } // Generate one opening in the maze sides int side = rand.Next(4); int openingRow = 0; int openingColumn = 0; while (openingRow == 0 && openingColumn == 0) // top left corner is invalid for an opening { int distance = rand.Next(1, size - 1); // Check that the opening isn't toward an interior wall if (side == 0 && maze[1, distance] != MazeObject.Wall) { openingRow = 0; openingColumn = distance; } else if (side == 1 && maze[rowMax - 1, distance] != MazeObject.Wall) { openingRow = rowMax; openingColumn = distance; } else if (side == 2 && maze[distance, 1] != MazeObject.Wall) { openingRow = distance; openingColumn = 0; } else if (side == 3 && maze[distance, columnMax - 1] != MazeObject.Wall) { openingRow = distance; openingColumn = columnMax; } } maze[openingRow, openingColumn] = MazeObject.Ground; return(maze); }
/// <summary> /// 迷路を表示する。 /// </summary> /// <param name="mazeObject">迷路オブジェクト</param> static void Show(MazeObject mazeObject) { for (int y = 0; y < mazeObject.SizeY; y++) { for (int x = 0; x < mazeObject.SizeX; x++) { if (mazeObject.Solved) { //迷路が解かれている if (mazeObject.FieldArray[x, y] == MazeFieldArray.CellType.Wall) { //壁 Console.Write("■"); } else if (mazeObject.FieldArray[x, y] == MazeFieldArray.CellType.Start) { //スタート Console.Write("◇"); } else if (mazeObject.FieldArray[x, y] == MazeFieldArray.CellType.Goal) { //ゴール Console.Write("◇"); } else { //道 if (mazeObject.SolveArray[x, y] == MazeSolveArray.CellType.Right) { //正しい道 Console.Write("〇"); } else { //間違った道 Console.Write(" "); } } } else { //迷路は解かれていない if (mazeObject.FieldArray[x, y] == MazeFieldArray.CellType.Wall) { //壁 Console.Write("■"); } else if (mazeObject.FieldArray[x, y] == MazeFieldArray.CellType.Start) { //スタート Console.Write("◇"); } else if (mazeObject.FieldArray[x, y] == MazeFieldArray.CellType.Goal) { //ゴール Console.Write("◇"); } else { //道 Console.Write(" "); } } } Console.WriteLine(); } }
public override void Update(GameTime gameTime) { base.Update(gameTime); switch (state) { case State.Waiting: if (PlayerRequestMoving) { SoundManager.Instance.PlaySound(ResManager.Instance.FootSteps); player.NumOfSteps = 1; state = State.PlayerMoving; } break; case State.CalculateMonsterMovement: if (currentMonsterIndex == monsters.Length) { currentMonsterIndex = 0; state = State.Waiting; } else { if (MonsterReadyToMove()) { SoundManager.Instance.PlaySound(ResManager.Instance.FootSteps); state = State.MonsterMoving; } } break; case State.MonsterMoving: { var currentMonster = monsters[currentMonsterIndex]; if (currentMonster.NeedMoving) { currentMonster.Move(gameTime); } else { currentMonster.Stop(); if (CheckCollision()) { SoundManager.Instance.PlaySound(ResManager.Instance.Explosion); var pos = MazeObject.MapToRealPosition(currentMonster.LogicPos); collision.Rect = new Rectangle(pos.X - 25, pos.Y - 25, 100, 100); state = State.Collision; return; } SoundManager.Instance.PlaySound(ResManager.Instance.FootSteps); PlayerScanning(); if (currentMonster.NumOfSteps == 0) { currentMonsterIndex++; } state = State.CalculateMonsterMovement; } } break; case State.PlayerMoving: if (player.NeedMoving) { player.Move(gameTime); } else { player.Stop(); SoundManager.Instance.PlaySound(ResManager.Instance.FootSteps); if (CheckCollision(true)) { SoundManager.Instance.PlaySound(ResManager.Instance.Explosion); var pos = MazeObject.MapToRealPosition(player.LogicPos); collision.Rect = new Rectangle(pos.X - 25, pos.Y - 25, 100, 100); state = State.Collision; return; } if (GetOutOfMaze) { GameResult.Instance.IsWon = true; GameResult.Instance.Score = 3 * numOfFreeSpace - numOfPlayerSteps; EventBoard.Instance.AddEvent(EventBoard.Event.ShowResult); state = State.End; return; } for (int i = 0; i < monsters.Length; i++) { PlayerScanning(i); } numOfPlayerSteps++; playerSteps.Text = "Numbers of step: " + numOfPlayerSteps; state = State.CalculateMonsterMovement; } break; case State.Collision: collision.Update(gameTime); endTime -= (int)gameTime.ElapsedGameTime.TotalMilliseconds; if (endTime <= 0) { GameResult.Instance.IsWon = false; EventBoard.Instance.AddEvent(EventBoard.Event.ShowResult); state = State.End; } break; case State.End: break; } }
public void RemoveObject(MazeObject objectToRemove) { MazeObjects.Remove(objectToRemove); }
public void AddMazeObject(MazeObject mazeObject) { MazeObjects.Add(mazeObject); }