コード例 #1
0
        public void Hit(Point point)
        {
            var ship = ships.FirstOrDefault(n => n.Points.Any(p => p == point));

            if (ship == null)
            {
                MissPoints.Add(point);
                var btn = Buttons.First(n => n.Coordinates() == point);
                btn.IsEnabled       = false;
                btn.BackgroundColor = Color.DarkBlue;
                btn.BorderColor     = Color.DarkBlue;
            }
            else
            {
                ship.HitPoints.Add(point);
                if (ship.Sank)
                {
                    var btns = new List <Button>();
                    ship.Points.ForEach(n => btns.Add(Buttons.First(b => b.Coordinates() == n)));
                    btns.ForEach(b =>
                    {
                        b.IsEnabled       = false;
                        b.BackgroundColor = Color.DarkRed;

                        b.FontAttributes = FontAttributes.Bold;
                    });
                }
                else
                {
                    var btn = Buttons.First(b => b.Coordinates() == point);
                    btn.IsEnabled       = false;
                    btn.BackgroundColor = Color.Red;
                }
            }
            if (ships.All(n => n.Sank))
            {
                GameOverAction.Invoke();
            }
        }
コード例 #2
0
ファイル: Game.cs プロジェクト: Nic1493/Picross
    //check if current puzzle data matches loaded puzzle data
    void CheckGameOver(CellData cellData)
    {
        for (int r = 0; r < targetPuzzleData.RowCount; r++)
        {
            for (int c = 0; c < targetPuzzleData.ColCount; c++)
            {
                //only necessary to check all filled cells
                if (cellData.Cells[r, c] == CellType.Filled || targetPuzzleData.cellData.Cells[r, c] == CellType.Filled)
                {
                    //compare CellTypes; stop checking once a match isn't found
                    if (cellData.Cells[r, c] != targetPuzzleData.cellData.Cells[r, c])
                    {
                        return;
                    }
                }
            }
        }

        //if all filled cells in game match text file data, call gameover functions
        currentPuzzleData.completionStatus = CompletionStatus.Complete;
        targetPuzzleData.SaveAsCompletedImage();
        GameOverAction?.Invoke();
    }
コード例 #3
0
 public void GameOverInvoke()
 {
     GameOverAction?.Invoke();
 }