/*Eliasz Zurawka * Multi Teir Prog II * Assignment One * Oct 30 2007 */ using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; namespace elLander { public partial class elLander : Form { private int dx = 0, dy = 0; private int fuel = 600; private bool doneGame = false; public elLander() { InitializeComponent(); } private void timer1_Tick(object sender, EventArgs e) { int newX, newY; if (dx > 0) dx = dx - 15; else if (dx < 0) dx = dx + 15; dy = dy + 35; newX = shipPic.Location.X + (dx / 100); newY = shipPic.Location.Y + (dy / 100); Point newSpot = new Point(newX, newY); shipPic.Location = newSpot; shipPic.Image = shipList.Images[0]; speedHor.Text = dx.ToString(); speedVert.Text = (-dy).ToString(); int currX = shipPic.Location.X; if ((shipPic.Location.X > 410) & (shipPic.Location.Y > 226) & (shipPic.Location.X < 460) & (shipPic.Location.Y < 235)) { if (dy < 450 & ((dx > -250) & (dx < 250))) { finishLabel.Text = "YOU WIN!"; gameTimer.Enabled = false; doneGame = true; ResetButton.Visible = true; } else { finishLabel.Text = "YOU CRASHED!"; gameTimer.Enabled = false; doneGame = true; ResetButton.Visible = true; } } else if (shipPic.Location.Y > 250) { finishLabel.Text = "YOU CRASHED!"; gameTimer.Enabled = false; doneGame = true; ResetButton.Visible = true; } else if (currX < 0 || currX > 540) { if((currX < 4 && dx < 0) || (currX > 525 && dx > 0)) dx = -dx; } else if (shipPic.Location.Y < -600) { finishLabel.Text = "You Flew too Far!"; gameTimer.Enabled = false; doneGame = true; ResetButton.Visible = true; } } private void Form1_KeyDown(object sender, KeyEventArgs e) { horzLabel.Text = doneGame.ToString(); if (fuel > 0 & !doneGame) { gameTimer.Enabled = true; switch (e.KeyCode) { case Keys.Right: shipPic.Image = shipList.Images[2]; if (dx < 600) dx = dx + 50; break; case Keys.Left: shipPic.Image = shipList.Images[3]; if (dx > -600) dx = dx - 50; break; case Keys.Up: shipPic.Image = shipList.Images[1]; if (dy > -1000) dy = dy - 55; break; } fuelAmountLabel.Text = (--fuel).ToString(); } } private void ResetButton_Click(object sender, EventArgs e) { fuel = 600; fuelAmountLabel.Text = (fuel).ToString(); dx = 0; dy = 0; speedHor.Text = dx.ToString(); speedVert.Text = (-dy).ToString(); Point newSpot = new Point(29, 213); shipPic.Location = newSpot; doneGame = false; finishLabel.Text = ""; ResetButton.Visible = false; //gameTimer.Start(); } } }