예제 #1
0
        public EasyGamePage()
        {
            InitializeComponent();

            string songPath = startupPath + "/sound/music/Soundtrack.mp3";

            soundTrackMediaPlayer.Open(new Uri(songPath));
            soundTrackMediaPlayer.MediaEnded += new EventHandler(Song_Ended);
            soundTrackMediaPlayer.Play();
            if (!SoundSetting.MusicOn)
            {
                soundTrackMediaPlayer.IsMuted = true;
            }

            buttonNames = new Dictionary <string, Button>();
            allButtons  = GameBoard.Children.OfType <Button>();
            foreach (Button b in allButtons)
            {
                buttonNames.Add(b.Name.ToString(), b);
            }

            engine = new KulamiEngine();
            engine.StartGame(GameType.LocalComputer);
            AI = new EasyAI(engine.CurrentGame);
            soundEffectPlayer.PlayStartGameSound();

            Random rndMoveFirst = new Random();
            int    playFirst    = rndMoveFirst.Next(0, 2);

            if (playFirst == 1)
            {
                player1turn = true;
            }
            else
            {
                player1turn = false;
                PlayerTurnLabel.Visibility   = Visibility.Hidden;
                ComputerTurnLabel.Visibility = Visibility.Visible;
                try
                {
                    MakeAIMove();
                }
                catch
                { }
            }

            InitializeImages();
        }
예제 #2
0
        public EasyGamePage()
        {
            InitializeComponent();

            string songPath = startupPath + "/sound/music/Soundtrack.mp3";
            soundTrackMediaPlayer.Open(new Uri(songPath));
            soundTrackMediaPlayer.MediaEnded += new EventHandler(Song_Ended);
            soundTrackMediaPlayer.Play();
            if (!SoundSetting.MusicOn)
                soundTrackMediaPlayer.IsMuted = true;

            buttonNames = new Dictionary<string, Button>();
            allButtons = GameBoard.Children.OfType<Button>();
            foreach (Button b in allButtons)
            {
                buttonNames.Add(b.Name.ToString(), b);
            }

            engine = new KulamiEngine();
            engine.StartGame(GameType.LocalComputer);
            AI = new EasyAI(engine.CurrentGame);
            soundEffectPlayer.PlayStartGameSound();

            Random rndMoveFirst = new Random();
            int playFirst = rndMoveFirst.Next(0, 2);

            if (playFirst == 1)
                player1turn = true;
            else
            {
                player1turn = false;
                PlayerTurnLabel.Visibility = Visibility.Hidden;
                ComputerTurnLabel.Visibility = Visibility.Visible;
                try
                {
                    MakeAIMove();
                }
                catch
                { }
            }

            InitializeImages();
        }
예제 #3
0
        public GamePage(bool easyLevel, GameType gType)
        {
            InitializeComponent();

            string songPath = startupPath + "/sound/music/Soundtrack.mp3";
            soundTrackMediaPlayer.Open(new Uri(songPath));
            soundTrackMediaPlayer.MediaEnded += new EventHandler(Song_Ended);
            soundTrackMediaPlayer.Play();

            if (gType == GameType.LANMultiplayer)
            {
                networkPeer = new LidgrenKulamiPeer.KulamiPeer(3070);
                //wait until connection is established
            }

            buttonNames = new Dictionary<string,Button>();
            allButtons = GameBackground.Children.OfType<Button>();
            foreach (Button b in allButtons)
            {
                buttonNames.Add(b.Name.ToString(), b);
            }

            int networkingBoardNum = 0;
            if (gType == GameType.LANMultiplayer)
            {
                Random rnd = new Random();
                int myRandomBoardNum = rnd.Next(1, 8);

                networkPeer.sendMove(myRandomBoardNum.ToString());
                int opponentRandomBoardNum = Convert.ToInt32(networkPeer.getMove());
                
                networkingBoardNum = (myRandomBoardNum + opponentRandomBoardNum)/2;
                while (myRandomBoardNum == opponentRandomBoardNum)
                {
                    myRandomBoardNum = rnd.Next(1, 8);
                    networkPeer.sendMove(myRandomBoardNum.ToString());
                    opponentRandomBoardNum = Convert.ToInt32(networkPeer.getMove());
                }
                if (myRandomBoardNum > opponentRandomBoardNum)
                    player1turn = true;
                else
                    player1turn = false;
            }

            engine = new KulamiEngine();
            if (gType == GameType.LANMultiplayer)
                engine.StartGame(gType, networkingBoardNum);
            else
                engine.StartGame(gType);

            easyLevelAIOn = easyLevel;
           
            if (engine.CurrentGame.GameType != GameType.LANMultiplayer)
            {
                Random rndMoveFirst = new Random();
                int playFirst = rndMoveFirst.Next(0, 2);

                if (playFirst == 1)
                    player1turn = true;
                else
                    player1turn = false;
            }

            if (engine.CurrentGame.GameType == GameType.LocalComputer)
            {
                if (easyLevelAIOn)
                    easyAI = new EasyAI(engine.CurrentGame);
                else
                    hardAI = new HardAI(engine.CurrentGame);
            }

            ImageBrush ib = new ImageBrush();
            ib.ImageSource = new BitmapImage(new Uri(startupPath + "/images/GameBoard" + engine.GameBoardNumber + ".png", UriKind.Absolute));
            BoardBackground.Background = ib;

            ImageBrush gb = new ImageBrush();
            gb.ImageSource = new BitmapImage(new Uri(startupPath + "/images/GameBackground.jpg", UriKind.Absolute));
            backgroundButton.Background = gb;

            ImageBrush sb = new ImageBrush();
            sb.ImageSource = new BitmapImage(new Uri(startupPath + "/images/soundOnButton.png", UriKind.Absolute));
            toggleSound_Btn.Background = sb;

            ImageBrush rb = new ImageBrush();
            rb.ImageSource = new BitmapImage(new Uri(startupPath + "/images/radarOnButton.png", UriKind.Absolute));
            toggleRadar_Btn.Background = rb;

            ImageBrush mb = new ImageBrush();
            mb.ImageSource = new BitmapImage(new Uri(startupPath + "/images/musicOnButton.png", UriKind.Absolute));
            toggleMusicBtn.Background = mb;
            
            ImageBrush ButtonImage = new ImageBrush();
            ButtonImage.ImageSource = new BitmapImage(new Uri(startupPath + "/images/GenericPlan.png", UriKind.Absolute));
            ApplyBackgroundButtons(ButtonImage);

            ImageBrush RedConquer = new ImageBrush();
            RedConquer.ImageSource = new BitmapImage(new Uri(startupPath + "/images/PlanConquerRed.png", UriKind.Absolute));
            planetConquerOne.Background = RedConquer;

            ImageBrush BlueConquer = new ImageBrush();
            BlueConquer.ImageSource = new BitmapImage(new Uri(startupPath + "/images/PlanConquerBlue.png", UriKind.Absolute));
            planetConquerTwo.Background = BlueConquer;

            DoubleAnimation fadeInAnimation = new DoubleAnimation();
            fadeInAnimation.From = 0.0;
            fadeInAnimation.To = 1.0;
            fadeInAnimation.Duration = new Duration(TimeSpan.FromSeconds(2));

            DoubleAnimation fadeOutAnimation = new DoubleAnimation();
            fadeOutAnimation.From = 1.0;
            fadeOutAnimation.To = 0.1;
            fadeOutAnimation.Duration = new Duration(TimeSpan.FromSeconds(2));

            DoubleAnimation planetConquerOneAnimation = new DoubleAnimation();
            planetConquerOneAnimation.From = 0.0;
            planetConquerOneAnimation.To = 1.0;
            planetConquerOneAnimation.Duration = new Duration(TimeSpan.FromSeconds(0.3));
            planetConquerOneAnimation.AutoReverse = true;

            DoubleAnimation planetConquerTwoAnimation = new DoubleAnimation();
            planetConquerTwoAnimation.From = 0.0;
            planetConquerTwoAnimation.To = 1.0;
            planetConquerTwoAnimation.Duration = new Duration(TimeSpan.FromSeconds(0.3));
            planetConquerTwoAnimation.AutoReverse = true;

            gameOverStoryboard = new Storyboard();
            HumanConquerStoryboard = new Storyboard();
            AIConquerStoryboard = new Storyboard();

            gameOverStoryboard.Children.Add(fadeInAnimation);
            gameOverStoryboard.Children.Add(fadeOutAnimation);
            HumanConquerStoryboard.Children.Add(planetConquerOneAnimation);
            AIConquerStoryboard.Children.Add(planetConquerTwoAnimation);

            Storyboard.SetTargetName(fadeInAnimation, WinnerLabel.Name);
            Storyboard.SetTargetProperty(fadeInAnimation, new PropertyPath(Rectangle.OpacityProperty));
            Storyboard.SetTargetName(fadeOutAnimation, GameBackground.Name);
            Storyboard.SetTargetProperty(fadeOutAnimation, new PropertyPath(Rectangle.OpacityProperty));

            Storyboard.SetTargetName(planetConquerOneAnimation, planetConquerOne.Name);
            Storyboard.SetTargetProperty(planetConquerOneAnimation, new PropertyPath(Rectangle.OpacityProperty));

            Storyboard.SetTargetName(planetConquerTwoAnimation, planetConquerTwo.Name);
            Storyboard.SetTargetProperty(planetConquerTwoAnimation, new PropertyPath(Rectangle.OpacityProperty));

            soundEffectPlayer.PlayStartGameSound();

            if (!player1turn && engine.CurrentGame.GameType == GameType.LocalComputer)
            {
                PlayerTurnLabel.Visibility = Visibility.Hidden;
                ComputerTurnLabel.Visibility = Visibility.Visible;
                MakeAIMove();
            }
            else if (engine.CurrentGame.GameType == GameType.LocalMultiplayer)
            {
                PlayerTurnLabel.Visibility = Visibility.Hidden;
                ComputerTurnLabel.Visibility = Visibility.Hidden;

                if (player1turn)
                    PlayerOneTurnLabel.Visibility = Visibility.Visible;
                else
                    PlayerTwoTurnLabel.Visibility = Visibility.Visible;
            }
        }
예제 #4
0
        public GamePage(bool easyLevel, GameType gType)
        {
            InitializeComponent();

            string songPath = startupPath + "/sound/music/Soundtrack.mp3";

            soundTrackMediaPlayer.Open(new Uri(songPath));
            soundTrackMediaPlayer.MediaEnded += new EventHandler(Song_Ended);
            soundTrackMediaPlayer.Play();

            if (gType == GameType.LANMultiplayer)
            {
                networkPeer = new LidgrenKulamiPeer.KulamiPeer(3070);
                //wait until connection is established
            }

            buttonNames = new Dictionary <string, Button>();
            allButtons  = GameBackground.Children.OfType <Button>();
            foreach (Button b in allButtons)
            {
                buttonNames.Add(b.Name.ToString(), b);
            }

            int networkingBoardNum = 0;

            if (gType == GameType.LANMultiplayer)
            {
                Random rnd = new Random();
                int    myRandomBoardNum = rnd.Next(1, 8);

                networkPeer.sendMove(myRandomBoardNum.ToString());
                int opponentRandomBoardNum = Convert.ToInt32(networkPeer.getMove());

                networkingBoardNum = (myRandomBoardNum + opponentRandomBoardNum) / 2;
                while (myRandomBoardNum == opponentRandomBoardNum)
                {
                    myRandomBoardNum = rnd.Next(1, 8);
                    networkPeer.sendMove(myRandomBoardNum.ToString());
                    opponentRandomBoardNum = Convert.ToInt32(networkPeer.getMove());
                }
                if (myRandomBoardNum > opponentRandomBoardNum)
                {
                    player1turn = true;
                }
                else
                {
                    player1turn = false;
                }
            }

            engine = new KulamiEngine();
            if (gType == GameType.LANMultiplayer)
            {
                engine.StartGame(gType, networkingBoardNum);
            }
            else
            {
                engine.StartGame(gType);
            }

            easyLevelAIOn = easyLevel;

            if (engine.CurrentGame.GameType != GameType.LANMultiplayer)
            {
                Random rndMoveFirst = new Random();
                int    playFirst    = rndMoveFirst.Next(0, 2);

                if (playFirst == 1)
                {
                    player1turn = true;
                }
                else
                {
                    player1turn = false;
                }
            }

            if (engine.CurrentGame.GameType == GameType.LocalComputer)
            {
                if (easyLevelAIOn)
                {
                    easyAI = new EasyAI(engine.CurrentGame);
                }
                else
                {
                    hardAI = new HardAI(engine.CurrentGame);
                }
            }

            ImageBrush ib = new ImageBrush();

            ib.ImageSource             = new BitmapImage(new Uri(startupPath + "/images/GameBoard" + engine.GameBoardNumber + ".png", UriKind.Absolute));
            BoardBackground.Background = ib;

            ImageBrush gb = new ImageBrush();

            gb.ImageSource = new BitmapImage(new Uri(startupPath + "/images/GameBackground.jpg", UriKind.Absolute));
            backgroundButton.Background = gb;

            ImageBrush sb = new ImageBrush();

            sb.ImageSource             = new BitmapImage(new Uri(startupPath + "/images/soundOnButton.png", UriKind.Absolute));
            toggleSound_Btn.Background = sb;

            ImageBrush rb = new ImageBrush();

            rb.ImageSource             = new BitmapImage(new Uri(startupPath + "/images/radarOnButton.png", UriKind.Absolute));
            toggleRadar_Btn.Background = rb;

            ImageBrush mb = new ImageBrush();

            mb.ImageSource            = new BitmapImage(new Uri(startupPath + "/images/musicOnButton.png", UriKind.Absolute));
            toggleMusicBtn.Background = mb;

            ImageBrush ButtonImage = new ImageBrush();

            ButtonImage.ImageSource = new BitmapImage(new Uri(startupPath + "/images/GenericPlan.png", UriKind.Absolute));
            ApplyBackgroundButtons(ButtonImage);

            ImageBrush RedConquer = new ImageBrush();

            RedConquer.ImageSource      = new BitmapImage(new Uri(startupPath + "/images/PlanConquerRed.png", UriKind.Absolute));
            planetConquerOne.Background = RedConquer;

            ImageBrush BlueConquer = new ImageBrush();

            BlueConquer.ImageSource     = new BitmapImage(new Uri(startupPath + "/images/PlanConquerBlue.png", UriKind.Absolute));
            planetConquerTwo.Background = BlueConquer;

            DoubleAnimation fadeInAnimation = new DoubleAnimation();

            fadeInAnimation.From     = 0.0;
            fadeInAnimation.To       = 1.0;
            fadeInAnimation.Duration = new Duration(TimeSpan.FromSeconds(2));

            DoubleAnimation fadeOutAnimation = new DoubleAnimation();

            fadeOutAnimation.From     = 1.0;
            fadeOutAnimation.To       = 0.1;
            fadeOutAnimation.Duration = new Duration(TimeSpan.FromSeconds(2));

            DoubleAnimation planetConquerOneAnimation = new DoubleAnimation();

            planetConquerOneAnimation.From        = 0.0;
            planetConquerOneAnimation.To          = 1.0;
            planetConquerOneAnimation.Duration    = new Duration(TimeSpan.FromSeconds(0.3));
            planetConquerOneAnimation.AutoReverse = true;

            DoubleAnimation planetConquerTwoAnimation = new DoubleAnimation();

            planetConquerTwoAnimation.From        = 0.0;
            planetConquerTwoAnimation.To          = 1.0;
            planetConquerTwoAnimation.Duration    = new Duration(TimeSpan.FromSeconds(0.3));
            planetConquerTwoAnimation.AutoReverse = true;

            gameOverStoryboard     = new Storyboard();
            HumanConquerStoryboard = new Storyboard();
            AIConquerStoryboard    = new Storyboard();

            gameOverStoryboard.Children.Add(fadeInAnimation);
            gameOverStoryboard.Children.Add(fadeOutAnimation);
            HumanConquerStoryboard.Children.Add(planetConquerOneAnimation);
            AIConquerStoryboard.Children.Add(planetConquerTwoAnimation);

            Storyboard.SetTargetName(fadeInAnimation, WinnerLabel.Name);
            Storyboard.SetTargetProperty(fadeInAnimation, new PropertyPath(Rectangle.OpacityProperty));
            Storyboard.SetTargetName(fadeOutAnimation, GameBackground.Name);
            Storyboard.SetTargetProperty(fadeOutAnimation, new PropertyPath(Rectangle.OpacityProperty));

            Storyboard.SetTargetName(planetConquerOneAnimation, planetConquerOne.Name);
            Storyboard.SetTargetProperty(planetConquerOneAnimation, new PropertyPath(Rectangle.OpacityProperty));

            Storyboard.SetTargetName(planetConquerTwoAnimation, planetConquerTwo.Name);
            Storyboard.SetTargetProperty(planetConquerTwoAnimation, new PropertyPath(Rectangle.OpacityProperty));

            soundEffectPlayer.PlayStartGameSound();

            if (!player1turn && engine.CurrentGame.GameType == GameType.LocalComputer)
            {
                PlayerTurnLabel.Visibility   = Visibility.Hidden;
                ComputerTurnLabel.Visibility = Visibility.Visible;
                MakeAIMove();
            }
            else if (engine.CurrentGame.GameType == GameType.LocalMultiplayer)
            {
                PlayerTurnLabel.Visibility   = Visibility.Hidden;
                ComputerTurnLabel.Visibility = Visibility.Hidden;

                if (player1turn)
                {
                    PlayerOneTurnLabel.Visibility = Visibility.Visible;
                }
                else
                {
                    PlayerTwoTurnLabel.Visibility = Visibility.Visible;
                }
            }
        }