예제 #1
0
 //Recursively Add all the tiles that this unit is able to atravel to
 public virtual void setAccessibleTiles(GameBoard.Tile currentTile, int distance)
 {
     if (distance > 0)
     {
         if ((currentTile.UP != null && (currentTile.UP.CurrentUnit == null ||
                                         (currentTile.UP.CurrentUnit.unitAllegiance == unitAllegiance))))
         {
             setAccessibleTiles(currentTile.UP, distance - 1);
             accessibleTiles.Add(currentTile.UP);
         }
         if ((currentTile.DOWN != null && (currentTile.DOWN.CurrentUnit == null ||
                                           (currentTile.DOWN.CurrentUnit.unitAllegiance == unitAllegiance))))
         {
             setAccessibleTiles(currentTile.DOWN, distance - 1);
             accessibleTiles.Add(currentTile.DOWN);
         }
         if ((currentTile.RIGHT != null && (currentTile.RIGHT.CurrentUnit == null ||
                                            (currentTile.RIGHT.CurrentUnit.unitAllegiance == unitAllegiance))))
         {
             setAccessibleTiles(currentTile.RIGHT, distance - 1);
             accessibleTiles.Add(currentTile.RIGHT);
         }
         if ((currentTile.LEFT != null && (currentTile.LEFT.CurrentUnit == null ||
                                           currentTile.LEFT.CurrentUnit.unitAllegiance == unitAllegiance)))
         {
             setAccessibleTiles(currentTile.LEFT, distance - 1);
             accessibleTiles.Add(currentTile.LEFT);
         }
     }
 }
예제 #2
0
 public virtual void moveUnit(GameBoard.Tile destination)
 {
     currentTile.CurrentUnit = null;
     destination.CurrentUnit = this;
     currentTile             = destination;
     Moved = true;
 }
예제 #3
0
        //recursively add all the tiles that unit is able to attack
        public virtual void setAttackTiles(GameBoard.Tile currentTile, int distance)
        {
            if (distance > 0)
            {
                GameBoard.Tile temp = currentTile;
                for (int i = 0; i < distance; i++)
                {
                    if (temp.UP != null)
                    {
                        accessibleTiles.Add(temp.UP);
                        temp = temp.UP;
                    }
                }

                temp = currentTile;
                for (int i = 0; i < distance; i++)
                {
                    if (temp.DOWN != null)
                    {
                        accessibleTiles.Add(temp.DOWN);
                        temp = temp.DOWN;
                    }
                }

                temp = currentTile;
                for (int i = 0; i < distance; i++)
                {
                    if (temp.LEFT != null)
                    {
                        accessibleTiles.Add(temp.LEFT);
                        temp = temp.LEFT;
                    }
                }

                temp = currentTile;
                for (int i = 0; i < distance; i++)
                {
                    if (temp.RIGHT != null)
                    {
                        accessibleTiles.Add(temp.RIGHT);
                        temp = temp.RIGHT;
                    }
                }
            }
        }
예제 #4
0
        public GameBoard(Game gameRef)
        {
            this.gameRef = gameRef;

            tiles     = new Tile[width, height];
            unitTable = new Dictionary <int, Unit>();

            for (int i = 0; i < width; i++)
            {
                for (int j = 0; j < height; j++)
                {
                    tiles[i, j] = new Tile();
                }
            }

            //set neighbors appropriately
            for (int i = 0; i < width; i++)
            {
                for (int j = 0; j < height; j++)
                {
                    GameBoard.Tile tile = tiles[i, j];

                    //set tile id e.g. 5,2
                    tile.x = i;
                    tile.y = j;

                    if (i != 0)
                    {
                        tile.DOWN = tiles[i - 1, j];
                    }
                    if (i != width - 1)
                    {
                        tile.UP = tiles[i + 1, j];
                    }
                    if (j != 0)
                    {
                        tile.RIGHT = tiles[i, j - 1];
                    }
                    if (j != height - 1)
                    {
                        tile.LEFT = tiles[i, j + 1];
                    }
                }
            }
        }
예제 #5
0
 public abstract ArrayList AttackTile(GameBoard.Tile tile);
예제 #6
0
파일: Game.cs 프로젝트: TenorioDan/projectH
        //we will remove the packet from the queue and act accordingly
        public void readPackets()
        {
            foreach (Player currentPlayer in players)
            {
                Queue <string> packetQueue = currentPlayer.playerClient.commandQueue;

                if (packetQueue.Count > 0)
                {
                    String   command = packetQueue.Peek();
                    string[] message = command.Split(new string[] { "\\" }, StringSplitOptions.None);
                    string   log     = "NETWORK LOG:";
                    foreach (string s in message)
                    {
                        log += s + "\\";
                    }

                    Console.WriteLine(log);

                    if (message[0].Equals("dontDisplayTip"))
                    {
                        dm.updateTooltip(currentPlayer.playerClient.clientName, Int32.Parse(message[1]));
                        packetQueue.Dequeue();
                    }
                    else if (currentPlayer.isMyTurn)
                    {
                        packetQueue.Dequeue();
                        //move message sends the command, the tile we are coming from and the tile we are going too
                        if (message[0].Equals("move"))
                        {
                            //if it is the turn of the client that sent this command
                            //AND if the tile we want to move to is in the list off accessible tiles of the object on the starting tile
                            //THEN we send a packet to both clients allow the object to move tiles.
                            if (currentPlayer.isMyTurn)
                            {
                                Unit           movingUnit      = board.getUnitByID(Int32.Parse(message[1]));
                                GameBoard.Tile startTile       = movingUnit.CurrentTile;
                                GameBoard.Tile destinationTile = board.Tiles[Int32.Parse(message[2]), Int32.Parse(message[3])];
                                movingUnit.setAccessibleTiles(startTile, movingUnit.MovementRange);

                                if (currentPlayer.playerAllegiance == movingUnit.unitAllegiance)
                                {
                                    if (currentPlayer.mana >= movingUnit.MovementCost)
                                    {
                                        if (!movingUnit.Paralyzed)
                                        {
                                            if (!movingUnit.Moved)
                                            {
                                                if (movingUnit.accessibleTiles.Contains(destinationTile))
                                                {
                                                    currentPlayer.mana -= movingUnit.MovementCost;

                                                    Console.WriteLine("LOG: moving unit from tile (" + startTile.x + "," + startTile.y + ") to tile(" + destinationTile.x + "," + destinationTile.y + ")");
                                                    movingUnit.moveUnit(destinationTile);
                                                    //Tell the clients to move the unit
                                                    if (!isAI_Game)
                                                    {
                                                        player2.playerClient.sw.WriteLine("move\\" + message[1] + "\\" + destinationTile.x + "\\" + destinationTile.y);
                                                    }
                                                    player1.playerClient.sw.WriteLine("move\\" + message[1] + "\\" + destinationTile.x + "\\" + destinationTile.y);
                                                }
                                                else
                                                {
                                                    Console.WriteLine("LOG: Tile is not in range.");

                                                    if (destinationTile.CurrentUnit == null)
                                                    {
                                                        Console.WriteLine("LOG: WTF");
                                                    }
                                                    else
                                                    {
                                                        Console.WriteLine("LOG: {0} ", destinationTile.CurrentUnit);
                                                    }
                                                }
                                            }
                                            else
                                            {
                                                Console.WriteLine("LOG: Unit has already moved");
                                            }
                                        }
                                        else
                                        {
                                            Console.WriteLine("LOG: Unit is paralyzed");
                                        }
                                    }
                                    else
                                    {
                                        Console.WriteLine("LOG: Player does not have enough mana.");
                                    }
                                }
                                else
                                {
                                    Console.WriteLine("LOG: Unit is not of same allegiance.");
                                }

                                movingUnit.accessibleTiles.Clear();
                            }
                            else
                            {
                                Console.WriteLine("LOG: It is not this player's turn");
                            }
                        }


                        else if (message[0].Equals("attack"))
                        {
                            if (currentPlayer.isMyTurn)
                            {
                                Unit           attackingUnit = board.getUnitByID(Int32.Parse(message[1]));
                                GameBoard.Tile tileToAttack  = board.Tiles[Int32.Parse(message[2]), Int32.Parse(message[3])];
                                attackingUnit.setAttackTiles(attackingUnit.CurrentTile, attackingUnit.AttackRange);

                                if (currentPlayer.playerAllegiance == attackingUnit.unitAllegiance)
                                {
                                    if (!attackingUnit.Paralyzed)
                                    {
                                        if (!attackingUnit.Attacked)
                                        {
                                            if (currentPlayer.mana >= attackingUnit.AttackCost)
                                            {
                                                if (attackingUnit.accessibleTiles.Contains(tileToAttack))
                                                {
                                                    Console.WriteLine("LOG: Unit {0} is attacking tile ({1}, {2})"
                                                                      , attackingUnit.UniqueID
                                                                      , tileToAttack.x
                                                                      , tileToAttack.y);
                                                    currentPlayer.mana -= attackingUnit.AttackCost;

                                                    //get a list of all the unit IDs that were attacked
                                                    //apply damage to all units
                                                    ArrayList unitIDs = attackingUnit.AttackTile(tileToAttack);
                                                    attackingUnit.Attacked = true;

                                                    sendAttackedUnits(unitIDs, attackingUnit);
                                                }


                                                else
                                                {
                                                    Console.WriteLine("LOG: Enemy is not in range.");
                                                }
                                            }
                                            else
                                            {
                                                Console.WriteLine("LOG: Player does not have enough mana to attack.");
                                            }
                                        }
                                        else
                                        {
                                            Console.WriteLine("LOG: Unit has already attacked");
                                        }
                                    }
                                    else
                                    {
                                        Console.WriteLine("LOG: Unit is paralyzed. Cannot Attack.");
                                    }
                                }
                                else
                                {
                                    Console.WriteLine("LOG: Unit is not of same allegiance.");
                                }

                                //fix this, should only need to perform this once
                                if (board.player1_Guardian.Health <= 0)
                                {
                                    board.player1_Soulstone.Invulnerable = false;
                                }
                                if (board.player2_Guardian.Health <= 0)
                                {
                                    board.player2_Soulstone.Invulnerable = false;
                                }

                                if (board.player1_Soulstone.Health <= 0)
                                {
                                    player1.playerClient.sw.WriteLine("defeat");
                                    if (!isAI_Game)
                                    {
                                        player2.playerClient.sw.WriteLine("victory");
                                    }
                                    gameOver = true;
                                    player1.playerClient.inGame = false;
                                    player2.playerClient.inGame = false;
                                }
                                else if (board.player2_Soulstone.Health <= 0)
                                {
                                    player1.playerClient.sw.WriteLine("victory");
                                    if (!isAI_Game)
                                    {
                                        player2.playerClient.sw.WriteLine("defeat");
                                    }
                                    gameOver = true;
                                    player1.playerClient.inGame = false;
                                    player2.playerClient.inGame = false;
                                }

                                attackingUnit.accessibleTiles.Clear();
                            }
                        }

                        else if (message[0].Equals("endTurn"))
                        {
                            if (currentPlayer.isMyTurn)
                            {
                                int maxMana = switchTurns();
                                player1.playerClient.sw.WriteLine("switchTurns\\{0}", maxMana);
                                if (!isAI_Game)
                                {
                                    player2.playerClient.sw.WriteLine("switchTurns\\{0}", maxMana);
                                }
                            }
                        }
                        else if (message[0].Equals("surrender"))
                        {
                            if (isAI_Game)
                            {
                                player1.playerClient.sw.WriteLine("defeat");
                            }
                            else
                            {
                                if (currentPlayer.playerAllegiance == Unit.Allegiance.PLAYER_1)
                                {
                                    player1.playerClient.sw.WriteLine("defeat");
                                    player2.playerClient.sw.WriteLine("victory");
                                }
                                else
                                {
                                    player1.playerClient.sw.WriteLine("victory");
                                    player2.playerClient.sw.WriteLine("defeat");
                                }
                            }

                            player1.playerClient.sw.WriteLine("enableMatchmaking");
                            player2.playerClient.sw.WriteLine("enableMatchmaking");
                            gameOver = true;
                            player1.playerClient.inGame = false;
                            player2.playerClient.inGame = false;
                        }
                    }
                }
            }
        }