public Shot enemyFired(Shot shot)
        {
            if (data.isBlockOccupied(shot.Coords))
            {
                data.setMyBoxState(shot.Coords.X, shot.Coords.Y,
                                   GameData.BoxState.BOMBED);
                shot.Hit = true;
            }
            else
            {
                data.setMyBoxState(shot.Coords.X, shot.Coords.Y,
                                   GameData.BoxState.MISSED);
                shot.Hit = false;
            }

            if (gameForm.InvokeRequired)
            {
                InvalidateCallback epc = new InvalidateCallback(gameForm.Invalidate);
                gameForm.Invoke(epc);
            }
            else
            {
                gameForm.Invalidate();
            }



            return(shot);
        }
        /// <summary>
        /// kaleitai ap to duktio pros epivevaiwsh ths volhs mas
        /// k enhmerwnei to diko mas enemyGrid tou UI.
        /// </summary>
        /// <param name="shot"></param>

        public bool shotResult(Shot shot)
        {
            if (shot.Confirmed == false)
            {
                //this is an error handling and the false means that the game is over
                return(false);
            }


            if (shot.Hit)
            {
                data.setEnemyBoxState(shot.Coords.X, shot.Coords.Y,
                                      GameData.BoxState.BOMBED);
            }
            else
            {
                data.setEnemyBoxState(shot.Coords.X, shot.Coords.Y,
                                      GameData.BoxState.MISSED);
            }

            if (gameForm.InvokeRequired)
            {
                InvalidateCallback epc = new InvalidateCallback(gameForm.Invalidate);
                gameForm.Invoke(epc);
            }
            else
            {
                gameForm.Invalidate();
            }

            return(!checkEndGame());
        }
示例#3
0
        /// <returns>true iff any frames were invalidated</returns>
        public bool Invalidate(int frame)
        {
            if (!Any())
            {
                return(false);
            }
            if (frame == 0)
            {
                frame = 1;                         // Never invalidate frame 0
            }
            var statesToRemove = _states.Where(s => s.Key >= frame).ToList();

            foreach (var state in statesToRemove)
            {
                Remove(state.Key);
            }
            InvalidateCallback?.Invoke(frame);
            return(statesToRemove.Count != 0);
        }
示例#4
0
        public bool Invalidate(int frame)
        {
            bool anyInvalidated = false;

            if (Any())
            {
                if (frame == 0)                 // Never invalidate frame 0
                {
                    frame = 1;
                }

                List <KeyValuePair <int, byte[]> > statesToRemove = _states.Where(s => s.Key >= frame).ToList();
                anyInvalidated = statesToRemove.Any();

                foreach (var state in statesToRemove)
                {
                    Remove(state.Key);
                }

                InvalidateCallback?.Invoke(frame);
            }

            return(anyInvalidated);
        }