-
Notifications
You must be signed in to change notification settings - Fork 0
/
ScoreManager.cs
62 lines (53 loc) · 1.67 KB
/
ScoreManager.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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Text;
using System.Threading.Tasks;
namespace Brick_Breaker
{
class ScoreManager
{
private int score;
// C# Encapsulation
public int GetScore
{
get { return score; }
}
/// <summary>
/// Initializes the ScoreManager class.
/// </summary>
public ScoreManager()
{
// Set starting score to 0
score = 0;
}
/// <summary>
/// Adds to player score.
/// </summary>
/// <param name="score">Value to add to the current score.</param>
public void AddScore(int score)
{
this.score += score;
}
/// <summary>
/// Uploads the score data to the server via a POST request.
/// </summary>
/// <param name="name">Name of the player.</param>
public void UploadScore(String name)
{
var request = (HttpWebRequest)WebRequest.Create("http://ics.net78.net/brick/addscore.php");
var postData = "name=" + name;
postData += "&score=" + score;
var data = Encoding.ASCII.GetBytes(postData);
request.Method = "POST";
request.ContentType = "application/x-www-form-urlencoded";
request.ContentLength = data.Length;
using (var stream = request.GetRequestStream())
{
stream.Write(data, 0, data.Length);
}
var response = (HttpWebResponse)request.GetResponse();
}
}
}