// 初始化,更新自己的UI信息 public void Initialize(ScoreInformation scoreInformation) { score = scoreInformation.score; coins = scoreInformation.coins; scoreRequestText.text = score.ToString() + "分"; coinsGetText.text = coins.ToString() + "金币"; }
private void OnTriggerStay(Collider collider) { //Debug.Log("Player collided with something " + collision.gameObject.name); if (collider.gameObject.tag.Contains("Player") || collider.gameObject.name.Contains("parachute")) { return; } if (hitCooldown == false) { hitCooldown = true; audioSource.clip = hurtSound[Random.Range(0, hurtSound.Length - 1)]; audioSource.pitch = Random.Range(0.85f, 1.25f); audioSource.Play(); Invoke("AllowPlayerToGetHit", 2.0f); GetComponent <ScoreUpdate>().Reset(); ScoreInformation info = new ScoreInformation(); FlyerProperties s = collider.gameObject.GetComponent <FlyerProperties>(); info.obsType = s.obstacleType; info.Score = s.scorePenalty; //Debug.Log(info); //Debug.Log("Hi im player and i hit something"); FindObjectOfType <MenuPlayers>().CurrentPlayers.Find(ss => ss.Playerid == CurrentController).AddScore(info); DamageTextController.CreateDamageText(s.scorePenalty.ToString(), transform); StartCoroutine(ShakePlayer()); } }
public void AddScore(ScoreInformation info) { if (!manager.StopScore) { Scores.Add(info); } }
public void client_UploadStringCompleted(object sender, UploadStringCompletedEventArgs e) { if (!e.Cancelled && e.Error == null) { try { ActionFacebookPostHighScoreArg arg = _waiting[(WebClient)sender]; string data = e.Result; ScoreInformation succeed = new ScoreInformation(); succeed = JsonConvert.DeserializeObject <ScoreInformation>(data); if (succeed != null) { if (succeed.success) { arg.score_inform = new ScoreInformation(); arg.score_inform = succeed; Done(arg); _waiting.Remove((WebClient)sender); } } } catch (Exception ex) { } } }
// 根据特定算法生成得分与金币获取量的信息 void InitializeScoreInformation() { for (int i = 0; i < 11; i++) { // 金币增量为100;得分增量为200 ScoreInformation scoreInformation = new ScoreInformation(); scoreInformation.score = LowestLevel + i * 200; scoreInformation.coins = 100; // 跳过整千 if (scoreInformation.score % 1000 == 0) { continue; } scoreInformationList.Add(scoreInformation); } }
/// <summary> /// Every timer tick: /// Updates the world (adds food, etc) /// Sends updates to the clients /// </summary> private void HeartBeatTick(object state, ElapsedEventArgs e) { // Prevent this eventhandler from firing again while we're handling it Heartbeat.Enabled = false; // Data to send to all of the clients StringBuilder data = new StringBuilder(); List <Tuple <int, double> > sortedByMass = new List <Tuple <int, double> >(); lock (World) { // Players get a little smaller each tick, and military viruses move along their path World.PlayerAttrition(); World.MoveMilitaryVirus(); // Move all players according to last mouse position lock (DataReceived) { // Uid's to be removed List <int> toBeRemoved = new List <int>(); // Move all player cubes according to last mouse position foreach (int uid in DataReceived.Keys) { // If the cube has been removed from the world, mark it to be removed and skip moving if (!World.Cubes.ContainsKey(uid)) { toBeRemoved.Add(uid); continue; } // Get all of the current masses for ranking purposes sortedByMass.Add(new Tuple <int, double>(uid, World.DatabaseStats[uid].CurrentMass)); World.Move(uid, DataReceived[uid].Item1, DataReceived[uid].Item2); } // Remove marked cubes foreach (int uid in toBeRemoved) { DataReceived.Remove(uid); } } // Check for collisions, eat some food data.Append(World.ManageCollisions()); // Add food to the world if necessary and append it to the data stream for (int i = 0; i < World.FOOD_PER_HEARTBEAT && World.Food.Count < World.MAX_FOOD_COUNT; i++) { data.Append(JsonConvert.SerializeObject(World.GenerateFoodorVirus()) + "\n"); } // Appends all of the player cube data - they should be constantly changing (mass, position, or both), therefore, we send them every time data.Append(World.SerializePlayers()); } sortedByMass.Sort((a, b) => b.Item2.CompareTo(a.Item2)); // Send data to sockets lock (Sockets) { List <Socket> disconnected = new List <Socket>(); foreach (Socket s in Sockets.Keys) { for (int i = 0; i < 5 && i < sortedByMass.Count; i++) { if (sortedByMass[i].Item1 == Sockets[s].Uid && (Sockets[s].HighestRank == 0 || Sockets[s].HighestRank > (i + 1))) { Sockets[s].HighestRank = (i + 1); } } // Remove sockets that are no longer connected if (!s.Connected) { disconnected.Add(s); continue; } Network.Send(s, data.ToString()); } foreach (Socket s in disconnected) { // Add data to database ScoreInformation score = Sockets[s]; TimeSpan playtime = score.Playtime.Elapsed; String formattedPlaytime = (playtime.Days * 24 + playtime.Hours) + "h " + playtime.Minutes + "m " + playtime.Seconds + "s"; World.StatTracker stats; lock (World) { stats = World.DatabaseStats[Sockets[s].Uid]; } // A little tricky here - we don't actually want to set the highest rank in the DB if it has not been set in the server. String magic does the job string highestRankColumn = (score.HighestRank == 0) ? "" : " HighestRank,"; string highestRankValue = (score.HighestRank == 0) ? "" : " " + score.HighestRank + ","; string insertPlayerData = String.Format("INSERT INTO Players(GameId, Name, Lifetime, MaxMass,{0} CubesEaten, TimeofDeath, NumPlayersEaten) " + "VALUES({1}, '{2}', '{3}', {4},{5} {6}, '{7}',{8});", highestRankColumn, ++GameIdCounter, stats.Name, formattedPlaytime, stats.MaxMass, highestRankValue, stats.CubesConsumed, DateTime.Now, stats.PlayersEaten.Count); // Now connect to the DB and execute the commands using (MySqlConnection conn = new MySqlConnection(connectionString)) { try { MySqlCommand insertData = new MySqlCommand(insertPlayerData, conn); conn.Open(); // Insert row of player stats in Players table insertData.ExecuteNonQuery(); // Insert row(s) into Eaten table (at least one for the player, and then one for all players it ate) if (stats.PlayersEaten.Count == 0) { (new MySqlCommand(String.Format("INSERT INTO Eaten(GameId, Name) VALUES({0}, '{1}');", GameIdCounter, stats.Name), conn)).ExecuteNonQuery(); } else { foreach (string eatenName in stats.PlayersEaten) { (new MySqlCommand(String.Format("INSERT INTO Eaten(GameId, Name, EatenPlayer) VALUES({0}, '{1}', '{2}');", GameIdCounter, stats.Name, eatenName), conn)).ExecuteNonQuery(); } } conn.Close(); } catch (Exception ex) { Console.WriteLine(ex.Message); } } // Remove this player lock (World) { World.DatabaseStats.Remove(Sockets[s].Uid); } lock (DataReceived) { DataReceived.Remove(Sockets[s].Uid); } Sockets.Remove(s); } } // Event can now fire again Heartbeat.Enabled = true; }
void ScoresCallback(FBResult result) { Debug.Log("ScoresCallback"); if (result.Error != null) { Debug.LogError(result.Error); return; } HighScores = new List<ScoreInformation>(); List<object> scoresList = Util.DeserializeScores(result.Text); foreach(object score in scoresList) { ScoreInformation scoreInfo = new ScoreInformation(); var entry = (Dictionary<string,object>) score; var user = (Dictionary<string,object>) entry["user"]; string userId = (string)user["id"]; scoreInfo.name = (string)user["first_name"]; scoreInfo.score = getScoreFromEntry(entry); LoadPicture(Util.GetPictureURL(userId, 128, 128),pictureTexture => { if (pictureTexture != null) { scoreInfo.picture = pictureTexture; } }); HighScores.Add( scoreInfo ); } }
public void MassResetOfDeathAndDestruction() { ScoreInformation.resetscorelists(); SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex); }