//怪物计时器运转方法 private void tmEnemy_Tick(object sender, EventArgs e) { if (FStatus == GameStatus.Playing) { switch (Glip) { case Game_Clip.Zero_Clip: if (FBornCount == 20) { if (FGame.AliveMonsterCount == 0) { //FinishGame(true); ReStart(); FBornCount = 0; Thread.Sleep(1000); FGame.PutMessage("积寒之地"); Glip = Game_Clip.One_Clip; } } else { FGame.SetMonster1(new LeveledMonster(1));/*生成小怪1*/ FBornCount++; RefreshCaption(); System.Threading.Thread.Sleep(10); } break; case Game_Clip.One_Clip: if (FBornCount == 30) { if (FGame.AliveMonsterCount == 0) { //FinishGame(true); ReStart(); FBornCount = 0; Thread.Sleep(1000); FGame.PutMessage("深海墓地"); Glip = Game_Clip.Two_Clip; } } else { FGame.SetMonster2(new LeveledMonster(1));/*生成小怪2*/ FBornCount++; RefreshCaption(); System.Threading.Thread.Sleep(10); } break; case Game_Clip.Two_Clip: if (FBornCount == 40) { if (FGame.AliveMonsterCount == 0) { FinishGame(true); } } else { FGame.SetMonster3(new LeveledMonster(1));/*生成小怪3*/ FBornCount++; RefreshCaption(); System.Threading.Thread.Sleep(10); } break; } } }
/// <summary> /// 绘制游戏开始logo /// </summary> //public void DrawLogo() //{ // Image logo = Image.FromFile("..//..//images//logo.png"); // FPainter.DrawImage(logo, 0, 0); //} /// <summary> /// 绘制游戏画面 /// </summary> private void Draw_DrawScreen(Game_Clip gc) { /*绘制背景*/ Draw_DrawBackground(gc); /*绘制塔*/ for (int i = 1; i < _MapCols - 1; i++) { for (int j = 1; j < _MapRows - 1; j++) { Tower aTower = FMap.Cells(i, j).Tower; if (aTower != null) { aTower.DrawTower(FPainter); } } } /*绘制怪物*/ foreach (LinkedList<Monster> List in FMonsters) { foreach (Monster m in List) { m.Draw(FPainter); } } /*绘制炮弹*/ for (int i = 1; i < _MapCols - 1; i++) { for (int j = 1; j < _MapRows - 1; j++) { Tower aTower = FMap.Cells(i, j).Tower; if (aTower != null) { aTower.DrawFloating(FPainter); } } } /*绘制血条*/ foreach (LinkedList<Monster> List in FMonsters) { foreach (Monster m in List) { float Left = -10; float Right = 10; float Life = (Right - Left) * m.Life / m.MaxLife + Left; Painter.DrawLine(FLifeBackPen, m.Position.X + Left, m.Position.Y - m.Radius - 2, m.Position.X + Right, m.Position.Y - m.Radius - 2); Painter.DrawLine(FLifeBackPen, m.Position.X + Left, m.Position.Y - m.Radius - 1, m.Position.X + Right, m.Position.Y - m.Radius - 1); Painter.DrawLine(FLifePen, m.Position.X + Left, m.Position.Y - m.Radius - 2, m.Position.X + Life, m.Position.Y - m.Radius - 2); Painter.DrawLine(FLifePen, m.Position.X + Left, m.Position.Y - m.Radius - 1, m.Position.X + Life, m.Position.Y - m.Radius - 1); } } /*绘制剪辑*/ FClipPainter.Draw(FPainter); /*绘制文字消息*/ if (FMessageStatus != MessageStatus.Disabled) { Color BrushColor = FMessageBrush.Color; FMessageBrush.Color = Color.FromArgb(FMessageAlpha, Color.Black); SizeF MessageSize = FPainter.MeasureString(FMessage, FMessageFont); float X = (_ScreenWidth - MessageSize.Width) / 2; float Y = (_ScreenHeight - MessageSize.Height) / 2; FPainter.DrawString(FMessage, FMessageFont, FMessageBrush, new PointF(X, Y)); } }
/// <summary> /// 绘制游戏画面 /// </summary> public void Draw(Game_Clip gg) { //if (ttt == 0) //{ // DrawLogo(); // Thread.Sleep(1000); // ttt++; //} Draw_DrawScreen(gg); }
/// <summary> /// 绘制游戏背景 /// </summary> private void Draw_DrawBackground(Game_Clip gc) { switch (gc) { case Game_Clip.Zero_Clip: Image map01=Image.FromFile("..//..//images//map01.png"); FPainter.DrawImage(map01, 0, 0); break; case Game_Clip.One_Clip: Image map02 = Image.FromFile("..//..//images//map02.png"); FPainter.DrawImage(map02, 0, 0); break; case Game_Clip.Two_Clip: Image map03 = Image.FromFile("..//..//images//map03.png"); FPainter.DrawImage(map03, 0, 0); break; } }
/// <summary> /// 游戏动作 /// </summary> /// <param name="Channel">出口数量</param> public void Action(Game_Clip gc) { /*运行塔*/ for (int i = 1; i < _MapCols - 1; i++) { for (int j = 1; j < _MapRows - 1; j++) { Tower aTower = FMap.Cells(i, j).Tower; if (aTower != null) { aTower.Run(FMonsters); } } } /*运行怪物*/ switch(gc) { case Game_Clip.Zero_Clip: LinkedList<Monster> List1 = FMonsters[0]; LinkedListNode<Monster> Current1 = List1.First; while (Current1 != null) { LinkedListNode<Monster> Next = Current1.Next; Direction CurrentDirection; if (Current1.Value.Life == 0) { if (OnMonsterKilled != null) { OnMonsterKilled(this, Current1.Value); } List1.Remove(Current1); } else { CurrentDirection = Current1.Value.Direction; //哈哈哈哈哈哈哈哈哈 { int X = (int)Current1.Value.Position.X; int Y = (int)Current1.Value.Position.Y; int Col = X / _CellSize; int Row = Y / _CellSize; //////怪物转向控制(呃 if (X >= 112 && Col == 3) { CurrentDirection = Direction.Down; } if (Row == 11 && Col == 3) { CurrentDirection = Direction.Right; } if (X >= 272 && Row == 11) { CurrentDirection = Direction.Up; } if (Row == 1 && Col == 8) { CurrentDirection = Direction.Right; } if (Row == 1 && X >= 400) { CurrentDirection = Direction.Down; } if (Row == 11 && X >= 400) { CurrentDirection = Direction.Right; } if (Row == 11 && X >= 560) { CurrentDirection = Direction.Up; } } /*行走*/ Current1.Value.Run(CurrentDirection); /*判断怪物是否通过场地*/ { int X = (int)Current1.Value.Position.X; int Y = (int)Current1.Value.Position.Y; int Col = X / _CellSize; int Row = Y / _CellSize; if (Row == 4 && Col == 17) { if (OnMonsterPass != null) { OnMonsterPass(this, Current1.Value); } Current1.Value.Life = 0; List1.Remove(Current1); } } } Current1 = Next; } break; case Game_Clip.One_Clip: { LinkedList<Monster> List2 = FMonsters[0]; LinkedListNode<Monster> Current2 = List2.First; while (Current2 != null) { LinkedListNode<Monster> Next = Current2.Next; Direction CurrentDirection; if (Current2.Value.Life == 0) { if (OnMonsterKilled != null) { OnMonsterKilled(this, Current2.Value); } List2.Remove(Current2); } else { CurrentDirection = Current2.Value.Direction; //哈哈哈哈哈哈哈哈哈 { int X = (int)Current2.Value.Position.X; int Y = (int)Current2.Value.Position.Y; int Col = X / _CellSize; int Row = Y / _CellSize; //////怪物转向控制(呃 if (X >= 336 && Row == 2) { CurrentDirection = Direction.Down; } else if (X >= 336 && X<520 && Row == 8) { CurrentDirection = Direction.Left; } else if (X <= 85 && Row == 8) { CurrentDirection = Direction.Down; } else if (X <= 85 && Row == 12) { CurrentDirection = Direction.Right; } else if (X >= 522 && Row == 12) { CurrentDirection = Direction.Up; } } /*行走*/ Current2.Value.Run(CurrentDirection); /*判断怪物是否通过场地*/ { int X = (int)Current2.Value.Position.X; int Y = (int)Current2.Value.Position.Y; int Col = X / _CellSize; int Row = Y / _CellSize; if (Row == 2 && Col == 16) { if (OnMonsterPass != null) { OnMonsterPass(this, Current2.Value); } Current2.Value.Life = 0; List2.Remove(Current2); } } } Current2 = Next; } } break; case Game_Clip.Two_Clip: { LinkedList<Monster> List3 = FMonsters[0]; LinkedListNode<Monster> Current3 = List3.First; while (Current3 != null) { LinkedListNode<Monster> Next = Current3.Next; Direction CurrentDirection; if (Current3.Value.Life == 0) { if (OnMonsterKilled != null) { OnMonsterKilled(this, Current3.Value); } List3.Remove(Current3); } else { CurrentDirection = Current3.Value.Direction; //哈哈哈哈哈哈哈哈哈 { int X = (int)Current3.Value.Position.X; int Y = (int)Current3.Value.Position.Y; int Col = X / _CellSize; int Row = Y / _CellSize; //////怪物转向控制(呃 if (X <= 148 && Row == 3) { CurrentDirection = Direction.Down; } if (X <= 148 && Row == 9) { CurrentDirection = Direction.Right; } if (X >= 208 && X<600 && Row == 9) { CurrentDirection = Direction.Down; } if (X >= 208 && Row == 12) { CurrentDirection = Direction.Right; } if (X >= 612 && Row == 12) { CurrentDirection = Direction.Up; } if (X >= 612 && Row == 8) { CurrentDirection = Direction.Left; } if (X <= 465 && X>400 && Row == 8) { CurrentDirection = Direction.Up; } } /*行走*/ Current3.Value.Run(CurrentDirection); /*判断怪物是否通过场地*/ { int X = (int)Current3.Value.Position.X; int Y = (int)Current3.Value.Position.Y; int Col = X / _CellSize; int Row = Y / _CellSize; if (Row == 7 && Col == 14) { if (OnMonsterPass != null) { OnMonsterPass(this, Current3.Value); } Current3.Value.Life = 0; List3.Remove(Current3); } } } Current3 = Next; } } break; } }