-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLanding.cs
120 lines (110 loc) · 3.97 KB
/
Landing.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
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Net.Http;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using Newtonsoft.Json;
using System.Security.Cryptography;
using System.Security;
using System.Configuration;
namespace ICS3U1_Culminating
{
public partial class Landing : Form
{
public Landing()
{
InitializeComponent();
}
private void Landing_Load(object sender, EventArgs e)
{
scoreLabel.Text = "0";
countUp(Globals.points, scoreLabel);
sendDataToServer();
}
Timer labelTransition = new Timer();
private async void sendDataToServer()
{
using (var client = new HttpClient())
{
client.BaseAddress = new Uri("http://api.carspotter.ca");
client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json"));
var Reqcontent = new FormUrlEncodedContent(new[]
{
new KeyValuePair<string, string>("name", Globals.username),
new KeyValuePair<string, string>("score", Globals.points.ToString())
});
Console.WriteLine("K");
var result = await client.PostAsync("/index.php/highscores", Reqcontent);
Console.WriteLine("Await");
if (result.IsSuccessStatusCode)
{
Console.WriteLine(result.StatusCode);
string responseString = await result.Content.ReadAsStringAsync();
dynamic response = JsonConvert.DeserializeObject(responseString);
//Console.WriteLine(Convert.ToString(response));
}
else
{
Console.WriteLine(result.StatusCode);
}
}
}
private void countUp(int score, Label Labl)
{
Timer tmr = new Timer();
tmr.Interval = 10;
tmr.Enabled = true;
tmr.Start();
tmr.Tick += new EventHandler(timerTick);
void timerTick(object sender, EventArgs e)
{
if(int.Parse(Labl.Text) < score)
{
Labl.Text = (int.Parse(Labl.Text) + 10).ToString();
} else
{
tmr.Enabled = false;
tmr.Stop();
}
}
}
public const int WM_NCLBUTTONDOWN = 0xA1;
public const int HT_CAPTION = 0x2;
[System.Runtime.InteropServices.DllImportAttribute("user32.dll")]
public static extern int SendMessage(IntPtr hWnd, int Msg, int wParam, int lParam);
[System.Runtime.InteropServices.DllImportAttribute("user32.dll")]
public static extern bool ReleaseCapture();
private void Landing_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e)
{
if (e.Button == MouseButtons.Left)
{
ReleaseCapture();
SendMessage(Handle, WM_NCLBUTTONDOWN, HT_CAPTION, 0);
}
}
private void Close(object sender, EventArgs e)
{
this.Close();
Application.Exit();
}
private void Minimize(object sender, EventArgs e)
{
this.WindowState = FormWindowState.Minimized;
}
private void Expand(object sender, EventArgs e)
{
this.WindowState = FormWindowState.Normal;
}
private void LeaderboardButton_Click(object sender, EventArgs e)
{
LeaderBoard leaderboard = new LeaderBoard();
leaderboard.Show();
this.Hide();
}
}
}