コード例 #1
0
ファイル: game.cs プロジェクト: mikository/mqtt-game
 private void M_ShotResponseRecieved(object sender, EventArgs e)
 {
     if (myTurn)
     {
         WeaponResponseComm c = (WeaponResponseComm)sender;
         short field          = 0;
         if (c.result == null)
         {
             if (c.response == FireResponse.hit)
             {
                 //myTurn = true;
                 field = 3;
             }
             else
             {
                 field = 2;
                 //myTurn = false;
             }
         }
         else if (c.result == FireResult.sunk)
         {
             //myTurn = true;
             field = 4;
         }
         else     //implement o win
         {
             Won.Invoke(me, EventArgs.Empty);
         }
         myTurn = false;
         opponent.Battlefield.field[getIntFromLetter(c.x), c.y] = field;
     }
 }
コード例 #2
0
    public void AddPoints()
    {
        СountPoints += 200 + _coefficientOfPoints;
        ChangeColor();

        if (СountPoints >= _level.WinCountPoints)
        {
            _isOpacity = true;
            Won?.Invoke();
        }
    }
コード例 #3
0
 public void OnEnemyKilled()
 {
     if (_activeDeathRequiredAmount)
     {
         _currentEnemyDeath++;
         if (_currentEnemyDeath >= _deathRequiredAmount)
         {
             Won?.Invoke(_missionName);
             ChangeLevelStatus();
         }
     }
 }
コード例 #4
0
 public void OnPlayerReceivedDamage(bool receivedDamage)
 {
     if (_activeUntouchable)
     {
         if (receivedDamage == false)
         {
             Won?.Invoke(_missionName);
             ChangeLevelStatus();
         }
         else
         {
             MissionFailed?.Invoke(_missionName);
         }
     }
 }
コード例 #5
0
 public void OnTimeIsOver(float timeValue)
 {
     if (_activeTimeToHoldOut)
     {
         if (timeValue == 0)
         {
             Won?.Invoke(_missionName);
             ChangeLevelStatus();
         }
         else
         {
             MissionFailed?.Invoke(_missionName);
         }
     }
 }
コード例 #6
0
 public void Sunk(BattleshipShip ship)
 {
     player1.sunk.Add(ship);
     for (int i = 0; i < ship.size; i++)
     {
         rightBoard.cells[ship.positions[i][0] - 1, ship.positions[i][1] - 1].BackgroundImage = ship.components[i];
     }
     if (player1.sunk.Count == player1.myShips.Count)
     {
         finished = true;
         //rightBoard.ImgClick -= Guess1;
         Won?.Invoke(this, new OnWin {
             player = player1
         });
     }
 }
コード例 #7
0
 private void OnWon()
 {
     Won?.Invoke(this, new GameControllerEventArgs(this));
 }
コード例 #8
0
        private void Guess1(object sender, BattleshipBoard.ImgClickEventArgs e)
        {
            int x = e.coordinates[0] - 1, y = e.coordinates[1] - 1;

            if (!finished)
            {
                Guess();
            }

            void Guess()
            {
                if (player1.guesses[x, y] == 0)
                {
                    bool hit = false;
                    foreach (BattleshipShip ship in bot.myShips)
                    {
                        if (!hit)
                        {
                            int i = 0;
                            while (i < ship.size && !(ship.positions[i][0] == x + 1 && ship.positions[i][1] == y + 1))
                            {
                                i++;
                            }
                            if (i < ship.size)
                            {
                                hit = true;
                                player1.guesses[x, y] = 2;
                                Hit(new int[] { x, y }, rightBoard);
                                ship.hp -= 1;
                                if (ship.hp == 0)
                                {
                                    Sunk(ship);
                                }
                            }
                        }
                    }
                    if (!hit)
                    {
                        player1.guesses[x, y] = 1;
                        Miss(new int[] { x, y }, rightBoard);
                    }
                    //BOT GUESS
                    if (!finished)
                    {
                        hit = false;
                        int[] botGuess = bot.Guesser();
                        foreach (BattleshipShip ship in player1.myShips)
                        {
                            if (!hit)
                            {
                                int i = 0, xBot = botGuess[0] + 1, yBot = botGuess[1] + 1;
                                while (i < ship.size && !(ship.positions[i][0] == xBot && ship.positions[i][1] == yBot))
                                {
                                    i++;
                                }
                                if (i < ship.size)
                                {
                                    hit = true;
                                    bot.guesses[x, y] = 2;
                                    bot.Hit();
                                    Hit(botGuess, leftBoard);
                                    ship.hp -= 1;
                                    if (ship.hp == 0)
                                    {
                                        bot.sunk.Add(ship);
                                        if (bot.sunk.Count == bot.myShips.Count)
                                        {
                                            finished = true;
                                            Won?.Invoke(this, new OnWin {
                                                player = bot
                                            });
                                        }
                                    }
                                }
                            }
                        }
                        if (!hit)
                        {
                            bot.guesses[x, y] = 1;
                            Miss(botGuess, leftBoard);
                        }
                    }
                }
            }
        }
コード例 #9
0
ファイル: Level.cs プロジェクト: benjohns1/processor-game
 private void OnWon(WonArgs e)
 {
     Won?.Invoke(this, e);
 }