-
Notifications
You must be signed in to change notification settings - Fork 0
/
Ball.cs
202 lines (199 loc) · 5.83 KB
/
Ball.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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
using System.Numerics;
namespace PlingPong
{
public class Ball
{
private int _x;
private int _y;
private int _ymin;
private int _ymax;
private int _stx;
private int _sty;
private string _momentum = "";
public Boolean start = false;
public BigInteger count = new BigInteger(0);
public Boolean Trygn = false;
public Boolean CT = false;
public int btMd = 0;
private int _prevx;
private int _prevy;
public Ball(int ymini, int ymaxi)
{
_x = 15;
_y = 5;
_stx = _x;
_sty = _y;
_ymin = ymini;
_ymax = ymaxi;
var rnd = new Random();
switch (rnd.Next(1, 4))
{
case 1:
_momentum = "LU";
break;
case 2:
_momentum = "LD";
break;
case 3:
_momentum = "RU";
break;
case 4:
_momentum = "RD";
break;
}
}
private void Check(char[,] Canvas, int x, int y)
{
try
{
//debug = (Canvas[y, x 2] "," Canvas[y, x - 2]);
if (y - 1 < _ymin)
{
Bounce(1);
return;
}
if (y 2 > _ymax)
{
Bounce(2);
return;
}
if (Canvas[y, x 2] == '|')
{
Bounce(3);
return;
}
if (Canvas[y, x - 2] == '|')
{
Bounce(4);
return;
}
}
catch (Exception)
{
if (_x <= 0)
{
if (btMd == 0) Console.WriteLine("Player 2 Wins!");
else System.Console.WriteLine("The Bot Wins!");
}
else
Console.WriteLine("Player 1 Wins!");
_x = _stx;
_y = _sty;
start = false;
restart(this);
}
}
public char[,] Iterate(char[,] Canvas)
{
_prevx = _x;
_prevy = _y;
Check(Canvas, _x, _y);
switch (_momentum)
{
case "LU":
Check(Canvas, _x, _y);
_x -= 1;
_y -= 1;
break;
case "LD":
Check(Canvas, _x, _y);
_x -= 1;
_y = 1;
break;
case "RU":
Check(Canvas, _x, _y);
_x = 1;
_y -= 1;
break;
case "RD":
Check(Canvas, _x, _y);
_x = 1;
_y = 1;
break;
}
Canvas[_y, _x] = ' ';
Canvas[_prevy, _prevx] = ' ';
return Canvas;
}
public char[,] Start(char[,] Canvas)
{
Canvas[_y, _x] = ' ';
return Canvas;
}
private void Bounce(int Case)
{
switch (Case)
{
case 1:
if (_momentum == "LU")
_momentum = "LD";
if (_momentum == "RU")
_momentum = "RD";
break;
case 2:
if (_momentum == "LD")
_momentum = "LU";
if (_momentum == "RD")
_momentum = "RU";
break;
case 3:
if (_momentum == "RD")
_momentum = "LD";
if (_momentum == "RU")
_momentum = "LU";
break;
case 4:
if (_momentum == "LU")
_momentum = "RU";
if (_momentum == "LD")
_momentum = "RD";
break;
}
}
public static void restart(Ball ball)
{
Console.WriteLine(@"Please select a valid option:
1. Restart
2. Try Again
3. Replay
4. Exit
5. Change Mode
");
switch (Console.ReadKey().Key)
{
case (ConsoleKey.D1):
Program.mainTwoPlayer(ball);
break;
case ConsoleKey.D2:
ball.Trygn = true;
Program.mainTwoPlayer(ball);
break;
case ConsoleKey.D3:
Console.WriteLine("Sorry thats not possible atm!");
restart(ball);
break;
case ConsoleKey.D4:
Console.ForegroundColor = ConsoleColor.Green;
Console.WriteLine("Goodbye!");
Console.ForegroundColor = ConsoleColor.Gray;
Console.Beep(100, 500);
break;
case ConsoleKey.Insert:
ball.CT = true;
Program.mainTwoPlayer(ball);
break;
case ConsoleKey.D5:
Program.Main();
break;
default:
Console.WriteLine("Try Again!");
restart(ball);
break;
}
}
public int Y
{
get { return _y; }
}
}
}