public void updateGame() { try { GameBoard.getGameBoard.ClearBoard(); if (playerArray != null) { for (int x = 0; x < playerArray.Length; x++) { if ((playerArray != null) && (playerArray.Length != 0)) { if ((playerArray[x].IsAlive)) { GameBoard.getGameBoard.SetSquare(playerArray[x].currentP.X, playerArray[x].currentP.Y, playerArray[x].Direction.ToString(), playerArray[x].Suffix); MapItem mi = new MapItem(playerArray[x].currentP.X, playerArray[x].currentP.Y); if (coinList.Contains(mi)) { expiredCoins.Add(mi); } if (lifeList.Contains(mi)) { expiredMeds.Add(mi); } } } } } foreach (BrickWall brick in brickList) { GameBoard.getGameBoard.SetSquare(brick.Location.X, brick.Location.Y, brick.Type); } foreach (StoneWall stone in stoneList) { GameBoard.getGameBoard.SetSquare(stone.Location.X, stone.Location.Y, stone.Type); } foreach (Water water in waterList) { GameBoard.getGameBoard.SetSquare(water.Location.X, water.Location.Y, water.Type); } if (expiredCoins.Count != 0) { foreach (MapItem c in expiredCoins) { coinList.Remove(c); } expiredCoins.Clear(); } foreach (MapItem coin in coinList) { GameBoard.getGameBoard.SetSquare(coin.Position.X, coin.Position.Y, coin.Type); } if (expiredMeds.Count != 0) { foreach (MapItem m in expiredMeds) { lifeList.Remove(m); } expiredMeds.Clear(); } foreach (MapItem item in lifeList) { GameBoard.getGameBoard.SetSquare(item.Position.X, item.Position.Y, item.Type); } } catch (Exception ee) { Console.WriteLine("Update Game Error...........!!!!!!1"); } }
public void removeCoins(MapItem coins) { expiredCoins.Add(coins); }
public void removeMapItem(MapItem item) { expiredMeds.Add(item); }
//******************************************************************************************************************************************************** // private System.Object lockThis = new System.Object(); public void calDijkstra() { bool shoot = false; for (int k = 0; k < GameManager.playerCount; k++) { if (k != GameManager.playerIndex) { int ux = GameManager.playerArray[k].currentP.X; int uy = GameManager.playerArray[k].currentP.Y; int mx = GameManager.playerArray[GameManager.playerIndex].currentP.X; int my = GameManager.playerArray[GameManager.playerIndex].currentP.Y; if (mx == ux) { if ((my < uy) && (GameManager.playerArray[GameManager.playerIndex].Direction == 2)) { shootPlayer(); shoot = true; break; } else if ((my > uy) && (GameManager.playerArray[GameManager.playerIndex].Direction == 0)) { shootPlayer(); shoot = true; break; } } else if(my==uy) { if ((mx < ux) && (GameManager.playerArray[GameManager.playerIndex].Direction == 1)) { shootPlayer(); shoot = true; break; } else if ((mx > ux) && (GameManager.playerArray[GameManager.playerIndex].Direction == 3)) { shootPlayer(); shoot = true; break; } } } } if (!shoot) { //lock (lockThis) Monitor.Enter(this); { Console.WriteLine("Dij started !!"); // Dijkstra.getDijkstra.calDijkstra(0,0); // Dijkstra.getDijkstra.printDist(); try { Dijkstra.getDijkstra.calDijkstra(GameManager.playerArray[GameManager.playerIndex].currentP.X, GameManager.playerArray[GameManager.playerIndex].currentP.Y); int min = int.MaxValue; int mx = GameManager.playerArray[GameManager.playerIndex].currentP.X; int my = GameManager.playerArray[GameManager.playerIndex].currentP.Y; MapItem[] coins = new MapItem[GameManager.coinList.Count]; GameManager.coinList.CopyTo(coins); foreach (MapItem m in coins) { if (Dijkstra.dist[m.Position.X, m.Position.Y] < min) { min = Dijkstra.dist[m.Position.X, m.Position.Y]; mx = m.Position.X; my = m.Position.Y; } } AIManager.getAIManager.findNextMove(mx, my); //Console.WriteLine("Player x= ................ "+GameManager.playerArray[GameManager.playerIndex].currentP.X); //Dijkstra.getDijkstra.printDist(); //Dijkstra.getDijkstra.calDijkstra(9,0); //Dijkstra.getDijkstra.printDist(); //Dijkstra.getDijkstra.printPrevious(); //Thread.CurrentThread.Start(); } catch (Exception e) { Console.WriteLine("Coin Pile Error at calDijkstra...........!!!"); } // this.findNextMove(1,0); } Monitor.Exit(this); } }