public static int GetScore(RecordColor c) { if (c == RecordColor.grey) return 0; else return (((int)c + 2) * (Game1.CurrentLevel.LevelNumber + 1)) * 5 / 7; }
/// <summary> /// Adds all initial moving objects to the Objects list /// </summary> private static void InitializeObjects() { NewLevel = false; Objects = new List<Mover>(); if (RobotPlayer == null) RobotPlayer = new Robot(45, 45); else { RobotPlayer.Position = Settings.RobotStartingPosition; RobotPlayer.RobotFlashing = false; RobotPlayer.Direction = Direction.None; RobotPlayer.NextDirection = Direction.None; } Objects.Add(RobotPlayer); for (int i = 0; i < Game1.CurrentLevel.NumRecords; i++) { Point p = Maze.getPointToPlace(); Objects.Add(new Record(p.X, p.Y, (RecordColor)i)); } nextColor = RecordColor.red; }
public static void AIChangeDirection(RecordColor c) { Mover[] objs = Objects.ToArray(); foreach (Mover m in objs) { if (!(m is Robot)) { Record rec = m as Record; if (rec.Color == RecordColor.grey) { // Calculate the difference in the X and Y positions double xDiff = RobotPlayer.Position.X - m.Position.X; double yDiff = RobotPlayer.Position.Y - m.Position.Y; if (rec.Direction == Direction.Down && Maze.CanGo(rec.Position, (Direction)((int)rec.Direction * -1))) { if (yDiff <= 0) rec.Direction = (Direction)((int)rec.Direction * -1); } else if (rec.Direction == Direction.Up && Maze.CanGo(rec.Position, (Direction)((int)rec.Direction * -1))) { if (yDiff >= 0) rec.Direction = (Direction)((int)rec.Direction * -1); } if (rec.Direction == Direction.Right && Maze.CanGo(rec.Position, (Direction)((int)rec.Direction * -1))) { if (xDiff <= 0) rec.Direction = (Direction)((int)rec.Direction * -1); } else if (rec.Direction == Direction.Left && Maze.CanGo(rec.Position, (Direction)((int)rec.Direction * -1))) { if (xDiff >= 0) rec.Direction = (Direction)((int)rec.Direction * -1); } } else if (rec.Color == MovingObjectManager.nextColor) { // Calculate the difference in the X and Y positions double xDiff = RobotPlayer.Position.X - m.Position.X; double yDiff = RobotPlayer.Position.Y - m.Position.Y; if (rec.Direction == Direction.Down && Maze.CanGo(rec.Position, (Direction)((int)rec.Direction * -1))) { if (yDiff >= 0) rec.Direction = (Direction)((int)rec.Direction * -1); } else if (rec.Direction == Direction.Up && Maze.CanGo(rec.Position, (Direction)((int)rec.Direction * -1))) { if (yDiff <= 0) rec.Direction = (Direction)((int)rec.Direction * -1); } if (rec.Direction == Direction.Right && Maze.CanGo(rec.Position, (Direction)((int)rec.Direction * -1))) { if (xDiff >= 0) rec.Direction = (Direction)((int)rec.Direction * -1); } else if (rec.Direction == Direction.Left && Maze.CanGo(rec.Position, (Direction)((int)rec.Direction * -1))) { if (xDiff <= 0) rec.Direction = (Direction)((int)rec.Direction * -1); } } } } }
public static void SetRelativeDirection(RecordColor color) { Mover[] objs = Objects.ToArray(); int r = Game1.rand.Next(2); foreach (Mover m in objs) { if (!(m is Robot)) { Record rec = m as Record; if (rec.Color == RecordColor.grey || rec.Color == nextColor) { // Calculate the difference in the X and Y positions double xDiff = RobotPlayer.Position.X - m.Position.X; double yDiff = RobotPlayer.Position.Y - m.Position.Y; if (xDiff >= 0 && yDiff >= 0) { if (r == 1) { m.AIChoice1 = Direction.Down; m.AIChoice2 = Direction.Right; } else { m.AIChoice1 = Direction.Right; m.AIChoice2 = Direction.Down; } } else if (xDiff >= 0 && yDiff <= 0) { if (r == 1) { m.AIChoice1 = Direction.Up; m.AIChoice2 = Direction.Right; } else { m.AIChoice1 = Direction.Right; m.AIChoice2 = Direction.Up; } } else if (xDiff <= 0 && yDiff <= 0) { if (r == 1) { m.AIChoice1 = Direction.Up; m.AIChoice2 = Direction.Left; } else { m.AIChoice1 = Direction.Left; m.AIChoice2 = Direction.Up; } } else if (xDiff <= 0 && yDiff >= 0) { if (r == 1) { m.AIChoice1 = Direction.Down; m.AIChoice2 = Direction.Left; } else { m.AIChoice1 = Direction.Left; m.AIChoice2 = Direction.Down; } } } } } }
public static void NextLevel() { ScoreManager.CurrentScore += (Game1.CurrentLevel.LevelNumber+11)*(100 - ((DateTime.Now - Game1.StartTime) + Game1.SumTime).Seconds) / 40; AudioPlayer.Play(0, (Game1.CurrentLevel.LevelNumber + 1) % 4 + 1); Objects.RemoveAll(item => item is Record); //GameWin = true; if (Game1.CurrentLevel.LevelNumber == 9) { Game1.CurrentLevel.LevelNumber = 0; GameWin = true; Game1.Win(); //win the game } else { if (Maze.level == 4) { Maze.level = 0; //more records if (Game1.CurrentLevel.NumRecords < 5) Game1.CurrentLevel.NumRecords += 2; else Game1.CurrentLevel.NumRecords = 6; } Maze.level++; Game1.CurrentLevel.LevelNumber++; switch (Game1.CurrentLevel.LevelNumber) { case 0: Textures.mazewall = Textures.MazeWall1; break; case 1: Textures.mazewall = Textures.MazeWall2; break; case 2: Textures.mazewall = Textures.MazeWall3; break; case 3: Textures.mazewall = Textures.MazeWall4; break; case 4: Textures.mazewall = Textures.MazeWall5; break; case 5: Textures.mazewall = Textures.MazeWall6; break; case 6: Textures.mazewall = Textures.MazeWall7; break; case 7: Textures.mazewall = Textures.MazeWall8; break; case 8: Textures.mazewall = Textures.MazeWall9; break; case 9: Textures.mazewall = Textures.MazeWall10; break; default: Textures.mazewall = Textures.MazeWall10; break; } //display a screen between levels Game1.screens.Play(new PreLevelScreen()); Maze.Draw(); InitializeObjects(); nextColor = RecordColor.red; } }
public static Point GetRelativePosition(RecordColor c) { Mover[] objs = Objects.ToArray(); int r = Game1.rand.Next(2); foreach (Mover m in objs) { if (!(m is Robot)) { Record rec = m as Record; if (rec.Color == c) return new Point(Math.Abs(RobotPlayer.Position.X - m.Position.X), Math.Abs(RobotPlayer.Position.Y - m.Position.Y)); } } return new Point(-9999, -9999); }
public Record(int x, int y, RecordColor c) { CanDamage = true; CountDown = false; NotStuck = true; this.Position.X = x; this.Position.Y = y; this.Color = c; this.Value = ScoreManager.GetScore(c); if (Settings.DifficultyLevel != Settings.DifficultySettings.easy) Settings.RecordSpeed = 2; else Settings.RecordSpeed = 1; this.Speed = Settings.RecordSpeed; this.CurrentDirection = Direction.None; this.OldPosition = this.Position; //CanGo = false; switch (c) { case RecordColor.red: this.Texture = Textures.RedRecord; break; } switch (c) { case RecordColor.red: this.Texture = Textures.RedRecord; break; case RecordColor.orange: this.Texture = Textures.OrangeRecord; break; case RecordColor.yellow: this.Texture = Textures.YellowRecord; break; case RecordColor.green: this.Texture = Textures.GreenRecord; break; case RecordColor.blue: this.Texture = Textures.BlueRecord; break; case RecordColor.violet: this.Texture = Textures.VioletRecord; break; } this.OriginalTexture = Texture; Random rand = new Random(); int r = rand.Next(4); switch (r) //This is used to determine a random initial direction for the records { case 0: this.Direction = Direction.Up; break; case 1: this.Direction = Direction.Down; break; case 2: this.Direction = Direction.Left; break; case 3: this.Direction = Direction.Right; break; } if (Maze.grid == null) Console.WriteLine("THE GRID IS NOT INSTANTIATED"); while (!Maze.CanGo(this.Position, this.Direction)) //This will choose a random direction if the initial random direction pointed the record towards a wall { if ((int)this.Direction == 2) { this.Direction = Direction.Right; } //if (!Maze.CanGo(this.Position, this.Direction)) this.Direction++; //else //CanGo = true; } //this.Direction = Direction.None; }
public override void Update() { TimeSpan elapsedTime = DateTime.Now - Game1.Time; //Random rand = new Random(); // I am not putting in an ai that knows where the robot is yet, so this is used in helping choose the direction int r; if (Maze.grid == null) Console.WriteLine("THE GRID IS NOT INSTANTIATED"); if (Maze.IsDeadEnd(this.Position)) this.Direction = (Direction)((int)this.Direction * -1); this.RelativePosition = MovingObjectManager.GetRelativePosition(this.Color); if (Maze.IsIntersection(this.Position)) { this.CurrentDirection = this.Direction; if ((Settings.DifficultyLevel == Settings.DifficultySettings.easy || (this.Color != RecordColor.grey && this.Color != MovingObjectManager.nextColor)) || (Settings.DifficultyLevel != Settings.DifficultySettings.hard && (this.Color == RecordColor.grey)) ) { do //This do while loop will choose a random direction to go at an intersection (until we want to implement an ai that will chase or flee from the robot which is not a priority for the demo) { r = Game1.rand.Next(4); switch (r) { case 0: this.Direction = Direction.Right; break; case 1: this.Direction = Direction.Left; break; case 2: this.Direction = Direction.Up; break; case 3: this.Direction = Direction.Down; break; } if (Maze.CanGo(this.Position, this.Direction)) { CanGo = true; if ((int)this.CurrentDirection + (int)this.Direction == 0) CanGo = false; } } while (!CanGo); CanGo = false; } else { MovingObjectManager.SetRelativeDirection(this.Color); if (this.Color == MovingObjectManager.nextColor) { this.AIChoice1 = (Direction)((int)this.AIChoice1 * -1); this.AIChoice2 = (Direction)((int)this.AIChoice2 * -1); } if (Maze.CanGo(this.Position, this.AIChoice1)) this.Direction = this.AIChoice1; else if (Maze.CanGo(this.Position, this.AIChoice2)) this.Direction = this.AIChoice2; else { r = Game1.rand.Next(2); if (r == 0) { this.Direction = (Direction)((int)this.AIChoice1 * -1); if (!Maze.CanGo(this.Position, this.Direction)) this.Direction = (Direction)((int)this.AIChoice2 * -1); } else { this.Direction = (Direction)((int)this.AIChoice2 * -1); if (!Maze.CanGo(this.Position, this.Direction)) this.Direction = (Direction)((int)this.AIChoice1 * -1); } } } } else if ((this.Color == RecordColor.grey || this.Color == MovingObjectManager.nextColor) && (RelativePosition.X < 59 && RelativePosition.Y < 59) && Settings.DifficultyLevel != Settings.DifficultySettings.easy) { if(Settings.DifficultyLevel == Settings.DifficultySettings.hard || this.Color == MovingObjectManager.nextColor) MovingObjectManager.AIChangeDirection(this.Color); } //if (elapsedTime.Milliseconds % 100 == 0) //{ // if (elapsedTime.Milliseconds % 2000 == 0) // NotStuck = true; // if (this.OldPosition.X - this.Position.X < 5 && this.OldPosition.Y - this.Position.Y < 5) // NotStuck = false; // this.OldPosition = this.Position; //} if (CountDown) DeathCount++; if (DeathCount < 100 && CountDown) { if ((DeathCount > 20 && DeathCount < 40) || (DeathCount > 60 && DeathCount < 80)) this.Texture = OriginalTexture; else this.Texture = Textures.GreyRecord; } if (DeathCount == 100) { this.Texture = Textures.GreyRecord; this.Color = RecordColor.grey; this.CanDamage = true; this.Value = ScoreManager.GetScore(Color); Gathered = false; } base.UpdatePosition(); }