コード例 #1
0
ファイル: ConnectFour.cs プロジェクト: Nitzahon/Connect_Four
 public ConnectFour(Player player1, Player player2, List<Player> players)
 {
     InitializeComponent();
     p1 = player1;
     p2 = player2;
     pList = players;
 }
コード例 #2
0
ファイル: Players.cs プロジェクト: Nitzahon/Connect_Four
        private void btnLoad2_Click(object sender, EventArgs e)
        {
            try
            {

                lstPlayer2.Items.Clear();
                pList.Clear();
                string fulltext;
                string[] split;
                StreamReader infile;

                infile = File.OpenText("Leaderboards.txt");

                while (!infile.EndOfStream)
                {
                    fulltext = infile.ReadLine();
                    split = fulltext.Split(',');

                    Player player = new Player();
                    player.Name = split[0];
                    player.Color = System.Drawing.Color.FromName(split[1]);
                    player.GamesWon = Convert.ToInt16(split[2]);
                    pList.Add(player);
                }
                infile.Close();
                foreach (Player p in pList)
                {

                    lstPlayer2.Items.Add(p.Name + " " + p.Color + " " + p.GamesWon);

                }
            }
            catch(Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
コード例 #3
0
ファイル: LeaderBoards.cs プロジェクト: Nitzahon/Connect_Four
        private void LeaderBoards_Load(object sender, EventArgs e)
        {
            bool player1saved = false;
            bool player2saved = false;
            foreach (Player p in pList)
            {
                if (p.Name == p1.Name)
                {
                    p.GamesWon = p1.GamesWon;
                    player1saved = true;
                }
                if (p.Name == p2.Name)
                {
                    p.GamesWon = p2.GamesWon;
                    player2saved = true;
                }

            }

            if (player1saved == false)
            {
                Player player1 = new Player();
                player1.Name = p1.Name;
                player1.Color = p1.Color;
                player1.GamesWon = p1.GamesWon;
                pList.Add(player1);
                player1saved = true;
            }
            if (player2saved == false)
            {
                Player player2 = new Player();
                player2.Name = p2.Name;
                player2.Color = p2.Color;
                player2.GamesWon = p2.GamesWon;
                pList.Add(player2);
                player2saved = true;
            }
            if (player1saved && player2saved)
            {
                try
                {
                    StreamWriter outfile;
                    outfile = File.CreateText("Leaderboards.txt");

                    foreach (Player p in pList)
                    {
                        outfile.WriteLine(p.Name + "," + p.Color + "," + p.GamesWon);

                    }
                    outfile.Close();
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);

                }

            }

            lstLeaderboards.Items.Add("      Player Name        |       Wins");
            lstLeaderboards.Items.Add("-------------------------------------------------");
            foreach (Player p in pList)
            {
                lstLeaderboards.Items.Add(p.Name +"\t \t|  " + p.GamesWon);

            }
        }