public GameScreen(ContentManager content, GraphicsDeviceManager graphics, Camera camera, InputManager input) { GameState.Current = new GameState(camera, GridSize, content); mGroundPlaneRenderer = new PlaneRenderer(graphics, camera, new BasicEffect(graphics.GraphicsDevice) { TextureEnabled = true, Texture = content.Load <Texture2D>("textures/ground_sand") }); mHeroEffect = content.Load <Effect>("effects/HeroEffect").Clone(); mHeroEffectPlaneRenderer = new PlaneRenderer(graphics, camera, mHeroEffect); LoadAndSaveManager.Current = new LoadAndSaveManager(GridSize, camera, this, content); mWhitePixel = new Texture2D(graphics.GraphicsDevice, 1, 1); mWhitePixel.SetData(new[] { Color.White }); mGraphics = graphics; mCamera = camera; mInput = input; BuildManager = new BuildManager(input); BuildManagerWrapper.Init(BuildManager); BuildManagerWrapper.LoadInputManager(input); GameStateWrapper.LoadInputManager(input); input.SetSelectAction(SelectUnits); mFontMenu = content.Load <SpriteFont>("fonts/Menu"); mFontSmall = content.Load <SpriteFont>("fonts/Small"); LoadAndSaveManager.Current.LoadMap("map01", true); mStatusBarRenderer = new StatusBarRenderer(graphics.GraphicsDevice, content, camera); camera.Position = new Vector3(GridSize / -2f, GridSize * GridSize, 4 * GridSize); GameStateWrapper.StartGame(); }
public async void LoadGame() { OpenFileDialog openDialog = new OpenFileDialog(); if (openDialog.ShowDialog() == true) { try { if (model == null) { GameStateWrapper state = await persistence.LoadGameAsync(openDialog.FileName); model = SquaresGameModel.FromSave(state, persistence); NewGame(model); } else { await model.LoadGameAsync(openDialog.FileName); PlayerOne.Player = model.PlayerOne; PlayerTwo.Player = model.PlayerTwo; } FieldSize = model.FieldSize; InitDots(FieldSize); UpdateUI(this, EventArgs.Empty); } catch (Exception excp) { System.Windows.MessageBox.Show(excp.Message); } } }
private static double calculateOneChance() { if (GameStateWrapper.ourCard(1).Index == GameStateWrapper.ourCard(2).Index) { return(1); } else { if (GameStateWrapper.THGS.Round == TexasHoldEmRound.Preflop) { return(0.422); } else if (GameStateWrapper.THGS.Round.Equals("Flop") && hasOneChance("Flop")) { return(0.23); } else if (GameStateWrapper.THGS.Round.Equals("Turn") && hasOneChance("Turn")) { return(0.19); } else if (GameStateWrapper.THGS.Round.Equals("River") && hasOneChance("River")) { return(0); } else { return(1); } } }
private async Task LoadGame(String path) { try { if (model == null) { GameStateWrapper state = await dataAccess.LoadGameAsync(path); model = SquaresGameModel.FromSave(state, dataAccess); NewGame(model); } else { await model.LoadGameAsync(path); p1NameLabel.Text = model.PlayerOne.PlayerName; p2NameLabel.Text = model.PlayerTwo.PlayerName; } InitDots(model.FieldSize); UpdateUI(this, EventArgs.Empty); } catch (Exception excp) { MessageBox.Show(excp.Message); } }
public static int makeBet(Gene gene) { // returns the ammount to bet double betEval = Math.Pow(gene.get(2) * gameValuation(gene) / 7.5, 2); return(((int)betEval * (GameStateWrapper.maxBet() - GameStateWrapper.minBet())) + GameStateWrapper.minBet()); }
public static GameState LoadGameState() { #if UNITY_EDITOR || UNITY_STANDALONE string filePath = Path.Combine(Application.streamingAssetsPath, _fileNameGameState); #elif UNITY_IOS string filePath = Path.Combine(Application.streamingAssetsPath + "/Raw", _fileNameGameState); #elif UNITY_ANDROID string filePath = Path.Combine("jar:file://" + Application.streamingAssetsPath + "!assets/", _fileNameGameState); #endif if (File.Exists(filePath)) { #if UNITY_EDITOR || UNITY_IOS || UNITY_STANDALONE string dataAsJson = File.ReadAllText(filePath, System.Text.Encoding.GetEncoding("Windows-1250")); #elif UNITY_ANDROID WWW reader = new WWW(filePath); while (!reader.isDone) { } string dataAsJson = reader.text; #endif GameStateWrapper gameStateWrapper = JsonUtility.FromJson <GameStateWrapper> (dataAsJson); return(gameStateWrapper.gameState); } else { Debug.Log("File " + filePath + " does not exist"); return(null); } }
public override void IsClicked(Action <List <Screen> > addScreens, Action <List <Screen> > removeScreens) { removeScreens(mScreensDeleting); addScreens(mScreensFollowing); LoadAndSaveManager.Current.LoadGame(mFileName); GameStateWrapper.SetPause(false); }
private static AButton[] GetButtons(ContentManager content) { const int buttonPadding = 20; const int buttonWidth = 300; const int buttonHeight = 100; const float skillButtonSizeFactor = 0.6f; const float skillButtonPositionOffset = (1f - skillButtonSizeFactor) / 2; var hero = GameState.Current.HeroesByPlayer[Players.Player]; var skills = hero.HeroSkills.SkillList.Keys.ToList(); var buttons = new List <AButton>(); var buttonPositionY = MenuPosY + buttonPadding; foreach (var skill in skills) { var buttonPositionX = MenuPosX + buttonPadding; buttons.Add(new MenuButton(content, buttonPositionX, buttonPositionY, buttonWidth, buttonHeight, new[] { hero.HeroSkills.GetName(skill) })); buttonPositionX += buttonWidth + buttonPadding; buttons.Add(new SkillButton(content, buttonPositionX, buttonPositionY + (int)(skillButtonPositionOffset * buttonHeight), (int)(skillButtonSizeFactor * buttonWidth), (int)(skillButtonSizeFactor * buttonHeight), skill)); buttonPositionX += (int)(skillButtonSizeFactor * buttonWidth) + buttonPadding; buttons.Add(new SkillLevelUpButton(content, buttonPositionX, buttonPositionY + (int)(skillButtonPositionOffset * buttonHeight), (int)(skillButtonSizeFactor * buttonWidth), (int)(skillButtonSizeFactor * buttonHeight), new[] { Properties.SkillingMenu.Plus }, skill)); buttonPositionY += buttonPadding + buttonHeight; } buttons.Add(new SkillPointAvailableButton(content, MenuPosX + MenuWidth - buttonPadding - (int)(skillButtonSizeFactor * buttonWidth), buttonPositionY, (int)(skillButtonSizeFactor * buttonWidth), (int)(2 * skillButtonSizeFactor * buttonHeight))); buttons.Add(new ActionButton(content, MenuPosX + MenuWidth - buttonPadding - (int)(skillButtonSizeFactor * buttonWidth), MenuPosY + buttonPadding, (int)(skillButtonSizeFactor * buttonWidth), (int)(skillButtonSizeFactor * buttonHeight), new[] { Properties.SkillingMenu.X }, () => { GameStateWrapper.SetPause(false); },
private static double shownValuation(Gene gene, int state) { double sum = 0; for (int i = 0; i < state; i++) { sum += gene.get(6 + (2 * i)) * similarity(GameStateWrapper.tableCard(i + 1), GameStateWrapper.ourCard(1)) + gene.get(7 + (2 * i)) * similarity(GameStateWrapper.tableCard(i + 1), GameStateWrapper.ourCard(2)); } return(sum); }
private static bool CheckEsc(Action <List <Screen> > removeScreens) { if (ExitWrapper.EscClicked) { GameStateWrapper.SetPause(false); removeScreens(new List <Screen> { Screen.InGameMenu }); } return(false); }
//Static factory public static SquaresGameModel FromSave(GameStateWrapper state, ISquaresGameDataAccess dAccess) { SquaresGameModel instance = new SquaresGameModel(state.FieldSize, state.PlayerOne, state.PlayerTwo, dAccess); instance.ActivePlayer = state.ActivePlayer; instance.lines = state.Lines; instance.rectangles = state.Rectangles; instance.registeredRectCount = state.RegisteredRectCount; return(instance); }
private static bool hasOneChance(string state) { if (state == "Flop") { if (GameStateWrapper.ourCard(1) == GameStateWrapper.tableCard(1) || GameStateWrapper.ourCard(1) == GameStateWrapper.tableCard(2) || GameStateWrapper.ourCard(1) == GameStateWrapper.tableCard(3) || GameStateWrapper.ourCard(2) == GameStateWrapper.tableCard(1) || GameStateWrapper.ourCard(2) == GameStateWrapper.tableCard(2) || GameStateWrapper.ourCard(1) == GameStateWrapper.tableCard(3)) { return(false); } else { return(true); } } else if (state == "Turn") { if (GameStateWrapper.ourCard(1) == GameStateWrapper.tableCard(4) || GameStateWrapper.ourCard(2) == GameStateWrapper.tableCard(4)) { return(false); } else { return(true); } } else if (state == "River") { if (GameStateWrapper.ourCard(1) == GameStateWrapper.tableCard(5) || GameStateWrapper.ourCard(2) == GameStateWrapper.tableCard(5)) { return(false); } else { return(true); } } else { return(false); } }
public async Task LoadGameAsync(String filePath) { if (dataAccess == null) { throw new InvalidOperationException("No data access is provided."); } GameStateWrapper state = await dataAccess.LoadGameAsync(filePath); this.GameEnded = false; this.FieldSize = state.FieldSize; this.PlayerOne = state.PlayerOne; this.PlayerTwo = state.PlayerTwo; this.ActivePlayer = state.ActivePlayer; this.lines = state.Lines; this.linesToEnd = CalcLinesToEnd(); this.rectangles = state.Rectangles; this.registeredRectCount = state.RegisteredRectCount; }
public async Task SaveGameAsync(String filePath) { if (dataAccess == null) { throw new InvalidOperationException("No data access is provided."); } GameStateWrapper state = new GameStateWrapper(); state.PlayerOne = PlayerOne; state.PlayerTwo = PlayerTwo; state.ActivePlayer = ActivePlayer; state.Lines = lines; state.Rectangles = rectangles; state.RegisteredRectCount = registeredRectCount; state.FieldSize = FieldSize; await dataAccess.SaveGameAsync(state, filePath); }
public virtual void Update(GameTime gameTime, Action <List <Screen> > addScreens, Action <List <Screen> > removeScreens) { if (CheckEsc(addScreens, removeScreens)) { return; } foreach (var button in mButtons) { if (button.GetClicked()) { if (button.GetTextFirstLine() == HeroMenuPanel.SkillTree) { GameStateWrapper.SetPause(true); } else if (button.GetTextFirstLine() == SkillingMenu.X) { GameStateWrapper.SetPause(false); } button.IsClicked(addScreens, removeScreens); } } }
public void Initialize() { Player PlayerOne = new Player("TestPlayer1", Colors.Red); Player PlayerTwo = new Player("TestPlayer2", Colors.Blue); state = new GameStateWrapper { PlayerOne = PlayerOne, PlayerTwo = PlayerTwo, ActivePlayer = PlayerOne, FieldSize = 3, Lines = new List <System.Tuple <Point, Point, Player> >(), Rectangles = new List <System.Tuple <Point, Point, Player> >(), RegisteredRectCount = 0 }; mockDAccess = new Mock <ISquaresGameDataAccess>(); mockDAccess.Setup(mock => mock.LoadGameAsync(It.IsAny <String>())) .Returns(() => Task.FromResult(state)); model = SquaresGameModel.FromSave(state, mockDAccess.Object); model.EndGame += EndGameAssert; model.EndGame += (sender, e) => ++ endGameRaised; }
public static double handValuation(Gene gene) { return(gene.get(3) * (double)GameStateWrapper.ourCard(1).Index + gene.get(4) * (double)GameStateWrapper.ourCard(2).Index + gene.get(5) * similarity(GameStateWrapper.ourCard(1), GameStateWrapper.ourCard(2))); }
private static double gameValuation(Gene gene) { return(handValuation(gene) + ((GameStateWrapper.shownCards() > 0) ? shownValuation(gene, GameStateWrapper.shownCards()) : 0.0)); }
public void Update(GameTime gameTime, Action <List <Screen> > addScreens, Action <List <Screen> > removeScreens) { GameStateWrapper.SetPause(true); removeScreens(new List <Screen> { Screen.HeroMenuPanel }); if (CheckEsc(removeScreens)) { return; } if (mLoadButton.GetClicked()) { addScreens(new List <Screen> { Screen.LoadScreen }); removeScreens(new List <Screen> { Screen.InGameMenu }); } else if (mSaveButton.GetClicked()) { addScreens(new List <Screen> { Screen.SaveScreen }); removeScreens(new List <Screen> { Screen.InGameMenu }); } else if (mGraphicsButton.GetClicked()) { removeScreens(new List <Screen> { Screen.InGameMenu }); addScreens(new List <Screen> { Screen.InGameVideoMenu }); } else if (mSoundButton.GetClicked()) { removeScreens(new List <Screen> { Screen.InGameMenu }); addScreens(new List <Screen> { Screen.InGameAudioMenu }); } else if (mBackToMainMenuButton.GetClicked()) { mCamera.Position = AMainMenuPage.sCameraPosition; addScreens(new List <Screen> { Screen.MainMenu }); removeScreens(new List <Screen> { Screen.InGameMenu, Screen.GameHud, Screen.GameScreen }); } else if (mBackToGameButton.GetClicked()) { GameStateWrapper.SetPause(false); removeScreens(new List <Screen> { Screen.InGameMenu }); } }