private void BossStage_KeyPress(object sender, KeyPressEventArgs e) { try { PictureBox pl2 = new PictureBox(); if (pause2 == 1) { this.Controls.Add(pl2); } if (count4 == 0 && pause == 0 && pause2 == 0) { Thread thread = new Thread(Fall); thread.Start(); if (e.KeyChar == 'd') { walk = 1; if (count3 == 0) { megasprite.Image = Image.FromFile("C:\\Users\\dania\\Pictures\\megawalk-right.gif"); } if (count3 == 1) { x = x + 5; } else { x = x + 3; } megasprite.Location = new System.Drawing.Point(x, y); count = 1; if (x > 851 && y < 165 && e1dead == 1) { for (int i = 0; i < 50; i++) { x = x + 3; System.Threading.Thread.Sleep(100); megasprite.Location = new System.Drawing.Point(x, y); } Stage2 st = new Stage2(); this.Hide(); st.ShowDialog(); this.Close(); } if (delay == 0) { Thread ts = new Thread(Delay); ts.Start(); } walk = 0; //if (count3 == 0) { // megasprite.Image = Image.FromFile("C:\\Users\\dania\\Pictures\\megastand.png"); //} } if (e.KeyChar == 'a') { walk = 1; if (count3 == 0) { megasprite.Image = Image.FromFile("C:\\Users\\dania\\Pictures\\megawalk.gif"); } if (count3 == 1) { x = x - 5; } else { x = x - 3; } megasprite.Location = new System.Drawing.Point(x, y); count = 0; if (delay == 0) { Thread ts = new Thread(Delay); ts.Start(); } walk = 0; } else if (e.KeyChar == 'w' && count3 == 0) { Thread thread1 = new Thread(MoveUp); thread1.Start(); } else if (pause2 == 1 && e.KeyChar == 's') { pb.Image = Image.FromFile("C:\\Users\\dania\\Pictures\\Game Over-2.png"); pause++; } else if (pause2 == 1 && e.KeyChar == 'l') { tries--; this.Hide(); if (tries != 0) { BossStage fm = new BossStage(); fm.ShowDialog(); } else { } this.Close(); } else if (pause2 == 2 && e.KeyChar == 'w') { pb.Image = Image.FromFile("C:\\Users\\dania\\Pictures\\Game-Over.png"); pause--; } else if (e.KeyChar == 'p') { pause = 1; pb.Location = new System.Drawing.Point(360, 140); pb.Size = new Size(274, 304); pb.Image = Image.FromFile("C:\\Users\\dania\\Pictures\\Pause_Resume.png"); megasprite.Visible = false; Enemy1.Visible = false; this.Controls.Add(pb); } else if (e.KeyChar == 'l') { Fire(); } } if (pause == 1 && e.KeyChar == 's') { pb.Image = Image.FromFile("C:\\Users\\dania\\Pictures\\Pause_Save.png"); pause++; } else if (pause == 2 && e.KeyChar == 's') { pb.Image = Image.FromFile("C:\\Users\\dania\\Pictures\\Pause_Quit.png"); pause++; } else if (pause == 3 && e.KeyChar == 'w') { pb.Image = Image.FromFile("C:\\Users\\dania\\Pictures\\Pause_Save.png"); pause--; } else if (pause == 2 && e.KeyChar == 'w') { pb.Image = Image.FromFile("C:\\Users\\dania\\Pictures\\Pause_Resume.png"); pause--; } else if (pause == 1 && e.KeyChar == 'l') { pause = 0; megasprite.Visible = true; Enemy1.Visible = true; this.Controls.Remove(pb); } else if (pause == 2 && e.KeyChar == 'l') { Save(); } else if (pause == 3 && e.KeyChar == 'l') { this.Close(); } else if (pause2 == 1 && e.KeyChar == 's') { pl2.Image = Image.FromFile("C:\\Users\\dania\\Pictures\\Game Over-2.png"); pause2++; } else if (pause2 == 1 && e.KeyChar == 'l') { tries--; this.Hide(); if (tries != 0) { Form1 fm = new Form1(3); fm.ShowDialog(); } else { } this.Close(); } else if (pause2 == 2 && e.KeyChar == 'w') { pl2.Image = Image.FromFile("C:\\Users\\dania\\Pictures\\Game-Over.png"); pause2--; } else if (pause2 == 2 && e.KeyChar == 'l') { this.Close(); } } catch (Exception ex) { MessageBox.Show(ex.Message); } }
private void MainMenu_KeyPress(object sender, KeyPressEventArgs e) { if (e.KeyChar == 's' && cursor < 3) { cursor++; cy = cy + 40; pictureBox2.Location = new System.Drawing.Point(cx, cy); } else if (e.KeyChar == (char)Keys.Enter && cursor == 2) { Form1 fm = new Form1(); this.Hide(); fm.ShowDialog(); this.Close(); } else if (e.KeyChar == 'w' && cursor > 1) { cursor--; cy = cy - 40; pictureBox2.Location = new System.Drawing.Point(cx, cy); } else if (cursor == 1 && e.KeyChar == (char)Keys.Enter) { int count = 0; string temp = ""; int life = 0; int energy = 0; int time = 0; int tries = 0; int stage = 0; int e1dead = 0; int x = 0; int y = 0; int ex = 0; int ey = 0; try { string Filename = "C:\\Users\\dania\\Desktop\\GameSave.xml"; XmlTextReader RD = new XmlTextReader(Filename); while (RD.Read()) { if (RD.NodeType == XmlNodeType.Element) { if (RD.LocalName.Equals("Life")) { temp = RD.ReadString(); life = Convert.ToInt32(temp); count++; } if (RD.LocalName.Equals("Energy")) { temp = RD.ReadString(); energy = Convert.ToInt32(temp); count++; } if (RD.LocalName.Equals("Time")) { temp = RD.ReadString(); time = Convert.ToInt32(temp); count++; } if (RD.LocalName.Equals("Tries")) { temp = RD.ReadString(); tries = Convert.ToInt32(temp); count++; } if (RD.LocalName.Equals("PlayerLocationX")) { temp = RD.ReadString(); x = Convert.ToInt32(temp); count++; } if (RD.LocalName.Equals("PlayerLocationY")) { temp = RD.ReadString(); y = Convert.ToInt32(temp); count++; } if (RD.LocalName.Equals("EnemnyLocationX")) { temp = RD.ReadString(); ex = Convert.ToInt32(temp); count++; } if (RD.LocalName.Equals("EnemnyLocationY")) { temp = RD.ReadString(); ey = Convert.ToInt32(temp); count++; } if (RD.LocalName.Equals("Stage")) { temp = RD.ReadString(); stage = Convert.ToInt32(temp); count++; } if (RD.LocalName.Equals("EnemnyDead")) { temp = RD.ReadString(); e1dead = Convert.ToInt32(temp); count++; } } } } catch (Exception ep) { MessageBox.Show(ep.Message); } Console.ReadLine(); if (count == 10) { MessageBox.Show("Load Sucessful"); } else { MessageBox.Show("not Sucessful"); } if (stage == 1) { Form1 f1 = new Form1(life, energy, x, y, ex, ey, time, tries); this.Hide(); f1.ShowDialog(); this.Close(); } else if (stage == 2) { Stage2 f1 = new Stage2(life, energy, x, y, ex, ey, time, e1dead, tries); this.Hide(); f1.ShowDialog(); this.Close(); } else if (stage == 3) { BossStage f1 = new BossStage(); this.Hide(); f1.ShowDialog(); this.Close(); } } }