- •Курсова робота
- •Завдання
- •1.1 Принцип дії
- •1.2 Особливості технології
- •1.2 Використання gps - навігаторів
- •2 Проектувальна частина
- •2.1 Постановка задачі
- •2.2 Вибір засобів створення ме
- •2.3 Розробка компонент ме
- •Висновки
- •Список використаних літературних джерел та посилань
- •Додаток 1. Лістинг програми
Додаток 1. Лістинг програми
Файл Form1.cs
//--------------------------------------------------------------------------
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace MultSyst
{
public partial class Form1 : Form
{
int waycount;
bool firstMove = true;
Point[] map;
Point[] ways;
const int STREET_LENGTH = 20;
int timeCar = 1;
int timeDirection = 1;
Point carPos;
Point nextPos;
int nextIndex;
int moveDir;
public Form1()
{
InitializeComponent();
pictureBox1.Image = new Bitmap(pictureBox1.Width, pictureBox1.Height);
makeMap();
drawMap(Color.Black);
//Load Pictures To Instruction
}
private void makeWay(int way)
{
if (way==1)
{
ways = new Point[24];
ways[0] = new Point(20, 340);
// Other point of way
ways[23] = new Point(300, 320);
}
else if (way == 2)
{
ways = new Point[27];
ways[0] = new Point(100, 20);
// Other point of way
ways[26] = new Point(60, 200);
}
}
private void makeMap()
{
map = new Point[134];
map[0] = new Point(100,0);
map[1] = new Point(100, 20);
// Other point of map
map[132] = new Point(280, 320);
map[133] = new Point(280, 340);
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void drawCar(Point pos, int time)
{
Graphics G = Graphics.FromImage(pictureBox1.Image);
SolidBrush myBrush = new SolidBrush(System.Drawing.Color.Black);
G.FillEllipse(myBrush, pos.X - 6, pos.Y - 6, 12, 12);
Pen blackPen = new Pen(Color.Yellow, 3);
G.DrawEllipse(blackPen, pos.X - 6 - 4 * time, pos.Y - 6 - 4 * time, 12 + 8 * time, 12 + 8 * time);
}
private void drawMap(Color color)
{
Graphics G = Graphics.FromImage(pictureBox1.Image);
G.Clear(Color.White);
Pen blackPen = new Pen(color, 3);
for (int i = 0; i < 133; i=i+2)
{
Point point1 = map[i];
Point point2 = map[i+1];
G.DrawLine(blackPen, point1, point2);
}
pictureBox1.Invalidate();
}
private void drawWay(int way)
{
Graphics G = Graphics.FromImage(pictureBox1.Image);
Pen blackPen = new Pen(Color.Green, 3);
for (int i = 0; i < way; i++)
{
Point point1 = ways[i];
Point point2 = ways[i + 1];
G.DrawLine(blackPen, point1, point2);
if (i == 0)
{
SolidBrush myBrush = new SolidBrush(System.Drawing.Color.Red);
G.FillEllipse(myBrush, ways[i].X - 6, ways[i].Y - 6, 12, 12);
}
if (i == way-1)
{
SolidBrush myBrush = new SolidBrush(System.Drawing.Color.Red);
G.FillEllipse(myBrush, ways[i+1].X - 6, ways[i+1].Y - 6, 12, 12)
}
}
pictureBox1.Invalidate();
}
private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
timer1.Enabled = false;
button1.Enabled = true;
button1.Text = "Почати рух";
firstMove = true;
if(comboBox1.SelectedIndex==0)
{
drawMap(Color.Gray);
makeWay(1);
drawWay(23);
waycount = 2;
}
else if (comboBox1.SelectedIndex == 1)
{
drawMap(Color.Gray);
makeWay(2);
drawWay(26);
waycount = 26;
}
}
private void showInf()
{
if (nextIndex != waycount+1)
{
int direction = 0;
int nextMoveDir = 0;
int timeTo = -1;
if (carPos == nextPos)
{
timeTo = 0;
if (carPos.X > ways[nextIndex].X)
nextMoveDir = 1;//left
else if (carPos.X < ways[nextIndex].X)
nextMoveDir = 2;//right
else if (carPos.Y < ways[nextIndex].Y)
nextMoveDir = 3;//bottom
else if (carPos.Y > ways[nextIndex].Y)
nextMoveDir = 4;//top
button1_Click(null, null);
}
else if (Math.Abs(carPos.X - nextPos.X) == 10 || Math.Abs(carPos.Y - nextPos.Y) == 10)
{
if (ways[nextIndex - 1].X > ways[nextIndex].X)
nextMoveDir = 1;//left
else if (ways[nextIndex - 1].X < ways[nextIndex].X)
nextMoveDir = 2;//right
else if (ways[nextIndex - 1].Y < ways[nextIndex].Y)
nextMoveDir = 3;//bottom
else if (ways[nextIndex - 1].Y > ways[nextIndex].Y)
nextMoveDir = 4;//top
timeTo = 50;
button1_Click(null,null);
}
if ((nextMoveDir == 2 && moveDir == 4) || (nextMoveDir == 1 && moveDir == 3) || (nextMoveDir == 3 && moveDir == 2) || (nextMoveDir == 4 && moveDir == 1))
direction = 2;
else if ((nextMoveDir == 2 && moveDir == 3) || (nextMoveDir == 1 && moveDir == 4) || (nextMoveDir == 3 && moveDir == 1) || (nextMoveDir == 4 && moveDir == 2))
direction = 1;
if (timeTo == 0)
{
if (direction == 2)
{
pictureBox2.Load("right.jpg");
richTextBox1.Text = "У даному випадку потрібно повернути праворуч негайно.";
System.Media.SoundPlayer sp = new System.Media.SoundPlayer(Properties.Resources.right);
sp.Play();
}
else if (direction == 1)
{
pictureBox2.Load("left.jpg");
richTextBox1.Text = "У даному випадку потрібно повернути ліворуч негайно.";
System.Media.SoundPlayer sp = new System.Media.SoundPlayer(Properties.Resources.left);
sp.Play();
}
}
else if (timeTo == 50)
{
if (direction == 2)
{
richTextBox1.Text = "У даному випадку потрібно приготуватися до повороту праворуч. Згідно маршруту поворот буде через 50 метрів.";
System.Media.SoundPlayer sp = new System.Media.SoundPlayer(Properties.Resources.right50);
sp.Play();
}
else if (direction == 1)
{
richTextBox1.Text = "У даному випадку потрібно приготуватися до повороту ліворуч. Згідно маршруту поворот буде через 50 метрів.";
System.Media.SoundPlayer sp = new System.Media.SoundPlayer(Properties.Resources.left50);
sp.Play();
}
}
pictureBox2.SizeMode = PictureBoxSizeMode.Zoom;
}
}
private void timer1_Tick(object sender, EventArgs e)
{
if (timeCar < 3)
timeCar++;
else timeCar = 1;
if (carPos != nextPos)
{
if (carPos.X - nextPos.X > 0)
carPos.X--;
else if (carPos.X - nextPos.X < 0)
carPos.X++;
if (carPos.Y - nextPos.Y > 0)
carPos.Y--;
else if (carPos.Y - nextPos.Y < 0)
carPos.Y++;
}
else
{
if (nextIndex != waycount+1)
{
nextPos = ways[nextIndex];
nextIndex++;
timeDirection = 1;
if (carPos.X > nextPos.X)
moveDir = 1;//left
else if (carPos.X < nextPos.X)
moveDir = 2;//right
else if (carPos.Y < nextPos.Y)
moveDir = 3;//bottom
else if (carPos.Y > nextPos.Y)
moveDir = 4;//top
pictureBox2.Image = null;
}
}
showInf();
if (comboBox1.SelectedIndex == 0)
{
drawMap(Color.Gray);
makeWay(1);
drawWay(23);
}
else if (comboBox1.SelectedIndex == 1)
{
drawMap(Color.Gray);
makeWay(2);
drawWay(26);
}
drawCar(carPos, timeCar);
}
private void button1_Click(object sender, EventArgs e)
{
if (button1.Text == "Почати рух")
{
richTextBox1.Text = "";
if (firstMove)
{
button1.Text = "Зупинити";
timer1.Enabled = true;
carPos = ways[0];
nextPos = ways[1];
nextIndex = 2;
firstMove = false;
if (carPos.X>nextPos.X)
moveDir = 1;//left
else if (carPos.X < nextPos.X)
moveDir = 2;//right
else if (carPos.Y < nextPos.Y)
moveDir = 3;//bottom
else if (carPos.Y > nextPos.Y)
moveDir = 4;//top
}
else
{
timer1.Enabled = true;
button1.Text = "Зупинити";
}
}
else
{
timer1.Enabled = false;
button1.Text = "Почати рух";
}
}
private void головнаToolStripMenuItem_Click(object sender, EventArgs e)
{
panel2.BringToFront();
}
private void прикладToolStripMenuItem_Click(object sender, EventArgs e)
{
panel1.BringToFront();
}
private void глосарійToolStripMenuItem_Click(object sender, EventArgs e)
{
panel3.BringToFront();
label9_Click(null, null);
}
private void label11_Click(object sender, EventArgs e)
{
panel1.BringToFront();
}
private void label12_Click(object sender, EventArgs e)
{
panel3.BringToFront();
label9_Click(null,null);
}
private void label9_Click(object sender, EventArgs e)
{
label14.Font = new Font(label14.Font.Name, label14.Font.Size, FontStyle.Underline);
label14.ForeColor = Color.Blue;
label15.Font = new Font(label15.Font.Name, label15.Font.Size, FontStyle.Underline);
label15.ForeColor = Color.Blue;
label13.Font = new Font(label13.Font.Name, label13.Font.Size, FontStyle.Underline);
label13.ForeColor = Color.Blue;
label9.Font = new Font(label9.Font.Name, label9.Font.Size, FontStyle.Regular);
label9.ForeColor = Color.Black;
richTextBox2.Clear();
String[] text = new String [2];
//TEXT
richTextBox2.Lines = text;
}
private void label13_Click(object sender, EventArgs e)
{
label9.Font = new Font(label9.Font.Name, label9.Font.Size, FontStyle.Underline);
label9.ForeColor = Color.Blue;
label14.Font = new Font(label14.Font.Name, label14.Font.Size, FontStyle.Underline);
label14.ForeColor = Color.Blue;
label15.Font = new Font(label15.Font.Name, label15.Font.Size, FontStyle.Underline);
label15.ForeColor = Color.Blue;
label13.Font = new Font(label13.Font.Name, label13.Font.Size, FontStyle.Regular);
label13.ForeColor = Color.Black;
richTextBox2.Clear();
String[] text = new String[1];
//TEXT
richTextBox2.Lines = text;
}
private void label14_Click(object sender, EventArgs e)
{
label9.Font = new Font(label9.Font.Name, label9.Font.Size, FontStyle.Underline);
label9.ForeColor = Color.Blue;
label13.Font = new Font(label13.Font.Name, label13.Font.Size, FontStyle.Underline);
label13.ForeColor = Color.Blue;
label14.Font = new Font(label14.Font.Name, label14.Font.Size, FontStyle.Regular);
label14.ForeColor = Color.Black;
label15.Font = new Font(label15.Font.Name, label15.Font.Size, FontStyle.Underline);
label15.ForeColor = Color.Blue;
richTextBox2.Clear();
String[] text = new String[1];
//TEXT
richTextBox2.Lines = text;
}
private void label15_Click(object sender, EventArgs e)
{
label9.Font = new Font(label9.Font.Name, label9.Font.Size, FontStyle.Underline);
label9.ForeColor = Color.Blue;
label13.Font = new Font(label13.Font.Name, label13.Font.Size, FontStyle.Underline);
label13.ForeColor = Color.Blue;
label15.Font = new Font(label15.Font.Name, label15.Font.Size, FontStyle.Regular);
label15.ForeColor = Color.Black;
label14.Font = new Font(label14.Font.Name, label14.Font.Size, FontStyle.Underline);
label14.ForeColor = Color.Blue;
richTextBox2.Clear();
String[] text = new String[1];
//TEXT
richTextBox2.Lines = text;
}
private void інструкціяToolStripMenuItem_Click(object sender, EventArgs e)
{
panel4.BringToFront();
}
private void label17_Click(object sender, EventArgs e)
{
panel3.BringToFront();
label9_Click(null, null);
}
private void label19_Click(object sender, EventArgs e)
{
panel4.BringToFront();
}
private void label20_Click(object sender, EventArgs e)
{
panel3.BringToFront();
label15_Click(null, null);
}
private void richTextBox1_Click(object sender, EventArgs e)
{
panel3.BringToFront();
label13_Click(null, null);
}
}
}
