예제 #1
0
        private void neuesSpielToolStripMenuItem_Click(object sender, EventArgs e)
        {
            NewGameForm f = new NewGameForm();

            if (f.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                _game = f.GameMode;
                _game.BDarsteller.Enabled = true;
                EnableBrett();
                ((BrettDarsteller)_game.BDarsteller).BrettUpdateEvent += UpdateBrett;
                ((BrettDarsteller)_game.BDarsteller).BrettEnableEvent += EnableBrett;
                _game.PlayerOutputEvent      += OutputPlayer;
                _game.WindowTitleChangeEvent += ChangeWindowTitle;
                _game.WinMessageEvent        += OutputWinMessage;
                OutputPlayer(_game.Player.Ausgabe());
                _game.Initialize();
                label1.Location = new Point(80, label1.Location.Y);
                if (_game.Player is Logik.Player.AIPlayer || _game.Player is Logik.Player.NetworkPlayer)
                {
                    _taskTurn = true;
                }
                if (_game is Logik.Game.NetworkGame)
                {
                    ((Logik.Game.NetworkGame)_game).newGameRequestReceivedEvent += ResetGame;
                }
                _spieler1Anfang = f.Spieler1Anfang;
                _spieler2Anfang = f.Spieler2Anfang;
            }
        }
예제 #2
0
파일: Game.cs 프로젝트: Postremus/UniTTT
 public Game(Logik.Game.Game gameMode)
 {
     _gameMode = gameMode;
     _gameMode.GetIntEvent += GetInt;
     _gameMode.GetStringEvent += Console.ReadLine;
     _gameMode.ShowMessageEvent += Console.WriteLine;
     _gameMode.WinMessageEvent += WinMessage;
     _gameMode.PlayerOutputEvent += PlayerOutput;
     _gameMode.WindowTitleChangeEvent += TitleChange;
     _gameMode.Initialize();
 }
예제 #3
0
파일: Game.cs 프로젝트: Postremus/UniTTT
 public Game(Logik.Game.Game gameMode)
 {
     _gameMode                         = gameMode;
     _gameMode.GetIntEvent            += GetInt;
     _gameMode.GetStringEvent         += Console.ReadLine;
     _gameMode.ShowMessageEvent       += Console.WriteLine;
     _gameMode.WinMessageEvent        += WinMessage;
     _gameMode.PlayerOutputEvent      += PlayerOutput;
     _gameMode.WindowTitleChangeEvent += TitleChange;
     _gameMode.Initialize();
 }
예제 #4
0
 public Form1()
 {
     InitializeComponent();
     _game = new Logik.Game.Game(new Logik.Player.Player('X'), new Logik.Player.Player('O'), new BrettDarsteller(3, 3), new Logik.Fields.Brett(3, 3));
     ((BrettDarsteller)_game.BDarsteller).BrettUpdateEvent += UpdateBrett;
     ((BrettDarsteller)_game.BDarsteller).BrettEnableEvent += EnableBrett;
     _game.PlayerOutputEvent      += OutputPlayer;
     _game.WindowTitleChangeEvent += ChangeWindowTitle;
     _game.WinMessageEvent        += OutputWinMessage;
     OutputPlayer(_game.Player1.Ausgabe());
     _game.Initialize();
     MouseClick     += MouseNewStart;
     _taskToken      = new CancellationTokenSource();
     _playerWaitTask = new Task(new Action(WaitForPlayerTask), _taskToken.Token);
     _playerWaitTask.Start();
     _isGameWindowClosed = false;
     FormClosed         += GameWindowClosedEvent;
 }
예제 #5
0
파일: Form1.cs 프로젝트: Postremus/UniTTT
 public Form1()
 {
     InitializeComponent();
     _game = new Logik.Game.Game(new Logik.Player.Player('X'), new Logik.Player.Player('O'), new BrettDarsteller(3, 3), new Logik.Fields.Brett(3, 3));
     ((BrettDarsteller)_game.BDarsteller).BrettUpdateEvent += UpdateBrett;
     ((BrettDarsteller)_game.BDarsteller).BrettEnableEvent += EnableBrett;
     _game.PlayerOutputEvent += OutputPlayer;
     _game.WindowTitleChangeEvent += ChangeWindowTitle;
     _game.WinMessageEvent += OutputWinMessage;
     OutputPlayer(_game.Player1.Ausgabe());
     _game.Initialize();
     MouseClick += MouseNewStart;
     _taskToken = new CancellationTokenSource();
     _playerWaitTask = new Task(new Action(WaitForPlayerTask), _taskToken.Token);
     _playerWaitTask.Start();
     _isGameWindowClosed = false;
     FormClosed += GameWindowClosedEvent;
 }
예제 #6
0
        public ScreenSaverForm(Color backColor)
        {
            InitializeComponent();
            LoadConfig();
            game         = new Logik.Game.Game(new Logik.Player.AIPlayer(3, 3, 3, 'X'), new Logik.Player.AIPlayer(3, 3, 3, 'O'), new BrettDarsteller(3, 3, Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height, _config.Matrix), null);
            moveTo       = new Point(0, 0);
            screenWidth  = Screen.PrimaryScreen.Bounds.Width;
            screenHeight = Screen.PrimaryScreen.Bounds.Height;

            FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;
            this.Bounds     = Screen.PrimaryScreen.Bounds;
            Cursor.Hide();
            TopMost = true;
            SetStyle(ControlStyles.SupportsTransparentBackColor, true);
            this.TransparencyKey = SystemColors.Control;
            BackColor            = backColor;

            RegisterEvents();

            ((BrettDarsteller)game.BDarsteller).DrawEvent += Draw;
            loopThread = new Thread(Loop);
        }
예제 #7
0
        public ScreenSaverForm(Color backColor)
        {
            InitializeComponent();
            LoadConfig();
            game = new Logik.Game.Game(new Logik.Player.AIPlayer(3, 3, 3, 'X'), new Logik.Player.AIPlayer(3, 3, 3, 'O'), new BrettDarsteller(3, 3, Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height, _config.Matrix), null);
            moveTo = new Point(0, 0);
            screenWidth = Screen.PrimaryScreen.Bounds.Width;
            screenHeight = Screen.PrimaryScreen.Bounds.Height;

            FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;
            this.Bounds = Screen.PrimaryScreen.Bounds;
            Cursor.Hide();
            TopMost = true;
            SetStyle(ControlStyles.SupportsTransparentBackColor, true);
            this.TransparencyKey = SystemColors.Control;
            BackColor = backColor;

            RegisterEvents();

            ((BrettDarsteller)game.BDarsteller).DrawEvent += Draw;
            loopThread = new Thread(Loop);
        }
예제 #8
0
파일: Program.cs 프로젝트: Postremus/UniTTT
        //ki:1 = Reinforcement
        //ki:2 = Recursion
        //ki:3 = Minimax
        //ki:4 = Like
        //ki:5 = Random7
        //ki:6 = Bot
        static void Main(string[] args)
        {
            Logik.Parameterdata        parameters  = Logik.ParameterInterpreter.InterpretCommandLine(args);
            Logik.Plugin.PluginManager plugManager = new Logik.Plugin.PluginManager();

            int width  = parameters.GetValue <int>("breite");
            int height = parameters.GetValue <int>("hoehe");

            if (!parameters.IsDefined("breite"))
            {
                width = 3;
            }
            if (!parameters.IsDefined("hoehe"))
            {
                height = 3;
            }

            Logik.Fields.Field field = new Logik.Fields.Brett(width, height);
            if (parameters.IsDefined("plugin"))
            {
                Logik.Plugin.IPlugin plugin = plugManager.Get(parameters.GetValue <string>("plugin"), Logik.Plugin.PluginTypes.Field);
                if (plugin is Logik.Fields.Field)
                {
                    field = (Logik.Fields.Field)plugin;
                    if (plugin is Logik.Plugin.IFieldPlugin)
                    {
                        if (((Logik.Plugin.IFieldPlugin)plugin).ForceFieldSize)
                        {
                            width  = field.Width;
                            height = field.Height;
                        }
                    }
                }
            }

            HumanPlayer hPlayer;
            char        aisymb;

            if (parameters.IsDefined("player"))
            {
                char symb = parameters.GetValue <char>("player");
                aisymb  = Logik.Player.Player.PlayerChange(symb);
                hPlayer = new HumanPlayer(symb);
            }
            else
            {
                hPlayer = new HumanPlayer('X');
                aisymb  = 'O';
            }

            Logik.Player.Player aiplayer = null;
            if (parameters.GetValue <int>("ki") != default(int))
            {
                aiplayer = new Logik.Player.AIPlayer(parameters.GetValue <int>("ki"), width, height, aisymb);
            }
            else if (parameters.GetValue <string>("ki") != default(string))
            {
                aiplayer = new Logik.Player.AIPlayer(parameters.GetValue <string>("ki"), width, height, aisymb);
            }

            if (parameters.IsDefined("help") && parameters.Count == 1)
            {
                Help();
            }
            else if (parameters.IsDefined("learn"))
            {
                if (parameters.IsDefined("human"))
                {
                    hPlayer.Learn();
                }
                else
                {
                    if (aiplayer == null)
                    {
                        throw new FormatException();
                    }
                    Console.Title = string.Format(CultureInfo.CurrentCulture, "UniTTT - {0} Lernmodus", aiplayer.ToString());
                    ((Logik.Player.AIPlayer)aiplayer).AI.ShowMessageEvent += Console.WriteLine;
                    ((Logik.Player.AIPlayer)aiplayer).AI.GetStringEvent   += Console.ReadLine;
                    ((Logik.Player.AIPlayer)aiplayer).AI.GetIntEvent      += GetInt;
                    aiplayer.Learn();
                }
            }
            else if (parameters.IsDefined("network"))
            {
                Logik.Network.Network client;
                string ip   = parameters.GetValue <string>("ip");
                int    port = parameters.GetValue <int>("port");
                if (parameters.GetValue <string>("protokoll") == "irc")
                {
                    client = new Logik.Network.IRCClient(ip, port, parameters.GetValue <string>("channel"));
                }
                else
                {
                    if (parameters.IsDefined("server"))
                    {
                        client = new Logik.Network.TCPServer(ip, port);
                    }
                    else
                    {
                        client = new Logik.Network.TCPClient(ip, port);
                    }
                }

                Logik.Game.Game gameMode = new Logik.Game.NetworkGame(hPlayer, new Logik.Player.NetworkPlayer(Logik.Player.Player.PlayerChange(hPlayer.Symbol), client), new BrettDarsteller(width, height), field, client);
                Game            g        = new Game(gameMode);
                g.Run();
            }
            else
            {
                Logik.Game.Game gameMode;
                BrettDarsteller bdar = new BrettDarsteller(width, height);
                if (parameters.IsDefined("kigame"))
                {
                    gameMode = new Logik.Game.Game(aiplayer, aiplayer, bdar, field);
                }
                else
                {
                    if (aiplayer != null)
                    {
                        gameMode = new Logik.Game.Game(hPlayer, aiplayer, bdar, field);
                    }
                    else
                    {
                        gameMode = new Logik.Game.Game(new HumanPlayer('X'), new HumanPlayer('O'), bdar, field);
                    }
                }
                Game g = new Game(gameMode);
                g.Run();
            }
        }
예제 #9
0
파일: Form1.cs 프로젝트: Postremus/UniTTT
 private void neuesSpielToolStripMenuItem_Click(object sender, EventArgs e)
 {
     NewGameForm f = new NewGameForm();
     if (f.ShowDialog() == System.Windows.Forms.DialogResult.OK)
     {
         _game = f.GameMode;
         _game.BDarsteller.Enabled = true;
         EnableBrett();
         ((BrettDarsteller)_game.BDarsteller).BrettUpdateEvent += UpdateBrett;
         ((BrettDarsteller)_game.BDarsteller).BrettEnableEvent += EnableBrett;
         _game.PlayerOutputEvent += OutputPlayer;
         _game.WindowTitleChangeEvent += ChangeWindowTitle;
         _game.WinMessageEvent += OutputWinMessage;
         OutputPlayer(_game.Player.Ausgabe());
         _game.Initialize();
         label1.Location = new Point(80, label1.Location.Y);
         if (_game.Player is Logik.Player.AIPlayer || _game.Player is Logik.Player.NetworkPlayer)
         {
             _taskTurn = true;
         }
         if (_game is Logik.Game.NetworkGame)
         {
             ((Logik.Game.NetworkGame)_game).newGameRequestReceivedEvent += ResetGame;
         }
         _spieler1Anfang = f.Spieler1Anfang;
         _spieler2Anfang = f.Spieler2Anfang;
     }
 }
예제 #10
0
파일: Program.cs 프로젝트: Postremus/UniTTT
        //ki:1 = Reinforcement
        //ki:2 = Recursion
        //ki:3 = Minimax
        //ki:4 = Like
        //ki:5 = Random7
        //ki:6 = Bot
        static void Main(string[] args)
        {
            Logik.Parameterdata parameters = Logik.ParameterInterpreter.InterpretCommandLine(args);
            Logik.Plugin.PluginManager plugManager = new Logik.Plugin.PluginManager();

            int width = parameters.GetValue<int>("breite");
            int height = parameters.GetValue<int>("hoehe");

            if (!parameters.IsDefined("breite"))
            {
                width = 3;
            }
            if (!parameters.IsDefined("hoehe"))
            {
                height = 3;
            }

            Logik.Fields.Field field = new Logik.Fields.Brett(width, height);
            if (parameters.IsDefined("plugin"))
            {
                Logik.Plugin.IPlugin plugin = plugManager.Get(parameters.GetValue<string>("plugin"), Logik.Plugin.PluginTypes.Field);
                if (plugin is Logik.Fields.Field)
                {
                    field = (Logik.Fields.Field)plugin;
                    if (plugin is Logik.Plugin.IFieldPlugin)
                    {
                        if (((Logik.Plugin.IFieldPlugin)plugin).ForceFieldSize)
                        {
                            width = field.Width;
                            height = field.Height;
                        }
                    }
                }
            }

            HumanPlayer hPlayer;
            char aisymb;
            if (parameters.IsDefined("player"))
            {
                char symb = parameters.GetValue<char>("player");
                aisymb = Logik.Player.Player.PlayerChange(symb);
                hPlayer = new HumanPlayer(symb);
            }
            else
            {
                hPlayer = new HumanPlayer('X');
                aisymb = 'O';
            }

            Logik.Player.Player aiplayer = null;
            if (parameters.GetValue<int>("ki") != default(int))
            {
                aiplayer = new Logik.Player.AIPlayer(parameters.GetValue<int>("ki"), width, height, aisymb);
            }
            else if (parameters.GetValue<string>("ki") != default(string))
            {
                aiplayer = new Logik.Player.AIPlayer(parameters.GetValue<string>("ki"), width, height, aisymb);
            }

            if (parameters.IsDefined("help") && parameters.Count == 1)
            {
                Help();
            }
            else if (parameters.IsDefined("learn"))
            {
                if (parameters.IsDefined("human"))
                {
                    hPlayer.Learn();
                }
                else
                {
                    if (aiplayer == null) throw new FormatException();
                    Console.Title = string.Format(CultureInfo.CurrentCulture, "UniTTT - {0} Lernmodus", aiplayer.ToString());
                    ((Logik.Player.AIPlayer)aiplayer).AI.ShowMessageEvent += Console.WriteLine;
                    ((Logik.Player.AIPlayer)aiplayer).AI.GetStringEvent += Console.ReadLine;
                    ((Logik.Player.AIPlayer)aiplayer).AI.GetIntEvent += GetInt;
                    aiplayer.Learn();
                }
            }
            else if (parameters.IsDefined("network"))
            {
                Logik.Network.Network client;
                string ip = parameters.GetValue<string>("ip");
                int port = parameters.GetValue<int>("port");
                if (parameters.GetValue<string>("protokoll") == "irc")
                {
                    client = new Logik.Network.IRCClient(ip, port, parameters.GetValue<string>("channel"));
                }
                else
                {
                    if (parameters.IsDefined("server"))
                    {
                        client = new Logik.Network.TCPServer(ip, port);
                    }
                    else
                    {
                        client = new Logik.Network.TCPClient(ip, port);
                    }
                }

                Logik.Game.Game gameMode = new Logik.Game.NetworkGame(hPlayer, new Logik.Player.NetworkPlayer(Logik.Player.Player.PlayerChange(hPlayer.Symbol), client), new BrettDarsteller(width, height), field, client);
                Game g = new Game(gameMode);
                g.Run();
            }
            else
            {
                Logik.Game.Game gameMode;
                BrettDarsteller bdar = new BrettDarsteller(width, height);
                if (parameters.IsDefined("kigame"))
                {
                    gameMode = new Logik.Game.Game(aiplayer, aiplayer, bdar, field);
                }
                else
                {
                    if (aiplayer != null)
                    {
                        gameMode = new Logik.Game.Game(hPlayer, aiplayer, bdar, field);
                    }
                    else
                    {
                        gameMode = new Logik.Game.Game(new HumanPlayer('X'), new HumanPlayer('O'), bdar, field);
                    }
                }
                Game g = new Game(gameMode);
                g.Run();
            }
        }