Ejemplo n.º 1
0
 private void selectTile(Tile tile)
 {
     if (SelectedTile == tile)
     {
         deselectSelectedTile();
     }
     else if (SelectedTile == null)
     {
         SelectedTile          = tile;
         SelectedTile.Selected = true;
         updateCanvas          = true;
         spellShop.updateShop();
     }
     else
     {
         if ((tile.CurrentCharacter == null || tile.CurrentCharacter.team != Character.Teams.Red) &&
             (SelectedTile.CurrentCharacter == null || SelectedTile.CurrentCharacter.team != Character.Teams.Red))
         {
             if (IsHost && SelectedTile.Y >= grid.GridHeight / 2 && tile.Y >= grid.GridHeight / 2 ||
                 !IsHost && SelectedTile.Y < grid.GridHeight / 2 && tile.Y < grid.GridHeight / 2)
             {
                 SoundManager.PlaySound("swapCharacter.wav");
                 swapCharacters(tile, SelectedTile);
                 gameNetworkManager.enqueueMsg(NetworkMsgPrefix.CharacterSwap,
                                               GameNetworkUtilities.serializeCharacterSwap(tile, SelectedTile));
                 deselectSelectedTile();
             }
         }
     }
 }
Ejemplo n.º 2
0
        public void startGame()
        {
            gameNetworkManager.start();

            gameNetworkManager.enqueueMsg(NetworkMsgPrefix.NewPlayer, GameNetworkUtilities.serializePlayerHP(Player));

            gameStart();
            timer.Start();
        }
 private void upgradeSpell_click(object sender, MouseEventArgs e)
 {
     character.upgradeSpell(spell);
     Visible = false;
     gameNetworkManager.enqueueMsg(NetworkMsgPrefix.LevelUpSpell, GameNetworkUtilities.serializeSpellAction(spell, character.CurrentTile));
     shop.SpellShopView.ShowSpells(manager.SelectedTile.CurrentCharacter);
     if (!isNewSpell)
     {
         SoundManager.PlaySound("upgradeSpell.wav");
         Visible = false;
     }
 }
Ejemplo n.º 4
0
        private void sellChar_click(object sender, MouseEventArgs e)
        {
            gameManager.TeamBlue.Remove(selectedCharacter);
            selectedCharacter.hideAllSpellUI();
            selectedCharacter.CurrentTile.CurrentCharacter = null;
            gameNetworkManager.enqueueMsg(NetworkMsgPrefix.SellCharacter,
                                          GameNetworkUtilities.serializeTile(selectedCharacter.CurrentTile));

            gameManager.Player.Gold += gameManager.CharShop.CharacterPrice;
            SoundManager.PlaySound("BuyCharacter.wav");
            gameManager.deselectSelectedTile();
        }
Ejemplo n.º 5
0
        public GameManager(GameForm gameForm, string playerName, bool isHost, string ip, int port)
        {
            this.gameForm = gameForm;

            if (isHost)
            {
                IsHost             = isHost;
                gameNetworkManager = new GameServer(port);
                randomSeed         = (int)DateTime.Now.Ticks;
                gameNetworkManager.enqueueMsg(NetworkMsgPrefix.SetSeed,
                                              GameNetworkUtilities.serializeRandomSeed(randomSeed));
            }
            else
            {
                gameNetworkManager = new GameClient(ip, port);
            }

            grid = new Grid(GRID_WIDTH, GRID_HEIGHT,
                            (int)((gameForm.Width - (Tile.WIDTH * GRID_WIDTH)) / 3),
                            (int)((gameForm.Height - (Tile.HEIGHT * GRID_HEIGHT)) / 3) + 30,
                            this);

            TeamBlue = new List <Character>();
            TeamRed  = new List <Character>();

            Player = new Player(playerName, true);

            otherPlayers       = new List <Player>();
            playersLeaderBoard = new PlayersLeaderBoard(Player);

            CharShop  = new CharShop(gameForm, this);
            spellShop = new Shop(gameForm, this, gameNetworkManager);

            stageTimer   = new StageTimer(this);
            stageManager = new StageManager(stageTimer,
                                            TeamBlue,
                                            TeamRed,
                                            grid,
                                            Player,
                                            playersLeaderBoard,
                                            CharShop,
                                            this,
                                            gameNetworkManager);
            stageTimer.switchStageEvent += stageManager.switchStage;

            stopwatch = new Stopwatch();
            timer     = new Timer
            {
                Interval = GAMELOOP_INTERVAL
            };
            timer.Tick += new EventHandler(gameLoop);
        }
 private void buySkill_click(object sender, MouseEventArgs e)
 {
     if (manager.Player.Gold < SPELL_PRICE)
     {
         return;
     }
     SoundManager.PlaySound("learnSpell.wav");
     manager.Player.Gold -= SPELL_PRICE;
     character.learnSpell(spell);
     Visible = false;
     gameNetworkManager.enqueueMsg(NetworkMsgPrefix.LearnSpell, GameNetworkUtilities.serializeSpellAction(spell, character.CurrentTile));
     shop.SpellShopView.ShowSpells(manager.SelectedTile.CurrentCharacter);
     character.ChooseSpell.refreshPanel(character, character.ActiveSpells);
     character.InactiveSpell.refreshPanel(character.InactiveSpells);
 }
Ejemplo n.º 7
0
 public void AddCharacter(CharacterType[] characterType)
 {
     for (int j = grid.GridHeight - 1; j > (grid.GridHeight - 1) / 2; j--)
     {
         for (int i = grid.GridWidth - 1; i >= 0; i--)
         {
             (int ii, int jj) = IsHost ? (i, j) : (grid.GridWidth - 1 - i, grid.GridHeight - 1 - j);
             if (grid.Tiles[ii, jj].CurrentCharacter == null)
             {
                 Character item = new Character(grid, grid.Tiles[ii, jj], Character.Teams.Blue, characterType, this, gameNetworkManager);
                 TeamBlue.Add(item);
                 gameNetworkManager.enqueueMsg(NetworkMsgPrefix.NewCharacter, GameNetworkUtilities.serializeCharacter(item));
                 return;
             }
         }
     }
 }
 private MouseEventHandler mouseEvent(List <Spells[]> spells, int k, PictureBox pic)
 {
     return((sender, e) =>
     {
         int charIndex = character.gameManager.TeamBlue.IndexOf(character);
         Spells[] currentSpell = spells[k];
         if (character.ActiveSpells.Count == 0)
         {
             character.DefaultSkill = currentSpell;
             gameNetworkManager.enqueueMsg(NetworkMsgPrefix.DefaultSkill, GameNetworkUtilities.serializeSpellActionMoving(currentSpell, charIndex));
         }
         character.ActiveSpells.Add(currentSpell);
         gameNetworkManager.enqueueMsg(NetworkMsgPrefix.AddActiveSpells, GameNetworkUtilities.serializeSpellAction(currentSpell, character.CurrentTile));
         character.InactiveSpells.Remove(currentSpell);
         refreshPanel(character.InactiveSpells);
         character.ChooseSpell.refreshPanel(character, character.ActiveSpells);
     });
 }
Ejemplo n.º 9
0
        private void refreshServerList()
        {
            enableConnectTabControls(false);

            lbx_connectList.Items.Clear();
            ips.Clear();

            lbl_connectStatus.Visible = true;
            lbl_connectStatus.Refresh();

            lastPortScanned = int.Parse(txt_connectPort.Text);
            GameNetworkUtilities.ServerStats[] serversStats = GameNetworkUtilities.getServersInNetwork(lastPortScanned);
            ips.AddRange(serversStats);
            foreach (GameNetworkUtilities.ServerStats serverStats in serversStats)
            {
                lbx_connectList.Items.Add($"{serverStats.GameName}\t{serverStats.HostPlayerName}({serverStats.Ip})\t{serverStats.Ping}ms");
            }

            lbl_connectStatus.Visible = false;
            enableConnectTabControls(true);
        }
Ejemplo n.º 10
0
 private void Btn_manualConnect_Click(object sender, EventArgs e)
 {
     connectedIP   = txt_connectIP.Text;
     connectedPort = int.Parse(txt_connectPort.Text);
     GameNetworkUtilities.ServerStats serverStats = GameNetworkUtilities.pingIP(connectedIP, connectedPort);
     if (serverStats.Equals(GameNetworkUtilities.INVALID_SERVER))
     {
         MessageBox.Show($"Could NOT Ping {connectedIP}:{connectedPort}",
                         "Could NOT Ping",
                         MessageBoxButtons.OK,
                         MessageBoxIcon.Error);
     }
     else
     {
         connected();
         playerName = txt_connectPlayerName.Text;
         lbx_lobbyPlayerList.Items.Add($"{playerName}\t\t(Local)");
         setLobbyGameName(serverStats.GameName);
         lobbyClient = new LobbyClient(connectedIP, connectedPort, this, playerName);
         lobbyClient.connectToServer();
     }
 }
Ejemplo n.º 11
0
 private MouseEventHandler mouseEvent(List <Spells[]> actives, int k)
 {
     return((sender, e) =>
     {
         int charIndex = character.gameManager.TeamBlue.IndexOf(character);
         Spells[] currentSpell = actives[k];
         if (character.gameManager.CurrentGameStage == StageManager.GameStage.Buy && e.Button == MouseButtons.Right)
         {
             character.InactiveSpells.Add(currentSpell);
             character.ActiveSpells.Remove(currentSpell);
             gameNetworkManager.enqueueMsg(NetworkMsgPrefix.RemActiveSpells, GameNetworkUtilities.serializeSpellAction(currentSpell, character.CurrentTile));
             refreshPanel(character, character.ActiveSpells);
             character.InactiveSpell.refreshPanel(character.InactiveSpells);
         }
         if (e.Button == MouseButtons.Left)
         {
             if (character.gameManager.CurrentGameStage == StageManager.GameStage.Fight && character.Stats[StatusType.Charge] == character.Stats[StatusType.ChargeMax])
             {
                 character.gameManager.removeRangeFromForm(this);
                 character.SpellReady = false;
                 character.resetMana();
                 currentSpell[character.SpellLevel[currentSpell]].castSpell(character);
             }
             if (character.Stats[StatusType.Charge] / character.Stats[StatusType.ChargeMax] < 0.9)
             {
                 character.DefaultSkill = currentSpell;
                 gameNetworkManager.enqueueMsg(NetworkMsgPrefix.DefaultSkill, GameNetworkUtilities.serializeSpellActionMoving(currentSpell, charIndex));
                 //gameNetworkManager.enqueueMsg(NetworkMsgPrefix.DefaultSkill, GameNetworkUtilities.serializeSpellAction(currentSpell,character.CurrentTile));
                 spellSwap(k);
                 gameNetworkManager.enqueueMsg(NetworkMsgPrefix.ExchActiveSpells, GameNetworkUtilities.serializeSpellSwap(k, charIndex));
                 if (character.gameManager.CurrentGameStage == StageManager.GameStage.Fight && e.Button == MouseButtons.Left)
                 {
                     character.hideChooseSpellUI();
                 }
                 refreshPanel(character, character.ActiveSpells);
             }
         }
     });
 }
Ejemplo n.º 12
0
 private void levelUp_click(object sender, MouseEventArgs e)
 {
     if (gameManager.Player.Gold < selectedCharacter.CurrentLevel * 5 || gameManager.CurrentGameStage != StageManager.GameStage.Buy)
     {
         return;
     }
     SoundManager.PlaySound("Rise03.wav");
     gameManager.Player.Gold -= selectedCharacter.CurrentLevel * 5;
     selectedCharacter.levelUp();
     gameNetworkManager.enqueueMsg(NetworkMsgPrefix.LevelUpCharacter, GameNetworkUtilities.serializeTile(selectedCharacter.CurrentTile));
     viewCharStats();
     if (!(selectedCharacter.CurrentLevel < CharacterType.MAX_CHAR_LVL - 1))
     {
         btn_levelUp.Enabled = false;
         btn_levelUp.Text    = "Max level";
     }
     else
     {
         btn_levelUp.Text = "Level UP";
     }
     SelectedCharacterView.UpdateChanges();
 }
Ejemplo n.º 13
0
        public bool update()
        {
            if (spellsUIVisibleBuy)
            {
                gameManager.removeRangeFromForm(InactiveSpell, ChooseSpell);
                spellsUIVisibleBuy = false;
                return(true);
            }
            statusEffects = statusEffects.Where(effect =>
            {
                if (effect.RemoveEffectTimeStamp < gameManager.ElapsedTime)
                {
                    foreach (StatusEffect item in statusEffects)
                    {
                        if (statusEffects.IndexOf(effect) < statusEffects.IndexOf(item))
                        {
                            item.inverseValue();
                            applyStatusEffect(item);
                            effect.inverseValue();
                            applyStatusEffect(effect);
                            item.inverseValue();
                            applyStatusEffect(item);
                            return(false);
                        }
                    }
                    effect.inverseValue();
                    applyStatusEffect(effect);
                    return(false);
                }
                return(true);
            }).ToList();


            if (Stats[StatusType.Charge] == Stats[StatusType.ChargeMax] &&
                ActiveSpells.Count != 0)
            {
                if (DefaultSkill == null)
                {
                    int charIndex = gameManager.TeamBlue.IndexOf(this);
                    DefaultSkill = ActiveSpells[0];
                    gameNetworkManager.enqueueMsg(NetworkMsgPrefix.DefaultSkill, GameNetworkUtilities.serializeSpellActionMoving(ActiveSpells[0], charIndex));
                }
                DefaultSkill[SpellLevel[DefaultSkill]].castSpell(this);
                hideChooseSpellUI();
                resetMana();
            }

            if (ToMoveTo == null)
            {
                if (CurrentTarget == null ||
                    CurrentTarget.IsDead ||
                    PathFinding.getDistance(CurrentTile, CurrentTarget.CurrentTile) > Stats[StatusType.Range])
                {
                    List <Tile> path = null;
                    try
                    {
                        (path, CurrentTarget) = PathFinding.findPathToClosestEnemy(CurrentTile, team, grid, gameManager);
                    }
                    catch (PathFinding.PathNotFoundException)
                    {
                        return(false);
                    }
                    if (PathFinding.getDistance(CurrentTile, CurrentTarget.CurrentTile) > Stats[StatusType.Range])
                    {
                        ToMoveTo          = path[0];
                        ToMoveTo.Walkable = false;
                    }
                }
                else
                {
                    if (gameManager.ElapsedTime > nextAtttackTime)
                    {
                        nextAtttackTime = gameManager.ElapsedTime + Stats[StatusType.AttackSpeed];
                        CurrentTarget.takeDamage(Stats[StatusType.AttackDamage], DamageType.PhysicalDamage);
                        Stats[StatusType.Charge] = Math.Min(Stats[StatusType.Charge] + 4, Stats[StatusType.ChargeMax]);

                        return(true);
                    }
                }
            }
            return(false);
        }
Ejemplo n.º 14
0
        private bool applyNetworkMsg()
        {
            bool updateLeaderBoard = false;

            gameNetworkManager.DataReceived.TryDequeue(out string result);
            string[] msg = result.Split(GameNetworkManager.NETWORK_MSG_SEPARATOR);

            if (msg[0].Equals(NetworkMsgPrefix.CharacterSwap.getPrefix()))
            {
                (Tile tile, Tile selectedTile) = GameNetworkUtilities.parseCharacterSwap(msg, grid);
                swapCharacters(tile, selectedTile);
            }
            if (msg[0].Equals(NetworkMsgPrefix.SetSeed.getPrefix()))
            {
                randomSeed = Convert.ToInt32(msg[1]);
            }
            else if (msg[0].Equals(NetworkMsgPrefix.StageChange.getPrefix()))
            {
                (GameStage gameStage, bool HostWins) = GameNetworkUtilities.parseStage(msg[1], msg[2]);
                stageTimer.switchStageEvent();
                if (gameStage == GameStage.FightToBuy)
                {
                    if (HostWins)
                    {
                        foreach (Character character in TeamBlue.Where(e => !e.IsDead))
                        {
                            character.takeDamage(10000, DamageType.PhysicalDamage);
                        }
                    }
                    else
                    {
                        foreach (Character character in TeamRed.Where(e => !e.IsDead))
                        {
                            character.takeDamage(10000, DamageType.PhysicalDamage);
                        }
                    }
                }
            }
            else if (msg[0].Equals(NetworkMsgPrefix.NewCharacter.getPrefix()))
            {
                TeamRed.Add(CharStatToCharacter(GameNetworkUtilities.parseCharacter(msg)));
            }
            else if (msg[0].Equals(NetworkMsgPrefix.PlayerHealthUpdate.getPrefix()))
            {
                Player otherPlayer = otherPlayers.Find(player => player.Name.Equals(msg[1]));
                otherPlayer.Health = int.Parse(msg[2]);
                updateLeaderBoard  = true;
                if (otherPlayer.Health == 0)
                {
                    endGame("You Win");
                }
            }
            else if (msg[0].Equals(NetworkMsgPrefix.NewPlayer.getPrefix()))
            {
                Player player = new Player(msg[1])
                {
                    Health = int.Parse(msg[2])
                };
                otherPlayers.Add(player);
                playersLeaderBoard.addPlayers(player);
                updateLeaderBoard = true;
            }
            else if (msg[0].Equals(NetworkMsgPrefix.SellCharacter.getPrefix()))
            {
                Tile tile = grid.Tiles[int.Parse(msg[1]), int.Parse(msg[2])];
                TeamRed.Remove(tile.CurrentCharacter);
                tile.CurrentCharacter = null;
                spellShop.updateShop();
            }
            else if (msg[0].Equals(NetworkMsgPrefix.LevelUpCharacter.getPrefix()))
            {
                grid.Tiles[int.Parse(msg[1]), int.Parse(msg[2])].CurrentCharacter.levelUp();
                spellShop.updateShop();
            }
            else if (msg[0].Equals(NetworkMsgPrefix.LevelUpSpell.getPrefix()))
            {
                grid.Tiles[int.Parse(msg[1]), int.Parse(msg[2])].CurrentCharacter.upgradeSpell(Spells.getSpell(int.Parse(msg[3])));
            }
            else if (msg[0].Equals(NetworkMsgPrefix.LearnSpell.getPrefix()))
            {
                grid.Tiles[int.Parse(msg[1]), int.Parse(msg[2])].CurrentCharacter.learnSpell(Spells.getSpell(int.Parse(msg[3])));
            }
            else if (msg[0].Equals(NetworkMsgPrefix.DefaultSkill.getPrefix()))
            {
                TeamRed[int.Parse(msg[1])].DefaultSkill = Spells.getSpell(int.Parse(msg[2]));
            }
            else if (msg[0].Equals(NetworkMsgPrefix.AddActiveSpells.getPrefix()))
            {
                Character character = grid.Tiles[int.Parse(msg[1]), int.Parse(msg[2])].CurrentCharacter;
                character.ActiveSpells.Add(Spells.getSpell(int.Parse(msg[3])));
                character.ChooseSpell.refreshPanel(character, character.ActiveSpells);
            }
            else if (msg[0].Equals(NetworkMsgPrefix.RemActiveSpells.getPrefix()))
            {
                Character character = grid.Tiles[int.Parse(msg[1]), int.Parse(msg[2])].CurrentCharacter;
                character.ActiveSpells.Remove(Spells.getSpell(int.Parse(msg[3])));
                character.ChooseSpell.refreshPanel(character, character.ActiveSpells);
            }
            else if (msg[0].Equals(NetworkMsgPrefix.ExchActiveSpells.getPrefix()))
            {
                Character character = TeamRed[int.Parse(msg[1])];
                character.ChooseSpell.spellSwap(int.Parse(msg[2]));
                character.ChooseSpell.refreshPanel(character, character.ActiveSpells);
            }
            else if (msg[0].Equals("EXIT"))
            {
                timer.Stop();
                MessageBox.Show("Disconnected", "Disconnected", MessageBoxButtons.OK, MessageBoxIcon.Error);
                gameForm.Close();
            }
            return(updateLeaderBoard);
        }