Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Drawing;
- using System.Linq;
- using System.Text;
- using System.Windows.Forms;
- using System.Drawing.Drawing2D;
- using System.IO;
- using System.Reflection;
- using System.Diagnostics;
- namespace Spillet
- {
- public partial class Form2 : Form
- {
- private bool ActiveTorpedo = false;
- int t = 450;
- bool[] h;
- string[] k;
- Baat Ubaaten;
- Torpedo Torpedoen;
- Battleship[] Battleshipen = new Battleship[10];
- Battleship dust = new Battleship();
- public Form2()
- {
- InitializeComponent();
- Assembly myAssembly = Assembly.GetExecutingAssembly();
- }
- private void Form2_Load(object sender, EventArgs e)
- {
- this.Ubaaten = new Baat();
- this.Controls.Add(this.Ubaaten);
- this.Torpedoen = new Torpedo();
- this.Controls.Add(this.Torpedoen);
- h = new bool[10];
- k = new string[10];
- this.Controls.Add(this.dust);
- for (int i = 0; i < 10; i++)
- {
- this.Controls.Add(this.Battleshipen[i]);
- //h[i] = false;
- //Debug.WriteLine("h[i] er " + h[i]);
- //if (h[i] == false)
- //{
- // k[i] = "false";
- // Debug.WriteLine("k[i] er " + h[i]);
- //}
- //else
- //{
- // k[i] = "true";
- // Debug.WriteLine("k[i] er " + h[i]);
- //}
- }
- timer2.Enabled = true;
- }
- private void Form2_KeyDown(object sender, KeyEventArgs e)
- {
- int ubaatposisjon = Ubaaten.Location.X;
- switch (e.KeyData)
- {
- case Keys.Up:
- if (ActiveTorpedo == false)
- {
- t = 450;
- Torpedoen.Location = new System.Drawing.Point(ubaatposisjon, t);
- ActiveTorpedo = true;
- this.Refresh();
- }
- break;
- case Keys.Down:
- // hmm
- this.Refresh();
- break;
- case Keys.Left:
- if (ubaatposisjon - 50 >= 0)
- {
- Ubaaten.Location = new Point(ubaatposisjon -= 20, 450);
- this.Refresh();
- }
- break;
- case Keys.Right:
- if (ubaatposisjon + 20 < 530)
- {
- Ubaaten.Location = new Point(ubaatposisjon += 20, 450);
- this.Refresh();
- }
- break;
- }
- }
- private void timer1_Tick(object sender, EventArgs e)
- {
- t = t - 6;
- Torpedoen.Location = new System.Drawing.Point(Torpedoen.Location.X, t);
- if (Torpedoen.Location.Y <= 0)
- {
- ActiveTorpedo = false;
- }
- this.Invalidate();
- }
- private void timer2_Tick(object sender, EventArgs e)
- {
- Random hih = new Random();
- int tilfeldig = hih.Next(0, 9);
- Debug.WriteLine("tilfeldig er " + tilfeldig);
- //if (h[tilfeldig] == false)
- //{
- Battleshipen[tilfeldig].Enabled = true;
- //}
- }
- }
- }
- _________________________Battleship Klassen___________________________
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Drawing;
- using System.Windows.Forms;
- using System.IO;
- using System.Reflection;
- using System.Timers;
- using System.Diagnostics;
- namespace Spillet
- {
- class Battleship : PictureBox
- {
- private Assembly assembly;
- private Stream stream;
- int p = 0;
- int x = 0;
- System.Timers.Timer t = new System.Timers.Timer();
- public Battleship()
- {
- assembly = Assembly.GetExecutingAssembly();
- stream = assembly.GetManifestResourceStream("Spillet.Battleship.gif");
- this.Image = Image.FromStream(stream);
- this.Width = 90;
- this.Height = 60;
- this.Location = new Point(100, p);
- this.Enabled = false;
- this.Visible = true;
- this.SizeMode = PictureBoxSizeMode.StretchImage;
- Debug.WriteLine("Battleship() er igang");
- sup();
- }
- public Battleship(int p)
- {
- int[] placement = new int[7];
- placement[0] = 20;
- placement[1] = 60;
- placement[2] = 100;
- placement[3] = 140;
- placement[4] = 180;
- placement[5] = 220;
- placement[6] = 260;
- Random random = new Random();
- int hm = random.Next(0, 6);
- p = placement[hm];
- }
- public void flytt(object source, ElapsedEventArgs e)
- {
- //if (this.Location.X >= -101)
- //{
- Debug.WriteLine("flytt() er igang");
- x = x + 5;
- this.Location = new System.Drawing.Point(this.Location.X + x, this.Location.Y);
- //}
- }
- public void sup()
- {
- Debug.WriteLine("sup() er igang");
- t.Elapsed += new ElapsedEventHandler(flytt);
- t.Interval = 500;
- t.Enabled = true;
- }
- }
- }
Add Comment
Please, Sign In to add comment