public LocalGamePage(string p1Name, string p2Name) { InitializeComponent(); player1Name = p1Name; player2Name = p2Name; string songPath = startupPath + "/sound/music/Soundtrack.mp3"; soundTrackMediaPlayer.Open(new Uri(songPath)); soundTrackMediaPlayer.MediaEnded += new EventHandler(Song_Ended); if (!SoundSetting.MusicOn) { soundTrackMediaPlayer.IsMuted = true; } soundTrackMediaPlayer.Play(); 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.LocalMultiplayer); soundEffectPlayer.PlayStartGameSound(); Random rndMoveFirst = new Random(); int playFirst = rndMoveFirst.Next(0, 2); FuelLeftLabel.Content = player1Name + "'s fuel:"; FuelLeftLabel2.Content = player2Name + "'s fuel:"; if (playFirst == 1) { PlayerOneTurnLabel.Visibility = Visibility.Visible; fuelIndicator1.Visibility = Visibility.Visible; PlayerOneTurnLabel.Content = player1Name + "'s turn"; player1turn = true; } else { PlayerTwoTurnLabel.Visibility = Visibility.Visible; fuelIndicator2.Visibility = Visibility.Visible; PlayerTwoTurnLabel.Content = player2Name + "'s turn"; player1turn = false; } InitializeImages(); }
public LocalGamePage(string p1Name, string p2Name) { InitializeComponent(); player1Name = p1Name; player2Name = p2Name; string songPath = startupPath + "/sound/music/Soundtrack.mp3"; soundTrackMediaPlayer.Open(new Uri(songPath)); soundTrackMediaPlayer.MediaEnded += new EventHandler(Song_Ended); if (!SoundSetting.MusicOn) soundTrackMediaPlayer.IsMuted = true; soundTrackMediaPlayer.Play(); 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.LocalMultiplayer); soundEffectPlayer.PlayStartGameSound(); Random rndMoveFirst = new Random(); int playFirst = rndMoveFirst.Next(0, 2); FuelLeftLabel.Content = player1Name + "'s fuel:"; FuelLeftLabel2.Content = player2Name + "'s fuel:"; if (playFirst == 1) { PlayerOneTurnLabel.Visibility = Visibility.Visible; fuelIndicator1.Visibility = Visibility.Visible; PlayerOneTurnLabel.Content = player1Name + "'s turn"; player1turn = true; } else { PlayerTwoTurnLabel.Visibility = Visibility.Visible; fuelIndicator2.Visibility = Visibility.Visible; PlayerTwoTurnLabel.Content = player2Name + "'s turn"; player1turn = false; } InitializeImages(); }
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(); }
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(); }
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; } }
public LANGamePage(LidgrenKulamiPeer.KulamiPeer nPeer, int boardNum, bool meFirst, string mName, string oName) { InitializeComponent(); networkPeer = nPeer; myName = mName; opponentsName = oName; if (meFirst) { PlayerTurnLabel.Visibility = System.Windows.Visibility.Visible; PlayerTurnLabel.Foreground = (SolidColorBrush)(new BrushConverter().ConvertFrom("#FFE85252")); fuelIndicator1.Visibility = Visibility.Visible; OpponentTurnLabel.Visibility = System.Windows.Visibility.Hidden; player1turn = true; myColor = "Red"; opponentsColor = "Blue"; } else { PlayerTurnLabel.Visibility = System.Windows.Visibility.Hidden; fuelIndicator2.Visibility = System.Windows.Visibility.Visible; OpponentTurnLabel.Visibility = System.Windows.Visibility.Visible; OpponentTurnLabel.Foreground = (SolidColorBrush)(new BrushConverter().ConvertFrom("#FFE85252")); player1turn = false; myColor = "Blue"; opponentsColor = "Red"; } string songPath = startupPath + "/sound/music/Soundtrack.mp3"; soundTrackMediaPlayer.Open(new Uri(songPath)); soundTrackMediaPlayer.MediaEnded += new EventHandler(Song_Ended); if (!SoundSetting.MusicOn) { soundTrackMediaPlayer.IsMuted = true; } soundTrackMediaPlayer.Play(); 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.LANMultiplayer, boardNum); soundEffectPlayer.PlayStartGameSound(); InitializeImages(boardNum); if (!meFirst) { if (!IsConnected()) { Disconnect(); } else { try { MakeOpponentMove(); } catch { } } } checkConnect.Elapsed += new ElapsedEventHandler(IfConnecting); checkConnect.AutoReset = true; checkConnect.Enabled = true; }
public LANGamePage(LidgrenKulamiPeer.KulamiPeer nPeer, int boardNum, bool meFirst, string mName, string oName) { InitializeComponent(); networkPeer = nPeer; myName = mName; opponentsName = oName; if (meFirst) { PlayerTurnLabel.Visibility = System.Windows.Visibility.Visible; PlayerTurnLabel.Foreground = (SolidColorBrush)(new BrushConverter().ConvertFrom("#FFE85252")); fuelIndicator1.Visibility = Visibility.Visible; OpponentTurnLabel.Visibility = System.Windows.Visibility.Hidden; player1turn = true; myColor = "Red"; opponentsColor = "Blue"; } else { PlayerTurnLabel.Visibility = System.Windows.Visibility.Hidden; fuelIndicator2.Visibility = System.Windows.Visibility.Visible; OpponentTurnLabel.Visibility = System.Windows.Visibility.Visible; OpponentTurnLabel.Foreground = (SolidColorBrush)(new BrushConverter().ConvertFrom("#FFE85252")); player1turn = false; myColor = "Blue"; opponentsColor = "Red"; } string songPath = startupPath + "/sound/music/Soundtrack.mp3"; soundTrackMediaPlayer.Open(new Uri(songPath)); soundTrackMediaPlayer.MediaEnded += new EventHandler(Song_Ended); if (!SoundSetting.MusicOn) soundTrackMediaPlayer.IsMuted = true; soundTrackMediaPlayer.Play(); 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.LANMultiplayer, boardNum); soundEffectPlayer.PlayStartGameSound(); InitializeImages(boardNum); if (!meFirst) { if (!IsConnected()) { Disconnect(); } else { try { MakeOpponentMove(); } catch { } } } checkConnect.Elapsed += new ElapsedEventHandler(IfConnecting); checkConnect.AutoReset = true; checkConnect.Enabled = true; }
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; } } }