public bool IsExistLet(LevelAbstract level, ref Label levelNum, ref PictureBox cat1, ref PictureBox cat2) { if (level.ExistLet(cat1, cat2) && (ruinBlock3 || ruinBlock4)) { return(false); } if (stayOnLet1 || stayOnLet2) { return(false); } return(level.ExistLet(cat1, cat2)); }
public void Jump(ref PictureBox Cat1, ref PictureBox Cat2, int width, ref bool complette, ref PictureBox CatStay, ref bool stop, int materialInt) { int x = 5; //число на которое увеличиваем X int y = -7; if (!level.completteLevel1(Cat1, Cat2)) { if (level.levelLabel().Equals("Level II")) { if (level.ExistLet(Cat1, Cat2)) { CatStay.Visible = false; stayOnLet1 = true; for (int i = 0; i < 5; i++) { if (flag) { Cat1.Visible = true; Cat2.Visible = false; Cat1.Left += x; Cat2.Left += x; Cat1.Top += y; Cat2.Top += y; flag = false; } else { Cat2.Visible = true; Cat1.Visible = false; Cat1.Left += x; Cat2.Left += x; Cat1.Top += y; Cat2.Top += y; flag = true; } Wait(0.1); x += 9; if (i < 2) { y = -30; } if (i == 2) { y = 0; } } } } else if (level.levelLabel().Equals("Level III")) { if (level.ExistLet(Cat1, Cat2)) { y = 0; x = 0; CatStay.Visible = false; for (int i = 0; i < 4; i++) { if (flag) { Cat1.Visible = true; Cat2.Visible = false; Cat1.Top += y; Cat2.Top += y; flag = false; } else { Cat2.Visible = true; Cat1.Visible = false; Cat1.Top += y; Cat2.Top += y; flag = true; } Wait(0.1); if (i < 2) { y -= 10; } if (i >= 2) { y += 45; } } CatStay.Location = Cat1.Location; CatStay.Location = Cat2.Location; Cat1.Visible = false; Cat2.Visible = false; CatStay.Visible = true; return; } } else if (level.levelLabel().Equals("Level IV")) { if (materialInt == 1 && level.ExistLet(Cat1, Cat2)) //Если препятствие каменное, то перепрыгиваем его { CatStay.Visible = false; stayOnLet2 = true; for (int i = 0; i < 5; i++) { if (flag) { Cat1.Visible = true; Cat2.Visible = false; Cat1.Left += x; Cat2.Left += x; Cat1.Top += y; Cat2.Top += y; flag = false; } else { Cat2.Visible = true; Cat1.Visible = false; Cat1.Left += x; Cat2.Left += x; Cat1.Top += y; Cat2.Top += y; flag = true; } Wait(0.1); x += 9; if (i < 2) { y = -30; } if (i == 2) { y = 0; } } } else if (materialInt == 2 && level.ExistLet(Cat1, Cat2)) //Если препятствие - деревянное, прыгаем на месте { y = 0; x = 0; CatStay.Visible = false; for (int i = 0; i < 4; i++) { if (flag) { Cat1.Visible = true; Cat2.Visible = false; Cat1.Top += y; Cat2.Top += y; flag = false; } else { Cat2.Visible = true; Cat1.Visible = false; Cat1.Top += y; Cat2.Top += y; flag = true; } Wait(0.1); if (i < 2) { y -= 10; } if (i >= 2) { y += 45; } } CatStay.Location = Cat1.Location; CatStay.Location = Cat2.Location; Cat1.Visible = false; Cat2.Visible = false; CatStay.Visible = true; return; } } if (!level.ExistLet(Cat1, Cat2)) { CatStay.Visible = false; for (int i = 0; i < 5; i++) { if (flag) { Cat1.Visible = true; Cat2.Visible = false; Cat1.Left += x; Cat2.Left += x; Cat1.Top += y; Cat2.Top += y; flag = false; } else { Cat2.Visible = true; Cat1.Visible = false; Cat1.Left += x; Cat2.Left += x; Cat1.Top += y; Cat2.Top += y; flag = true; } Wait(0.1); x += 2; if (i < 2) { y -= 5; } if (i == 2) { y += 30; } if (i > 2) { y += 10; } } } } CatStay.Location = Cat1.Location; CatStay.Visible = true; Cat1.Visible = false; Cat2.Visible = false; complette = level.completteLevel1(Cat1, Cat2); }
private void buttonRun_Click(object sender, EventArgs e) { labelNextLevel.Visible = false; if (labelLevel.Text.Equals("Level III")) { holzBlock.Visible = true; } clickStop = false; labelLevelComplette.Visible = false; pictureBox1.Image = GameKitten_sAdventure.Properties.Resources.diamant2; contr.ReturnBeginPosition(ref CatStay, this.Width); contr.ReturnBeginPosition(ref Cat1, this.Width); contr.ReturnBeginPosition(ref Cat2, this.Width); int materialIntIf = 0; string command; String[] s = textBox1.Text.Split(new String[] { "\r\n" }, StringSplitOptions.RemoveEmptyEntries); labelINFO.Visible = true; labelINFO.Text = ""; bool complette = false; for (int i = 0; i < s.Length; i++) { command = ""; materialIntIf = 0;//неизвестно, какой материал if (!complette || !clickStop) { //if (...) then Regex regexIf = new Regex(@"if\s*\(\s*(wooden block|stone block)\s*\)\sthen\s*[A-Z|a-z|;|(|)]*$", RegexOptions.IgnoreCase); //if (...) then ... else ... Regex regexIfElse = new Regex(@"if\s*\(\s*(wooden block|stone block)\s*\)\s*then\s*[A-Z|a-z|;|(|)]*\s*else\s*[A-Z|a-z|;|(|)]*", RegexOptions.IgnoreCase); //while (...) do { ... } Regex regexWhile = new Regex(@"while\s*\(\s*(free)\s*\)\s*do\s*{", RegexOptions.IgnoreCase); s[i] = s[i].ToLower(); //s[i] = s[i].Replace(" ", ""); if (regexIf.IsMatch(s[i])) { int begPos = s[i].IndexOf("then"); int endPos = s[i].IndexOf(';'); int length = endPos - begPos - 4; int temp = 0; command = ""; //Команда, выполняемая, если условие выполнено for (int j = begPos + 5; j < endPos; j++) { if (char.IsLetter(s[i][j])) { command = s[i].Substring(j, length - temp); break; } temp++; } Match match = regexIf.Match(s[i]); if (match.Groups[1].Value == "wooden block") { materialIntIf = 2; } if (match.Groups[1].Value == "stone block") { materialIntIf = 1; } if (level.GetMaterial() == materialIntIf) { DoIt(command, materialIntIf, ref complette, ref clickStop); } } else if (regexIfElse.IsMatch(s[i])) { int posThen = s[i].IndexOf("then"); int posElse = s[i].IndexOf("else"); string commandThen = s[i].Substring(posThen + 5, posElse - posThen - 6); string commandElse = s[i].Substring(posElse + 5, s[i].Length - posElse - 5); int begPosCond = s[i].IndexOf("("); int endPosCond = s[i].IndexOf(")"); string condition = s[i].Substring(begPosCond + 1, endPosCond - begPosCond - 1); if (condition == "wooden block") { materialIntIf = 2; } if (condition == "stone block") { materialIntIf = 1; } //labelINFO.Text = commandThen +" " + commandElse; if (level.GetMaterial() == materialIntIf) //Если условие выполняется, то выполняем команду после then { DoIt(commandThen, materialIntIf, ref complette, ref clickStop); } else //иначе после else { DoIt(commandElse, materialIntIf, ref complette, ref clickStop); } } else if (regexWhile.IsMatch(s[i])) { int begPos = s[i].IndexOf("{"); int endPos = s[i].IndexOf("}"); string allComand = s[i].Substring(begPos + 1, endPos - begPos - 1); char[] delimiter = { ' ' }; string[] commands = allComand.Split(delimiter, StringSplitOptions.RemoveEmptyEntries); int begPosCond = s[i].IndexOf("("); int endPosCond = s[i].IndexOf(")"); string condition = s[i].Substring(begPosCond + 1, endPosCond - begPosCond - 1); condition = condition.Replace(" ", ""); materialIntIf = 0; if (condition == "free") { while (!clickStop && !contr.IsExistLet(level, ref labelLevel, ref Cat1, ref Cat2) && !contr.IsExistDiamond(level, ref labelLevel, ref Cat1, ref Cat2)) // while (!clickStop && !contr.IsExistDiamond(level, ref labelLevel, ref Cat1, ref Cat2)) { for (int j = 0; j < commands.Length; j++) { // if (!clickStop && !contr.IsExistDiamond(level, ref labelLevel, ref Cat1, ref Cat2)) if (!clickStop && !contr.IsExistLet(level, ref labelLevel, ref Cat1, ref Cat2) && !contr.IsExistDiamond(level, ref labelLevel, ref Cat1, ref Cat2)) { commands[j] = commands[j].Replace(" ", ""); DoIt(commands[j], materialIntIf, ref complette, ref clickStop); } } } CatStay.Location = Cat1.Location; CatStay.Location = Cat2.Location; Cat1.Visible = false; Cat2.Visible = false; CatStay.Visible = true; if (labelLevel.Text.Equals("Level IV")) { if (level.ExistLet(Cat1, Cat2) && !contr.GetRuinBlock4()) { Random rnd = new Random(); int materialInt = rnd.Next(1, 3); ChangeMagicBlock(materialInt); level.SetMaterial(materialInt); } } } } else { DoIt(s[i], materialIntIf, ref complette, ref clickStop); } } } if (complette) { ClassSound.playWin(); pictureBox1.Image = GameKitten_sAdventure.Properties.Resources.diamantComplette; labelLevelComplette.Visible = true; labelNextLevel.Visible = true; if (labelLevel.Text.Equals("Level IV")) { labelNextLevel.Text = "Следующие уровни - скоро!"; } } CatStay.Location = Cat1.Location; CatStay.Location = Cat2.Location; Cat1.Visible = false; Cat2.Visible = false; CatStay.Visible = true; }