aboutsummaryrefslogtreecommitdiff
path: root/source/WindowsFormsApplication1/Apps/Pong.cs
blob: fb14dde37d615b1c8c8f2e15d34be3b791d70288 (plain) (blame)
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
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using ShiftUI;

namespace ShiftOS
{
    public partial class Pong : Form
    {
        int xVel = 7;
        int yVel = 8;
        int computerspeed = 8;
        int level = 1;
        int secondsleft = 60;
        int casualposition;
        double xveldec = 3.0;
        double yveldec = 3.0;
        double incrementx = 0.4;
        double incrementy = 0.2;
        int levelxspeed = 3;
        int levelyspeed = 3;
        int beatairewardtotal;
        int beataireward = 1;
        int[] levelrewards = new int[50];
        int totalreward;
        int countdown = 3;
        
        public Pong()
        {
            InitializeComponent();
        }

        private void Pong_Load(object sender, EventArgs e)
        {
            setuplevelrewards();

            if(API.Upgrades["customgrayshades"] == true && API.Upgrades["multitasking"] == true)
            {
                if(API.Upgrades["shiftnet"] == false)
                {
                    tmrstoryline.Start();
                }
            }
        }

        // Move the paddle according to the mouse position.
        private void pongMain_MouseMove(object sender, ShiftUI.MouseEventArgs e)
        {
            paddleHuman.Location = new Point(paddleHuman.Location.X, (MousePosition.Y - this.Location.Y) - (paddleHuman.Height / 2));
        }


        // ERROR: Handles clauses are not supported in C#
        private void gameTimer_Tick(object sender, EventArgs e)
        {
            if (this.Left < Screen.PrimaryScreen.Bounds.Width)
            {
                if (this.Height != API.CurrentSkin.titlebarheight)
                {
                    //Set the computer player to move according to the ball's position.
                    if (ball.Location.X > 500 - xVel * 10 && xVel > 0)
                    {
                        if (ball.Location.Y > paddleComputer.Location.Y + 50)
                        {
                            paddleComputer.Location = new Point(paddleComputer.Location.X, paddleComputer.Location.Y + computerspeed);
                        }
                        if (ball.Location.Y < paddleComputer.Location.Y + 50)
                        {
                            paddleComputer.Location = new Point(paddleComputer.Location.X, paddleComputer.Location.Y - computerspeed);
                        }
                        casualposition = rand.Next(-150, 201);
                    }
                    else {
                        //used to be me.location.y
                        if (paddleComputer.Location.Y > this.Size.Height / 2 - paddleComputer.Height + casualposition)
                        {
                            paddleComputer.Location = new Point(paddleComputer.Location.X, paddleComputer.Location.Y - computerspeed);
                        }
                        //used to be me.location.y
                        if (paddleComputer.Location.Y < this.Size.Height / 2 - paddleComputer.Height + casualposition)
                        {
                            paddleComputer.Location = new Point(paddleComputer.Location.X, paddleComputer.Location.Y + computerspeed);
                        }
                    }

                    //Set Xvel and Yvel speeds from decimal
                    if (xVel > 0)
                        xVel = (int)Math.Round(xveldec);
                    if (xVel < 0)
                        xVel = (int)-Math.Round(xveldec);
                    if (yVel > 0)
                        yVel = (int)Math.Round(yveldec);
                    if (yVel < 0)
                        yVel = (int)-Math.Round(yveldec);

                    // Move the game ball.
                    ball.Location = new Point(ball.Location.X + xVel, ball.Location.Y + yVel);

                    // Check for top wall.
                    if (ball.Location.Y < 0)
                    {
                        ball.Location = new Point(ball.Location.X, 0);
                        yVel = -yVel;
                    }

                    // Check for bottom wall.
                    if (ball.Location.Y > pgcontents.Height - ball.Height)
                    {
                        ball.Location = new Point(ball.Location.X, pgcontents.Height - ball.Size.Height);
                        yVel = -yVel;
                    }

                    // Check for player paddle.
                    if (ball.Bounds.IntersectsWith(paddleHuman.Bounds))
                    {
                        ball.Location = new Point(paddleHuman.Location.X + ball.Size.Width, ball.Location.Y);
                        //randomly increase x or y speed of ball
                        switch (rand.Next(1, 3))
                        {
                            case 1:
                                xveldec = xveldec + incrementx;
                                break;
                            case 2:
                                if (yveldec > 0)
                                    yveldec = yveldec + incrementy;
                                if (yveldec < 0)
                                    yveldec = yveldec - incrementy;
                                break;
                        }
                        xVel = -xVel;
                        API.PlaySound(Properties.Resources.typesound);
                    }

                    // Check for computer paddle.
                    if (ball.Bounds.IntersectsWith(paddleComputer.Bounds))
                    {
                        ball.Location = new Point(paddleComputer.Location.X - paddleComputer.Size.Width + 1, ball.Location.Y);
                        xveldec = xveldec + incrementx;
                        xVel = -xVel;
                        API.PlaySound(Properties.Resources.typesound);
                    }

                    // Check for left wall.
                    if (ball.Location.X < -100)
                    {
                        ball.Location = new Point(this.Size.Width / 2 + 200, this.Size.Height / 2);
                        paddleComputer.Location = new Point(paddleComputer.Location.X, ball.Location.Y);
                        if (xVel > 0)
                            xVel = -xVel;
                        pnllose.Show();
                        gameTimer.Stop();
                        counter.Stop();
                        lblmissedout.Text = "You Missed Out On:" + Environment.NewLine + lblstatscodepoints.Text.Replace("Codepoints earned: ", "") + " Codepoints";
                    }

                    // Check for right wall.
                    if (ball.Location.X > this.Width - ball.Size.Width - paddleComputer.Width + 100)
                    {
                        ball.Location = new Point(this.Size.Width / 2 + 200, this.Size.Height / 2);
                        paddleComputer.Location = new Point(paddleComputer.Location.X, ball.Location.Y);
                        if (xVel > 0)
                            xVel = -xVel;
                        beatairewardtotal = beatairewardtotal + beataireward;
                        lblbeatai.Show();
                        lblbeatai.Text = "You got " + beataireward + " codepoints for beating the Computer!";
                        tmrcountdown.Start();
                        gameTimer.Stop();
                        counter.Stop();
                    }

                    //lblstats.Text = "Xspeed: " & Math.Abs(xVel) & " Yspeed: " & Math.Abs(yVel) & " Human Location: " & paddleHuman.Location.ToString & " Computer Location: " & paddleComputer.Location.ToString & Environment.NewLine & " Ball Location: " & ball.Location.ToString & " Xdec: " & xveldec & " Ydec: " & yveldec & " Xinc: " & incrementx & " Yinc: " & incrementy
                    lblstatsX.Text = "Xspeed: " + xveldec;
                    lblstatsY.Text = "Yspeed: " + yveldec;
                    lblstatscodepoints.Text = "Codepoints earned: " + (levelrewards[level - 1] + beatairewardtotal).ToString();

                    lbllevelandtime.Text = "Level: " + level + " - " + secondsleft + " Seconds Left";

                    if (xVel > 20 || xVel < -20)
                    {
                        paddleHuman.Width = Math.Abs(xVel);
                        paddleComputer.Width = Math.Abs(xVel);
                    }
                    else {
                        paddleHuman.Width = 20;
                        paddleComputer.Width = 20;
                    }

                    computerspeed = Math.Abs(yVel);

                    //  pgcontents.Refresh()
                    // pgcontents.CreateGraphics.FillRectangle(Brushes.Black, ball.Location.X, ball.Location.Y, ball.Width, ball.Height)
                }
            }
        }

        // ERROR: Handles clauses are not supported in C#
        private void counter_Tick(object sender, EventArgs e)
        {
            if (this.Left < Screen.PrimaryScreen.Bounds.Width)
            {
                if (this.Height != API.CurrentSkin.titlebarheight)
                {
                    secondsleft = secondsleft - 1;
                    if (secondsleft == -1)
                    {
                        secondsleft = 60;
                        level = level + 1;
                        generatenextlevel();
                        pnlgamestats.Show();
                        pnlgamestats.BringToFront();
                        pnlgamestats.Location = new Point((pgcontents.Width / 2) - (pnlgamestats.Width / 2), (pgcontents.Height / 2) - (pnlgamestats.Height / 2));

                        counter.Stop();
                        gameTimer.Stop();
                    }
                    lblstatscodepoints.Text = "Codepoints earned: " + (levelrewards[level - 1] + beatairewardtotal).ToString();
                }
            }
        }

        // ERROR: Handles clauses are not supported in C#
        private void btnplayon_Click(object sender, EventArgs e)
        {
            xveldec = levelxspeed;
            yveldec = levelyspeed;

            secondsleft = 60;

            tmrcountdown.Start();
            lblbeatai.Text = "Get " + beataireward + " codepoints for beating the Computer!";
            pnlgamestats.Hide();
            lblbeatai.Show();
            ball.Location = new Point(paddleHuman.Location.X + paddleHuman.Width + 50, paddleHuman.Location.Y + paddleHuman.Height / 2);
            if (xVel < 0)
                xVel = Math.Abs(xVel);
            lbllevelandtime.Text = "Level: " + level + " - " + secondsleft + " Seconds Left";
        }

        //Increase the ball speed stats for the next level
        private void generatenextlevel()
        {
            lbllevelreached.Text = "You Reached Level " + level + "!";

            lblpreviousstats.Text = "Initial Ball X Speed: " + levelxspeed + Environment.NewLine + "Initial Ball Y Speed: " + levelyspeed + Environment.NewLine + "Increment X Speed: " + incrementx + Environment.NewLine + "Increment Y Speed: " + incrementy;

            switch (rand.Next(1, 3))
            {
                case 1:
                    levelxspeed = levelxspeed + 1;
                    break;
                case 2:
                    levelxspeed = levelxspeed + 2;
                    break;
            }

            switch (rand.Next(1, 3))
            {
                case 1:
                    levelyspeed = levelyspeed + 1;
                    break;
                case 2:
                    levelyspeed = levelyspeed + 2;
                    break;
            }

            switch (rand.Next(1, 6))
            {
                case 1:
                    incrementx = incrementx + 0.1;
                    break;
                case 2:
                    incrementx = incrementx + 0.2;
                    break;
                case 3:
                    incrementy = incrementy + 0.1;
                    break;
                case 4:
                    incrementy = incrementy + 0.2;
                    break;
                case 5:
                    incrementy = incrementy + 0.3;
                    break;
            }

            lblnextstats.Text = "Initial Ball X Speed: " + levelxspeed + Environment.NewLine + "Initial Ball Y Speed: " + levelyspeed + Environment.NewLine + "Increment X Speed: " + incrementx + Environment.NewLine + "Increment Y Speed: " + incrementy;

            if (level < 15)
            {
                beataireward = level * 2;
            }
            else {
                double br = levelrewards[level - 1] / 10;
                beataireward = (int)Math.Round(br);
            }

            totalreward = levelrewards[level - 1] + beatairewardtotal;

            btncashout.Text = "Cash out with " + totalreward.ToString() + " codepoints!";
            btnplayon.Text = "Play on for " + (levelrewards[level] + beatairewardtotal).ToString() + " codepoints!";
        }

        private void setuplevelrewards()
        {
            levelrewards[0] = 0;
            levelrewards[1] = 1;
            levelrewards[2] = 3;
            levelrewards[3] = 7;
            levelrewards[4] = 13;
            levelrewards[5] = 20;
            levelrewards[6] = 30;
            levelrewards[7] = 45;
            levelrewards[8] = 60;
            levelrewards[9] = 80;
            levelrewards[10] = 100;
            levelrewards[11] = 125;
            levelrewards[12] = 150;
            levelrewards[13] = 200;
            levelrewards[14] = 250;
            levelrewards[15] = 300;
            levelrewards[16] = 400;
            levelrewards[17] = 500;
            levelrewards[18] = 650;
            levelrewards[19] = 800;
            levelrewards[20] = 1000;
            levelrewards[21] = 1250;
            levelrewards[22] = 1600;
            levelrewards[23] = 2000;
            levelrewards[24] = 2500;
            levelrewards[25] = 3000;
            levelrewards[26] = 3750;
            levelrewards[27] = 4500;
            levelrewards[28] = 5500;
            levelrewards[29] = 7000;
            levelrewards[30] = 9000;
            levelrewards[31] = 11000;
            levelrewards[32] = 13500;
            levelrewards[33] = 16000;
            levelrewards[34] = 20000;
            levelrewards[35] = 25000;
            levelrewards[36] = 32000;
            levelrewards[37] = 40000;
            levelrewards[38] = 50000;
            levelrewards[39] = 75000;
            levelrewards[40] = 100000;
        }

        // ERROR: Handles clauses are not supported in C#
        private void countdown_Tick(object sender, EventArgs e)
        {
            if (this.Left < Screen.PrimaryScreen.Bounds.Width)
            {
                if (this.Height != API.CurrentSkin.titlebarheight)
                {
                    switch (countdown)
                    {
                        case 0:
                            countdown = 3;
                            lblcountdown.Hide();
                            lblbeatai.Hide();
                            API.PlaySound(Properties.Resources.writesound);
                            gameTimer.Start();
                            counter.Start();
                            tmrcountdown.Stop();
                            break;
                        case 1:
                            lblcountdown.Text = "1";
                            countdown = countdown - 1;
                            API.PlaySound(Properties.Resources.writesound);
                            break;
                        case 2:
                            lblcountdown.Text = "2";
                            countdown = countdown - 1;
                            API.PlaySound(Properties.Resources.writesound);
                            break;
                        case 3:
                            lblcountdown.Text = "3";
                            countdown = countdown - 1;
                            API.PlaySound(Properties.Resources.writesound);
                            lblcountdown.Show();
                            break;
                    }
                }
            }
        }

        // ERROR: Handles clauses are not supported in C#
        private void btncashout_Click(object sender, EventArgs e)
        {
            pnlgamestats.Hide();
            pnlfinalstats.Show();
            lblfinalcodepointswithtext.Text = "You cashed out with " + totalreward + " codepoints!";
            lblfinallevelreached.Text = "Codepoints rewarded for reaching level " + (level - 1).ToString();
            lblfinallevelreward.Text = levelrewards[level - 1].ToString();
            lblfinalcomputerreward.Text = beatairewardtotal.ToString();
            lblfinalcodepoints.Text = totalreward + " CP";
            API.AddCodepoints(totalreward);
        }

        private void newgame()
        {
            pnlfinalstats.Hide();
            pnllose.Hide();
            pnlintro.Hide();

            level = 1;
            totalreward = 0;
            beataireward = 2;
            beatairewardtotal = 0;
            secondsleft = 60;
            lblstatscodepoints.Text = "Codepoints: ";
            //reset stats text
            lblstatsX.Text = "Xspeed: ";
            lblstatsY.Text = "Yspeed: ";

            levelxspeed = 3;
            levelyspeed = 3;

            incrementx = 0.4;
            incrementy = 0.2;

            xveldec = levelxspeed;
            yveldec = levelyspeed;

            tmrcountdown.Start();
            lblbeatai.Text = "Get " + beataireward + " codepoints for beating the Computer!";
            pnlgamestats.Hide();
            lblbeatai.Show();
            ball.Location = new Point(paddleHuman.Location.X + paddleHuman.Width + 50, paddleHuman.Location.Y + paddleHuman.Height / 2);
            if (xVel < 0)
                xVel = Math.Abs(xVel);
            lbllevelandtime.Text = "Level: " + level + " - " + secondsleft + " Seconds Left";
        }

        // ERROR: Handles clauses are not supported in C#
        private void btnplayagain_Click(object sender, EventArgs e)
        {
            newgame();
        }

        // ERROR: Handles clauses are not supported in C#
        private void btnlosetryagain_Click(object sender, EventArgs e)
        {
            newgame();
        }

        // ERROR: Handles clauses are not supported in C#
        private void btnstartgame_Click(object sender, EventArgs e)
        {
            newgame();
        }

        Random rand = new Random();
        // ERROR: Handles clauses are not supported in C#
        private void tmrstoryline_Tick(object sender, EventArgs e)
        {
            // Random chance of showing getshiftnet storyline
            int i = rand.Next(0, 100);

            if (i >= 25 && i <= 50)
            {
                Terminal term = new Terminal();
                API.CreateForm(term, "Terminal", Properties.Resources.iconTerminal);
                term.StartShiftnetStory();
                tmrstoryline.Stop();
            }
            
        }

        // ERROR: Handles clauses are not supported in C#
        private void me_closing(object sender, FormClosingEventArgs e)
        {
            tmrstoryline.Stop();
        }
    }
}