Exemple #1
0
        public Game(GameStartConfig gs, Label statusLabel, Dictionary<int, Button> MapButton, GameForm fm)
        {
            sl = statusLabel;
            btnMap = MapButton;
            form = fm;
            switch (gs.GM)
            {
                case GameMode.HumanVSHuman:
                    p1 = new Human() { Name = gs.Player1Name, ID = "X" };
                    p2 = new Human() { Name = gs.Player2Name, ID = "O" };
                    break;
                case GameMode.HumanVSAI:
                    p1 = new Human() { Name = gs.Player1Name, ID = "X" };
                    p2 = new AI() { Name = "[AI] " + RandomName.GetName(p1.Name), ID = "O", currentDifficulty = gs.Difficulty };
                    break;
                case GameMode.AIVSAI:
                    p1 = new AI() { Name = "[AI] " + RandomName.GetName(""), ID = "X", currentDifficulty = gs.Difficulty };
                    p2 = new AI() { Name = "[AI] " + RandomName.GetName(""), ID = "O", currentDifficulty = gs.Difficulty };
                    break;
                default:
                    break;
            }
            Players = new LinkedList<Player>();
            Players.AddLast(p1);
            Players.AddLast(p2);
            pCur = Players.First;

            fm.Text = string.Format("{0} VS {1}", p1.Name, p2.Name);
            WriteTurn();

            if (p1 is AI)
                p1.Move(this);
        }
        public GameForm(StartForm fm1, GameStartConfig gs)
        {
            InitializeComponent();

            MapButton = new Dictionary<int, Button>();

            for (int i = 1; i <= 9; i++)
                MapButton.Add(i, Controls.Find("button_" + i, false).Single() as Button);

            game = new Game(gs, statusLabel, MapButton, this);
            fm = fm1;
            log = gs.Log;
            tlog();
        }
 private void button1_Click(object sender, EventArgs e)
 {
     if (GM == GameMode.AIVSAI)
     {
         gsc = new GameStartConfig() { GM = GM, Difficulty = DIFF, Log = false };
         new GameForm(this, gsc).Show();
         this.Hide();
         return;
     }
     if (string.IsNullOrWhiteSpace(textBox1.Text))
     {
         MessageBox.Show("Player 1 Name cannot be empty!!!", "Error!", MessageBoxButtons.OK, MessageBoxIcon.Error);
         return;
     }
     if (GM == GameMode.HumanVSHuman)
         if (string.IsNullOrWhiteSpace(textBox2.Text))
         {
             MessageBox.Show("Player 2 Name cannot be empty!!!", "Error!", MessageBoxButtons.OK, MessageBoxIcon.Error);
             return;
         }
     gsc = new GameStartConfig() { GM = GM, Player1Name = textBox1.Text, Player2Name = textBox2.Text, Difficulty = DIFF, Log = false };
     new GameForm(this, gsc).Show();
     this.Hide();
 }