public Bullet(Contestant con, Point origin, int dir) { shooter = con; pos = origin; Direction = dir; Console.WriteLine("Bullet shot at " + pos.X + "," + pos.Y + "," + direction); RandomGen r = new RandomGen(); id = r.randomD(1000); }
public d(CoinPile A_0, Contestant A_1, bool[][] A_2) { this.f = 0; base..ctor(); this.a = A_0; this.b = A_1; this.c = A_2; this.b(); return; }
private string AddContestant(string conIP, int port) { if (playerList.Count < GameEngine.maxPlayerNumber && !(playerIPList.Contains(conIP) && playerPort.Contains(port))) { Monitor.Enter(playerIPList); Monitor.Enter(playerPort); Monitor.Enter(playerList); int index = playerList.Count; Contestant con = new Contestant("P" + index, conIP, port); con.UpdatedTime = DateTime.Now; playerList.Add(con); playerIPList.Add(conIP); playerPort.Add(port); //Engine.joinedPlayers += 1; //Engine.alivePlayers += 1; switch (playerList.Count) { case (1): con.StartP = new Point(0, 0); this.RaiseGameStartingEvent(); break; case (2): con.StartP = new Point(0, mapSize - 1); break; case (3): con.StartP = new Point(mapSize - 1, 0); break; case (4): con.StartP = new Point(mapSize - 1, mapSize - 1); break; default: // LIMITATION: Max Number of Contestants should be equal or less to the width of the map con.StartP = new Point(playerList.Count, playerList.Count); break; } con.CurrentP = con.StartP; if (playerList.Count == GameEngine.maxPlayerNumber && GameEngine.gameStarted) { GameEngine.gameStarted = true; GameEngine.gameFinished = false; this.RaiseGameJustStartedEvent(); } Monitor.Exit(playerList); Monitor.Exit(playerPort); Monitor.Exit(playerIPList); //If added then initial map is sent. gui.AddPlayer(con.CurrentP.X, con.CurrentP.Y, con.Direction, index); // gui.InitializeMap(Constant.MAP_SIZE, GameEngine.mapDetails); return "I:" + con.Name + ":" + mapDetails + Constant.S2C_DEL; } else if (playerList.Count >= GameEngine.maxPlayerNumber && !playerIPList.Contains(conIP)) { return Constant.S2C_CONTESTANTSFULL + Constant.S2C_DEL; } else if (playerIPList.Contains(conIP) && playerPort.Contains(port)) { return Constant.S2C_ALREADYADDED + Constant.S2C_DEL; } else { return Constant.S2C_REQUESTERROR + Constant.S2C_DEL; } }
public string updateContestant(Contestant con, string request) { string pointsEarned = ""; if (!con.IsAlive) //Player is not alive { return Constant.S2C_NOTALIVE + Constant.S2C_DEL; } TimeSpan dr = DateTime.Now - con.UpdatedTime; if (dr.TotalMilliseconds < Constant.PLAYER_DELAY) { con.UpdatedTime = DateTime.Now; //No flooding the server is accepted ;) return Constant.S2C_TOOEARLY + Constant.S2C_DEL; } //Console.WriteLine(dr.TotalSeconds); con.InvalidCell = false; Point reqPoint = new Point(); Boolean shoot = false; Boolean turn = false; //Calculating the next cell requested. if (Constant.UP.Equals(request.ToUpperInvariant())) { if (con.Direction == 0) //If it is facing North already move { reqPoint.X = con.CurrentP.X; reqPoint.Y = con.CurrentP.Y - 1; } else //Turn to face North { reqPoint.X = con.CurrentP.X; reqPoint.Y = con.CurrentP.Y; con.Direction = 0; turn = true; } } else if (Constant.DOWN.Equals(request.ToUpperInvariant())) { if (con.Direction == 2) { reqPoint.X = con.CurrentP.X; reqPoint.Y = con.CurrentP.Y + 1; } else { reqPoint.X = con.CurrentP.X; reqPoint.Y = con.CurrentP.Y; con.Direction = 2; turn = true; } } else if (Constant.LEFT.Equals(request.ToUpperInvariant())) { if (con.Direction == 3) { reqPoint.X = con.CurrentP.X - 1; reqPoint.Y = con.CurrentP.Y; } else { reqPoint.X = con.CurrentP.X; reqPoint.Y = con.CurrentP.Y; con.Direction = 3; turn = true; } } else if (Constant.RIGHT.Equals(request.ToUpperInvariant())) { if (con.Direction == 1) { reqPoint.X = con.CurrentP.X + 1; reqPoint.Y = con.CurrentP.Y; } else { reqPoint.X = con.CurrentP.X; reqPoint.Y = con.CurrentP.Y; con.Direction = 1; turn = true; } } else if (Constant.SHOOT.Equals(request.ToUpperInvariant())) { shoot = true; } if (!shoot) { con.Shot = false; //Checking for errors in the cell requested. if (IsInvalid(reqPoint)) { //out of the map. con.InvalidCell = true; con.UpdatedTime = DateTime.Now; //Releasing the players. return Constant.S2C_INVALIDCELL + Constant.S2C_DEL; } else //Cell requested is in the map. { if (GameEngine.obstacles.Contains(reqPoint)) { //Hits on an obstacle. return ObstacleHit(con); } else if (GameEngine.brickLocations.Contains(reqPoint)) { int brickIndex = brickLocations.IndexOf(reqPoint); if (brickWalls[brickIndex].DamageLevel < 4) //consider as obstacle { return ObstacleHit(con); } else { con.CurrentP = reqPoint; con.UpdatedTime = DateTime.Now; } } else if (GameEngine.water.Contains(reqPoint)) { //Falls in a pit. con.IsAlive = false; con.CurrentP = reqPoint; con.Health = 0; con.UpdatedTime = DateTime.Now; HandlePlayerDeath(); return Constant.S2C_FALLENTOPIT + Constant.S2C_DEL; } else //Not an obstacle or pitfall. May be an already occupied cell. { Monitor.Enter(GameEngine.playerList); for (int i = 0; i < GameEngine.playerList.Count; i++) { if (!turn && i != con.Index && reqPoint == GameEngine.playerList[i].CurrentP) { if (GameEngine.playerList[i].IsAlive) { con.UpdatedTime = DateTime.Now; // con.CurrentP = reqPoint; return Constant.S2C_CELLOCCUPIED + Constant.S2C_DEL; } else { break; } } } Monitor.Exit(GameEngine.playerList); //Non occupied cell, May be a regular CoinPile is here. //Monitor.Enter(GameEngine.availableCoinPileList); foreach (CoinPile t in GameEngine.availableCoinPileList) { if (t.Position == reqPoint) { con.PointsEarned += t.Price; con.Coins += t.Price; pointsEarned += t.Price; int tIndex = gameEng.DisappearCoinPileList.IndexOf(t); GameEngine.availableCoinPileList.Remove(t); GameEngine.availableCoinPileList.Sort(CompareMapItemsByDisappearTime); HandleCoinPileGameEnd(); gui.RemoveMapItem(t.Position.X, t.Position.Y); break; } } foreach (CoinPile c in plunderCoinPileList) { if (c.Position == reqPoint) { con.PointsEarned += c.Price; con.Coins += c.Price; pointsEarned += c.Price; plunderCoinPileList.Remove(c); HandleCoinPileGameEnd(); gui.RemoveMapItem(c.Position.X, c.Position.Y); break; } } //Non occupied cell, May be a lifepack is here. foreach (LifePack l in GameEngine.availableLifePackList) { if (l.Position == reqPoint) { con.Health += (int)(0.1f * Constant.PLAYER_HEALTH); int lIndex = gameEng.DisappearLifePackList.IndexOf(l); GameEngine.availableLifePackList.Remove(l); GameEngine.availableLifePackList.Sort(CompareMapItemsByDisappearTime); gui.RemoveMapItem(l.Position.X, l.Position.Y); break; } } con.UpdatedTime = DateTime.Now; con.CurrentP = reqPoint; } } } else { con.Shot = true; activeBullets.Add(new Bullet(con, con.CurrentP, con.Direction)); } return null; }
private String ObstacleHit(Contestant con) { con.PointsEarned -= GameEngine.obstaclePenalty; con.UpdatedTime = DateTime.Now; return Constant.S2C_HITONOBSTACLE + ";" + GameEngine.obstaclePenalty + Constant.S2C_DEL; }
public AIMessage(Contestant con, String com) { contestant = con; command = com; }
public lk.ac.mrt.cse.pc11.AI.b e() { lk.ac.mrt.cse.pc11.AI.b b; b = new lk.ac.mrt.cse.pc11.AI.b(this.a.Position); Label_0014: return b; }
public void a(Contestant A_0, string A_1) { this.f.Add(new AIMessage(A_0, A_1)); return; }