public void DrawCave(List <int>[] graph, List <bool>[] isActive, List <Danger> DangerList, Danger danger, int CurrentRoom) { Clear(Color.Black); int deltaStar = (int)StarTimer.ElapsedMilliseconds; StarTimer.Restart(); for (int i = 0; i < StarX.Count; ++i) { StarTime[i] -= deltaStar; if (StarTime[i] <= 0) { StarX[i] = Utily.Next() % Width; StarY[i] = Utily.Next() % Height; StarTime[i] = Utily.Next() % 200 + 500; } Graphics.FillRectangle(Brushes.White, StarX[i], StarY[i], 1, 1); } if (!IsAnimated) { DrawAllFriends(graph, isActive, DangerList, danger, CurrentRoom, Width / 2 - length / 2, (Height - length) / 2 - deltaY); isActiveLast = isActive; DangerListLast = DangerList; dangerLast = danger; CurrentRoomLast = CurrentRoom; } if (IsAnimated) { long Milliseconds = moveTimerAnimation.ElapsedMilliseconds; Progress = Milliseconds / 2500.0f; int TargetCenterX = Width / 2 - length / 2; int TargetCenterY = (Height - length) / 2 - deltaY; //coordinates for animation room DrawRegion(-ScaleRoomX[numberstone], -ScaleRoomY[numberstone], TargetCenterX - (int)(length * ScaleRoomX[numberstone] * Progress) + (int)(2 * length * ScaleRoomX[numberstone]) - (int)(length * ScaleRoomX[numberstone] * Progress), TargetCenterY - (int)(length * ScaleRoomY[numberstone] * Progress) + (int)(2 * length * ScaleRoomY[numberstone]) - (int)(length * ScaleRoomY[numberstone] * Progress)); DrawAllFriends(graph, isActiveLast, DangerListLast, dangerLast, CurrentRoomLast, TargetCenterX - (int)(length * ScaleRoomX[numberstone] * Progress), TargetCenterY - (int)(length * ScaleRoomY[numberstone] * Progress)); if (Progress >= 1.0f) { Progress = 0.0f; moveTimerAnimation.Stop(); IsAnimated = false; } } if ((IsBatAnimated || MaximizateBat) && !IsAnimated) { if (batTimerAnimation == null) { batTimerAnimation = new Stopwatch(); batTimerAnimation.Start(); } else { long Milliseconds = batTimerAnimation.ElapsedMilliseconds; float progress = Milliseconds / 2500.0f; length = (int)(normallength * (1.0f - progress)); if (progress >= 1.0f) { progress -= 1; MaximizateBat = true; MinimizeBat = false; length = (int)(normallength * progress); } if (Milliseconds > 5000) { IsBatAnimated = false; MaximizateBat = false; MinimizeBat = false; batTimerAnimation = null; length = normallength; } } } if (IsArrowAnimation && !IsBatAnimated && !IsAnimated) { long ms = ArrowTimerAnimation.ElapsedMilliseconds; int WaitTime = 500; if (ms < WaitTime) { Pen pn = new Pen(Color.Gold, 5); //sin and cos alpha. alpha-angle left-upper and upper double cos = 3 / Utily.Hypot(3, 2); double sin = 2 / Utily.Hypot(3, 2); int UseHeight = Height - 120; //draw arrow //for every Direction if (ArrowDirection == 0) { Graphics.DrawLine(pn, Width / 2, UseHeight / 2 - ms * length / 2 / WaitTime, Width / 2, UseHeight / 2 - ms * length / 2 / WaitTime - 50); } if (ArrowDirection == 3) { Graphics.DrawLine(pn, Width / 2, UseHeight / 2 + ms * length / 2 / WaitTime, Width / 2, UseHeight / 2 + ms * length / 2 / WaitTime + 50); } if (ArrowDirection == 1) { Graphics.DrawLine(pn, Width / 2 - length * ms / 3 / WaitTime, UseHeight / 2 - ms * length / 4 / WaitTime, Width / 2 - length * ms / 3 / WaitTime - (int)(50 * cos), UseHeight / 2 - ms * length / 4 / WaitTime - (int)(50 * sin)); } if (ArrowDirection == 2) { Graphics.DrawLine(pn, Width / 2 - length * ms / 3 / WaitTime, UseHeight / 2 + ms * length / 4 / WaitTime, Width / 2 - length * ms / 3 / WaitTime - (int)(50 * cos), UseHeight / 2 + ms * length / 4 / WaitTime + (int)(50 * sin)); } if (ArrowDirection == 5) { Graphics.DrawLine(pn, Width / 2 + length * ms / 3 / WaitTime, UseHeight / 2 - ms * length / 4 / WaitTime, Width / 2 + length * ms / 3 / WaitTime + (int)(50 * cos), UseHeight / 2 - ms * length / 4 / WaitTime - (int)(50 * sin)); } if (ArrowDirection == 4) { Graphics.DrawLine(pn, Width / 2 + length * ms / 3 / WaitTime, UseHeight / 2 + ms * length / 4 / WaitTime, Width / 2 + length * ms / 3 / WaitTime + (int)(50 * cos), UseHeight / 2 + ms * length / 4 / WaitTime + (int)(50 * sin)); } } else { IsArrowAnimation = false; ArrowTimerAnimation.Stop(); } } }
public void UpDate(long time) { if (state == ControlState.Cave) { List <string> listachiv = new List <string>(); map.GetAchievement(listachiv); if (minigame != null) { minigame.GetAchievement(listachiv); } player.GetAchievement(listachiv); score.getAchievement(listachiv); view.DrawCave(map.graph, map.isActive, map.GetDangerList(), map.danger, map.Room); if (!MiniGameEnd) { minigame.TickTime(); minigame.DrawMiniGame(view.Graphics); if (!minigame.Is_playing) { if (!minigame.Is_Winner && StoryMiniGame != StoryMG.BuyArrow && StoryMiniGame != StoryMG.BuyHint) { IsWin = false; EndGame(); } if (minigame.Is_Winner && StoryMiniGame == StoryMG.BuyHint) { int rnd = Utily.Next() % HintMessage.Count; Hint NowHint = (Hint)rnd; int HintData = 0; if (NowHint == Hint.Bat) { HintData = map.GetBat() + 1; } if (NowHint == Hint.Pit) { HintData = map.GetPit() + 1; } if (NowHint == Hint.Wumpus) { HintData = map.Wumpus + 1; } if (NowHint != Hint.NoLuck) { view.AddComand(HintMessage[(int)NowHint] + HintData, true); } else { view.AddComand(HintMessage[(int)NowHint], true); } } if (minigame.Is_Winner && StoryMiniGame == StoryMG.BuyArrow) { player.GiveArrows(); view.AddComand(Messages.GiveArrowsString, true, false); } if (minigame.Is_Winner && StoryMG.Wumpus == StoryMiniGame) { map.WumpusGoAway(); view.AddComand(Messages.WumpusRunString, true); } if (minigame.Is_Winner) { score.AddScores(50); } MiniGameEnd = true; } } else { view.DrawInterface(player.Coins, player.Arrow, map.Room, player.CanBuyArrow(), player.CanBuyHint()); } if (!CheckDanger && !view.MinimizeBat && !view.IsAnimated) { CheckDanger = true; if (map.danger == Danger.Pit) { minigame = new MiniGame(Width, Height); StoryMiniGame = StoryMG.Pit; minigame.HintText = Messages.PitHintText; minigame.InitializeMiniGame(PitDiff[Difficulty]); UseMiniGame = true; MiniGameEnd = false; } if (map.danger == Danger.Bat) { view.AddComand(Messages.MetBatString, true); map.Respaw(); } if (map.danger == Danger.Wumpus) { minigame = new MiniGame(Width, Height); StoryMiniGame = StoryMG.Wumpus; minigame.HintText = Messages.WumpusHintText; MiniGameEnd = false; UseMiniGame = true; minigame.InitializeMiniGame(WumpusDiff[Difficulty]); } Danger dangerabout = map.GetDangerAbout(); if (dangerabout == Danger.Bat) { view.AddComand(String.Format(Messages.BatWarning, map.Room + 1), true); } if (dangerabout == Danger.Pit) { view.AddComand(String.Format(Messages.PitWarning, map.Room + 1), true); } if (dangerabout == Danger.Wumpus) { string strout = String.Format(Messages.WumpusWarning, map.Room + 1); if (!player.IsShotArrow) { strout += Messages.HintRightClick; } view.AddComand(strout, true); } } if (map.IsWin && view.IsEndAnimation()) { IsWin = true; EndGame(); } else if (player.Arrow == 0 && view.IsEndAnimation()) { IsWin = false; EndGame(); } } if (state == ControlState.MainMenu) { view.DrawMainMenu(); } if (state == ControlState.PickCave) { view.DrawPickCave(MapForPiсk[numPickCave].graph, MapForPiсk[numPickCave].isActive, numPickCave, numDiff, seed); } if (time > 0) { view.DrawText((1000 / time).ToString(), 5, 5, 10, "Arial", Color.White); } if (score != null) { score.TickTime(); score.Draw(view.Graphics); } }
public View(int width, int height) { Bitmap = new System.Drawing.Bitmap(width, height); Graphics = System.Drawing.Graphics.FromImage(Bitmap); Width = width; Height = height; length = Height * 8 / 12; ConsoleList = new List <string>(); BanerTimer = new Stopwatch(); StarTimer = new Stopwatch(); StarTimer.Start(); StarX = new List <int>(); StarY = new List <int>(); StarTime = new List <int>(); //Coorinate Stars for (int i = 0; i < 200; ++i) { StarX.Add(Utily.Next() % Width); StarY.Add(Utily.Next() % Height); StarTime.Add(Utily.Next() % 200 + 100); } ArrowTimerAnimation = new Stopwatch(); normallength = length; #region setted images room[0] = new CompressionImage("data/Cave/TryTop1.png", length / 3, length / 3); room[1] = new CompressionImage("data/Cave/TryUpperLeft1.png", length / 3, length / 3); room[2] = new CompressionImage("data/Cave/TryBottomLeft1.png", length / 3, length / 3); room[3] = new CompressionImage("data/Cave/TryTop1.png", length / 3, length / 3); room[4] = new CompressionImage("data/Cave/TryUpperLeft1.png", length / 3, length / 3); room[5] = new CompressionImage("data/Cave/TryBottomLeft1.png", length / 3, length / 3); for (int i = 0; i < 6; ++i) { room[i].ScreenWidth = width; room[i].ScreenHeight = height; } CaveRoom = new CompressionImage[CountImageRoom]; for (int i = 0; i < CountImageRoom; ++i) { CaveRoom[i] = new CompressionImage("data/Cave/ColorRoom" + (i + 1) + ".png", length, length, Width, Height); } PitRoom = new CompressionImage("data/Cave/PitRoom.png", length, length, Width, Height); TypeImageRoom = new int[30]; UpdateImage(); DarkRoom = new CompressionImage("data/Cave/DarkRoom.png", length, length, Width, Height); BackGround = new CompressionImage("data/Cave/background.png", width, 120); WumpusImg = new CompressionImage("data/Cave/wumpus.png", length / 2, length / 2, Width, Height); DiffImg = new CompressionImage[3]; DiffImg[1] = new CompressionImage("./data/Sprites/Bow.png", 200, 200, Width, Height); DiffImg[2] = new CompressionImage("./data/Sprites/CrossBow.png", 200, 200, Width, Height); DiffImg[0] = new CompressionImage("./data/Sprites/Spear.png", 200, 200, Width, Height); #endregion #region setted constants // const for drawing bridge StownPosX.Add(1.0f / 3.0f - 1.0f / 70.0f); // 0 item StownPosY.Add(-1.0f / 6.0f); StownPosX.Add(0); // 1 item StownPosY.Add(1.0f / 9.0f); StownPosX.Add(0); // 2 item StownPosY.Add(1.0f / 9.0f + 1.0f / 2.0f); StownPosX.Add(StownPosX[0]); // 3 item StownPosY.Add(StownPosY[0] + 1); StownPosX.Add(StownPosX[1] + 2.0f / 3.0f); // 4 item StownPosY.Add(StownPosY[1] + 1.0f / 2.0f); StownPosX.Add(StownPosX[2] + 2.0f / 3.0f); // 5 item StownPosY.Add(StownPosY[2] - 1.0f / 2.0f); // for animation ScaleRoomX.Add(0); // 0 item ScaleRoomY.Add(-1); ScaleRoomX.Add(-0.67f); // 1 item ScaleRoomY.Add(-0.5f); ScaleRoomX.Add(-0.67f); // 2 item ScaleRoomY.Add(0.5f); ScaleRoomX.Add(0); // 3 item ScaleRoomY.Add(1); ScaleRoomX.Add(0.67f); // 4 item ScaleRoomY.Add(0.5f); ScaleRoomX.Add(0.67f); // 5 item ScaleRoomY.Add(-0.5f); #endregion MainMenuImage = Image.FromFile(@".\data\Sprites\Menu.png"); MainForm = new Form1(Drawing, width, height); MainForm.Show(); deltaY = height / 36 + 30; }
public void MouseDown(object sender, MouseEventArgs e) { if (state == ControlState.Cave && !MiniGameEnd) { minigame.Down(e); } if (state == ControlState.Cave && MiniGameEnd && view.IsEndAnimation()) { view.StopAnimation(); RegionCave rg = view.GetRegionCave(e.X, e.Y); if (rg >= 0 && (int)rg < 6 && map.isActive[map.Room][(int)rg]) { if (e.Button == MouseButtons.Left) { int WumpusRun = Utily.Next() % 8; if (WumpusRun < Difficulty) { map.WumpusGoAway(1); } int add = map.Move((int)rg); player.AddCoins(add); score.AddScores(5 * add); view.StartAddCoinAnimation(add); if (map.danger == Danger.Bat) { view.StartBatAnimation(); } view.StartMoveAnimation((int)rg); CheckDanger = false; } else { player.PushArrow(); map.PushArrow((int)rg); view.StartArrowAnimation((int)rg); List <string> achiv = new List <string>(); player.GetAchievement(achiv); score.getAchievement(achiv); } } if (rg == RegionCave.BuyArrow) { if (player.CanBuyArrow()) { StoryMiniGame = StoryMG.BuyArrow; MiniGameEnd = false; minigame = new MiniGame(Width, Height); minigame.HintText = Messages.ArrowHintText; minigame.InitializeMiniGame(ArroDiff[Difficulty]); UseMiniGame = true; player.BuyArrows(); } else { view.AddComand(string.Format(Messages.NotEnoughCoins, player.NeedForBuyArrows()), true, false); } } if (rg == RegionCave.BuyHint) { if (player.CanBuyHint()) { StoryMiniGame = StoryMG.BuyHint; MiniGameEnd = false; minigame = new MiniGame(Width, Height); minigame.HintText = Messages.HintHintText; minigame.InitializeMiniGame(HintDiff[Difficulty]); UseMiniGame = true; player.BuyHint(); } else { view.AddComand(string.Format(Messages.NotEnoughCoins, player.NeedForBuyHint()), true, false); } } if (rg == RegionCave.UpConsole) { view.ChangeIndex(1); } if (rg == RegionCave.DownConsole) { view.ChangeIndex(-1); } } if (state == ControlState.MainMenu) { RegionMenu rg = view.GetRegionMainMenu(e.X, e.Y); if (rg == RegionMenu.NewGame) { NewGame(); } if (rg == RegionMenu.Continue) { ContinueMenu(); } if (rg == RegionMenu.ScoreList) { score = new Scores(Width, Height); score.LoadLeaders(false); state = ControlState.ScoreList; } if (rg == RegionMenu.Exit) { Application.Exit(); } } if (state == ControlState.PickCave) { RegionPickCave rg = view.GetRegionPickCave(e.X, e.Y); int Intrg = (int)rg; if (Intrg < 5) { numPickCave = Intrg; } if (Intrg >= (int)RegionPickCave.Diff1 && Intrg <= (int)RegionPickCave.Diff3) { numDiff = Intrg - (int)RegionPickCave.Diff1; } if (rg == RegionPickCave.Play) { StartAfterPick(); } } }