-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path#8 Program.cs
126 lines (115 loc) · 3.84 KB
/
#8 Program.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
//was written by Rostislav Gogolauri
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace task8
{
class Program
{
static void Main(string[] args)
{
double Vx, Vy, x0, y0, x, y, w, h,overH,overW;
int t;
Console.WriteLine("Vx= ");
Vx = Convert.ToDouble(Console.ReadLine());
Console.WriteLine("Vy= ");
Vy = Convert.ToDouble(Console.ReadLine());
Console.WriteLine("x0= ");
x0 = Convert.ToDouble(Console.ReadLine());
Console.WriteLine("y0= ");
y0 = Convert.ToDouble(Console.ReadLine());
Console.WriteLine("t= ");
t = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("W= ");
w = Convert.ToDouble(Console.ReadLine());
Console.WriteLine("H= ");
h = Convert.ToDouble(Console.ReadLine());
x = x0;
y = y0;
if (x0 <= 0 || y0 <= 0 || x0 > w || y0 > h)
{
Console.Write("Are you kidding?");
}
else
{
for (int i = 0; i <= t; i++)
{
x = x + Vx;
y = y + Vy;
if (x <= 0 && y <= 0)
{ //
overH = Math.Abs(y);
overW = Math.Abs(x);
x = 0+overW;
Vx = -Vx;
//
y = 0+overH;
Vy = -Vy;
//
}
else if (x <= 0 && y > 0 &&y<=h)
{ //
overW = Math.Abs(x);
x = 0 + overW;
Vx = -Vx;
//
}
else if (x <= 0 && y >= h)
{ //
overW = Math.Abs(x);
overH = y - h;
x = 0+overW;
Vx = -Vx;
//
y = h-overH;
Vy = -Vy;
}
else if (x > 0 && y <= 0)
{ //
overH = Math.Abs(y);
y = 0+overH;
Vy = -Vy;
//
}
else if (x >= w && y <= 0)
{ //
overH = Math.Abs(y);
y = 0+overH;
Vy = -Vy;
//
x = w;
Vx = -Vx;
}
else if (y >= h && x >= w)
{ //
overH = y - h;
overW = x - w;
y = h-overH;
Vy = -Vy;
//
x = w-overW;
Vx = -Vx;
}
else if (x>=w && y>=0)
{
overW = x - w;
Vx = -Vx;
x = w-overW;
}
else if (y >= h && x >= 0)
{
overH = y - h;
Vy = -Vy;
y = h-overH;
}
Console.WriteLine("i={0} ", i);
Console.Write("x={0} ", x);
Console.Write("y={0} ", y);
}
}
Console.ReadKey();
}
}
}