コード例 #1
0
        private int BattleshipWins()
        {
            List <List <string> > sum = SqlConnectionHandler.Query($"SELECT sum(score) FROM battleship WHERE score = 1");

            if (sum[0][0] != "")
            {
                return(int.Parse(sum[0][0]));
            }
            else
            {
                return(0);
            }
        }
コード例 #2
0
        private int Attempts(string table)
        {
            List <List <string> > result = SqlConnectionHandler.Query($"SELECT COUNT(id) FROM {table}");

            if (result.Count > 0)
            {
                return(int.Parse(result[0][0]));
            }
            else
            {
                return(0);
            }
        }
コード例 #3
0
        private void PlayTime()
        {
            List <List <string> > result = SqlConnectionHandler.Query("SELECT timeSpent FROM times");
            int seconds = 0;

            foreach (List <string> item in result)
            {
                string[] toTime = item[0].Split(':');
                seconds += int.Parse(toTime[0]) * 3600 + int.Parse(toTime[1]) * 60 + int.Parse(toTime[2]);
            }
            TimeSpan t = TimeSpan.FromSeconds(seconds);

            playTimeLabel.Text = "Play time:" + t.ToString("c");
        }
コード例 #4
0
ファイル: Snake.cs プロジェクト: RandomByteFF/Logic-games
        private void StartGame()
        {
            var highScore = SqlConnectionHandler.Query("SELECT MAX(score) FROM snake");

            if (highScore.Count != 0 && highScore[0][0] != "")
            {
                recordText.Text = highScore[0][0];
            }
            else
            {
                recordText.Text = "0";
            }
            SnakeSpawn();

            timer.Interval = Tick;

            CreateSprite(Properties.Resources.apple, new Vector2(), -2);
            NewApplePosition();
            headColor = false;
            tailColor = true;

            timer.Start();
        }
コード例 #5
0
        //DISPLAY WIN
        private void OnWinSingle(BattleshipPlayer winner)
        {
            ChangeView(menu, win);
            winnerLb.Text = winner.name + " WON!";
            List <List <string> > sum = new List <List <string> >();

            //INSERTING DATA TO THE TABLE
            try
            {
                if (SqlConnectionHandler.InitialSetup() == 0)
                {
                    if (winner.name != "BOT")
                    {
                        SqlConnectionHandler.RunNonQuery($"INSERT INTO battleship(score) VALUES(1)");
                    }
                    else
                    {
                        SqlConnectionHandler.RunNonQuery($"INSERT INTO battleship(score) VALUES(-1)");
                    }
                }
                //GETTING STATS
                sum = SqlConnectionHandler.Query($"SELECT sum(score) FROM battleship WHERE score = 1");
                if (sum.Count > 0)
                {
                    string ammount = Convert.ToString(sum[0][0]);
                    winStatisticsLabel.Text = "Wins against bot: " + ammount;
                }
                else
                {
                    winStatisticsLabel.Hide();
                }
            }
            catch
            {
                winStatisticsLabel.Hide();
            }
        }