Advertisement
Guest User

Untitled

a guest
Jan 30th, 2019
161
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.93 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9. using System.Windows.Forms;
  10.  
  11. namespace _01_30_2019
  12. {
  13.     public partial class Form1 : Form
  14.     {
  15.         public Form1()
  16.         {
  17.             InitializeComponent();
  18.            
  19.         }
  20.  
  21.        
  22.         class Ship
  23.         {
  24.             private double ship_posX; // position X on map
  25.             private double ship_posY; // position Y on map
  26.             private int ship_heading; // current heading
  27.             private int ship_speed_max; // max speed of a ship
  28.             private int ship_current_speed; // current speed of a ship
  29.             private string ship_class; // surface or submarine
  30.             private string ship_foe; // friend or enemy?
  31.             private string is_controllable; // is controllable by player?
  32.             private int depth; // current depth of a submarine (if a submarine)
  33.  
  34.             public void move(int heading, int speed)
  35.             {
  36.                 if (heading == 0)  ship_posY -= speed; // ship is heading NORTH
  37.                 if (heading == 45) // ship is heading NORTH-EAST
  38.                 {
  39.                     ship_posX += speed;
  40.                     ship_posY -= speed;
  41.                 }
  42.                 if (heading == 90) ship_posX += speed; // ship is heading EAST
  43.                 if (heading == 135) // ship is heading SOUTH-EAST
  44.                 {
  45.                     ship_posX += speed;
  46.                     ship_posY += speed;
  47.                 }
  48.                 if (heading == 180) ship_posY += speed; // ship is heading SOUTH
  49.                 if (heading == 225) // ship is heading SOUTH-WEST
  50.                 {
  51.                     ship_posX -= speed;
  52.                     ship_posY += speed;
  53.                 }
  54.                 if (heading == 270) ship_posX -= speed; // ship is heading WEST
  55.                 if (heading == 315) // ship is heading NORTH-WEST
  56.                 {
  57.                     ship_posX -= speed;
  58.                     ship_posY -= speed;
  59.                 }
  60.             }
  61.  
  62.             public void create_ship(double posx, double posy)
  63.             {
  64.                 ship_posX = posx;
  65.                 ship_posY = posy;
  66.                 // only a few parameters for now. Later will be name, speed_max, class, friend or foe and more
  67.             }
  68.  
  69.         }
  70.  
  71.         private void Form1_Load(object sender, EventArgs e)
  72.         {
  73.             // forms load == game starts
  74.  
  75.             Ship[] submarine = new Ship[100];
  76.             submarine[0].create_ship(140, 200); // create first ship with only two parameters: position X and Y on future map
  77.         }
  78.  
  79.         private void timer1_Tick(object sender, EventArgs e)
  80.         {
  81.             submarine[0].move(90, 15); // ERROR: compiler shows "The name 'submarine' does not exist in the current context
  82.         }
  83.     }
  84. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement