public gamePhase HandleInput(ButtonEvents bEvent, gamePhase same, Player player, GraphicsDevice gDev) { gamePhase result = same; if (bEvent.BackPress || bEvent.EscPress) { result = gamePhase.SPLASH; } if (bEvent.StartPress || bEvent.EnterPress) { result = gamePhase.PAUSE; } if ((bEvent.APress || bEvent.SpacePress) && player.bullets().Count < player.maxBullets) { player.Fire(); } player.setPosition(player.X + (GamePad.GetState(PlayerIndex.One).ThumbSticks.Left.X *player.Speed), player.Y); //***** if (Keyboard.GetState().IsKeyDown(Keys.Left)) { player.setPosition((player.X - player.Speed), player.Y); } else if (Keyboard.GetState().IsKeyDown(Keys.Right)) { player.setPosition((player.X + player.Speed), player.Y); } //***** player.CheckBounds(0, gDev.Viewport.Width - 200); return(result); }
public gamePhase HandleInput(ButtonEvents bEvent, gamePhase same, UFOManager ufo, Player player) { gamePhase result = same; if (bEvent.BackPress || bEvent.EscPress) { // Allows the game to exit result = gamePhase.QUIT; } else if (bEvent.DpadDownPress || bEvent.DownPress) { // Move difficulty selector down difficulty.option = (difficulty.option + 1) % 3; } else if (bEvent.DpadUpPress || bEvent.UpPress) { // Move difficulty selector up difficulty.option = (difficulty.option + 2) % 3; } else if (bEvent.StartPress || bEvent.EnterPress) { // Begin game switch (difficulty.option) { case 0: //Easy player.level = 1; player.score = 0; player.lives = 10; player.maxBullets = 8; player.bulletSpeed = 3; player.setSpeedMultiplier(8); break; case 1: //Medium player.level = 1; player.score = 0; player.lives = 5; player.maxBullets = 2; player.bulletSpeed = 1.5f; player.setSpeedMultiplier(5); break; case 2: //Hard player.level = 1; player.score = 0; player.lives = 3; player.maxBullets = 1; player.bulletSpeed = 1; player.setSpeedMultiplier(3); break; } ufo.Destroy(); result = gamePhase.LOADLEVEL; mFirstPass = true; //reset splash screen initializer } return(result); }
public gamePhase HandleInput(ButtonEvents bEvent, gamePhase same) { gamePhase result = same; if (bEvent.StartPress || bEvent.EnterPress) { result = gamePhase.SPLASH; } return(result); }
/* board[23] is last pointe * board[24-25] is whiteBar and blackBar respectively * board[26-27] is white checkers bared off and black checkers bared off */ //On scene start, set up the board private void Start() { dice.resetDicePos(); //Sets dice to rest position arrangeBoard(); //Arrange starting board configuration assignPointePos(); //Ensure each pointe knows which pointe it is //Display AI table if against AI if (againstAI) { AIMoveInformation.gameObject.SetActive(true); } //initial game configuration states currGamePhase = turnPhase.StartGame; whiteCheckerPhase = gamePhase.Regular; blackCheckerPhase = gamePhase.Regular; //Player order is determined by the first roll, where higher number goes first StartCoroutine(determinePlayerOrder()); }
//Update board after AI move, given the move the AI selected, AI = black checkers private void updateBoard(KeyValuePair <int, int> move) { //Check for hit and do actions if hit if (board[move.Value] == 1) { whiteCheckerPhase = gamePhase.Regular; Checker removedChecker = pointes[move.Value].removeChecker(); removedChecker.setPos(24); bar.addCheckerOnBar(removedChecker); board[move.Value] = 0; board[24]++; } //Happens when checkers exist on bar, then must deal with them if (board[25] < 0) { Checker removedChecker = bar.removeCheckerOnBar(false); removedChecker.setPos(move.Value); pointes[move.Value].addChecker(removedChecker); board[25]++; } //Not on bar, then check barring off then check regular move and do actions else if (move.Value > MAXPOINTES) { Checker removedChecker = pointes[move.Key].removeChecker(); baringOff.addCheckerBaringOff(removedChecker); removedChecker.setPos(27); board[move.Key]++; board[27]--; } else { Checker removedChecker = pointes[move.Key].removeChecker(); removedChecker.setPos(move.Value); pointes[move.Value].addChecker(removedChecker); board[move.Key]++; } board[move.Value]--; }
//Deal with releasing a selected checker, either moving it or resetting it private void releaseSelectedChecker() { RaycastHit[] hits; Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition); hits = Physics.RaycastAll(ray); bool clickedPointe = false; int newPointePos = 0; for (int i = 0; i < hits.Length; i++) { PointeManager pointeSelected = hits[i].transform.GetComponent <PointeManager>(); BaringOffManager clickedBaringOff = hits[i].transform.GetComponent <BaringOffManager>(); if (pointeSelected && pointeSelected.isClickable()) { clickedPointe = true; newPointePos = pointeSelected.getPos(); //Look at board seperately for white phase vs black if (currGamePhase == turnPhase.WhiteTurn) { //Check for hit and do actions if hit if (board[newPointePos] == -1) { blackCheckerPhase = gamePhase.Regular; Checker removedChecker = pointes[newPointePos].removeChecker(); removedChecker.setPos(25); bar.addCheckerOnBar(removedChecker); board[newPointePos] = 0; board[25]--; } if (board[24] > 0) { Checker removedChecker = bar.removeCheckerOnBar(true); removedChecker.setPos(newPointePos); pointes[newPointePos].addChecker(removedChecker); selectedCheckerOrigBoardPos = 24; board[24]--; } //Not on bar, then regular move and do actions else { Checker removedChecker = pointes[selectedCheckerOrigBoardPos].removeChecker(); removedChecker.setPos(newPointePos); pointes[newPointePos].addChecker(removedChecker); board[selectedCheckerOrigBoardPos]--; } board[newPointePos]++; } else if (currGamePhase == turnPhase.BlackTurn) { //Check for hit and do actions if hit if (board[newPointePos] == 1) { whiteCheckerPhase = gamePhase.Regular; Checker removedChecker = pointes[newPointePos].removeChecker(); removedChecker.setPos(24); bar.addCheckerOnBar(removedChecker); board[newPointePos] = 0; board[24]++; } if (board[25] < 0) { Checker removedChecker = bar.removeCheckerOnBar(false); removedChecker.setPos(newPointePos); pointes[newPointePos].addChecker(removedChecker); selectedCheckerOrigBoardPos = -1; board[25]++; } //Not on bar, then regular move and do actions else { Checker removedChecker = pointes[selectedCheckerOrigBoardPos].removeChecker(); removedChecker.setPos(newPointePos); pointes[newPointePos].addChecker(removedChecker); board[selectedCheckerOrigBoardPos]++; } board[newPointePos]--; } } else if (clickedBaringOff && clickedBaringOff.isClickable()) { clickedPointe = true; Checker removedChecker = pointes[selectedCheckerOrigBoardPos].removeChecker(); baringOff.addCheckerBaringOff(removedChecker); if (currGamePhase == turnPhase.WhiteTurn) { removedChecker.setPos(26); board[selectedCheckerOrigBoardPos]--; board[26]++; newPointePos = -1; } else { removedChecker.setPos(27); board[selectedCheckerOrigBoardPos]++; board[27]--; newPointePos = 24; } baringOff.changeHighlightBaringOff(false); } } if (clickedPointe) { removeCheckerHighlights(); movesLeftForTurn--; if (currGamePhase == turnPhase.WhiteTurn) { if (board[26] == MAXCHECKERS) { StartCoroutine(finishGame(true)); } if (whiteCanBearOff()) { whiteCheckerPhase = gamePhase.BaringOff; } } else { if (-board[27] == MAXCHECKERS) { StartCoroutine(finishGame(false)); } if (blackCanBearOff()) { blackCheckerPhase = gamePhase.BaringOff; } } if (movesLeftForTurn == 0) { //Switch turns dice.resetDicePos(); if (currGamePhase == turnPhase.WhiteTurn) { currGamePhase = turnPhase.BlackTurn; if (againstAI) { rolledValues = dice.throwDice(true); StartCoroutine(doAIMove()); currGamePhase = turnPhase.WhiteTurn; } } else { currGamePhase = turnPhase.WhiteTurn; } } else if (rolledValues[0] == rolledValues[1]) { usedRoll1 = true; getLegalMoves(-1, rolledValues[1]); } else if (Mathf.Abs(newPointePos - selectedCheckerOrigBoardPos) == rolledValues[0]) { usedRoll1 = true; getLegalMoves(-1, rolledValues[1]); } else { usedRoll2 = true; getLegalMoves(rolledValues[0], -1); } } else { selectedChecker.transform.position = selectedCheckerOrigPos; } selectedChecker = null; selectedCheckerOrigPos = Vector3.zero; selectedCheckerOrigBoardPos = -1; resetPointes(); }
//Calls upon the AI to get the best possible move, given the board state IEnumerator doAIMove() { yield return(new WaitForSeconds(waitFinishMove)); int roll1 = rolledValues[0]; int roll2 = rolledValues[1]; Dictionary <KeyValuePair <int, int>, float> winPercentages = new Dictionary <KeyValuePair <int, int>, float>(); if (roll1 == roll2) { for (int i = 0; i < 4; i++) { KeyValuePair <int, int> move = AI.getPlay(board, roll1, roll2, winPercentages); displayWinPercentages(winPercentages); if (move.Key == -1 && move.Value == -1) { break; } updateBoard(move); yield return(new WaitForSeconds(waitFinishMove)); } } else { KeyValuePair <int, int> move = AI.getPlay(board, roll1, roll2, winPercentages); displayWinPercentages(winPercentages); if (move.Key != -1 && move.Value != -1) { updateBoard(move); yield return(new WaitForSeconds(waitFinishMove)); if (Mathf.Abs(move.Key - move.Value) == roll1) { move = AI.getPlay(board, roll2, -1, winPercentages); displayWinPercentages(winPercentages); if (move.Key != -1 && move.Value != -1) { updateBoard(move); } } else { move = AI.getPlay(board, roll1, -1, winPercentages); displayWinPercentages(winPercentages); if (move.Key != -1 && move.Value != -1) { updateBoard(move); } } } } if (-board[27] == MAXCHECKERS) { StartCoroutine(finishGame(false)); } if (blackCanBearOff()) { blackCheckerPhase = gamePhase.BaringOff; } dice.resetDicePos(); }
/// <summary> /// Allows the game to perform any initialization it needs to before starting to run. /// This is where it can query for any required services and load any non-graphic /// related content. Calling base.Initialize will enumerate through any components /// and initialize them as well. /// </summary> protected override void Initialize() { // Initialize game window base.Initialize(); // Everything else bEvents = new ButtonEvents(GamePad.GetState(PlayerIndex.One), Keyboard.GetState()); phase = gamePhase.DEVINTRO; Texture2D[] frames = new Texture2D[31] { Content.Load <Texture2D>("Intro/devint-01"), Content.Load <Texture2D>("Intro/devint-02"), Content.Load <Texture2D>("Intro/devint-03"), Content.Load <Texture2D>("Intro/devint-04a"), Content.Load <Texture2D>("Intro/devint-04b"), Content.Load <Texture2D>("Intro/devint-04a"), Content.Load <Texture2D>("Intro/devint-04a"), Content.Load <Texture2D>("Intro/devint-04a"), Content.Load <Texture2D>("Intro/devint-04b"), Content.Load <Texture2D>("Intro/devint-04a"), Content.Load <Texture2D>("Intro/devint-04b"), Content.Load <Texture2D>("Intro/devint-04a"), Content.Load <Texture2D>("Intro/devint-05"), Content.Load <Texture2D>("Intro/devint-06"), Content.Load <Texture2D>("Intro/devint-07"), Content.Load <Texture2D>("Intro/devint-08"), Content.Load <Texture2D>("Intro/devint-09"), Content.Load <Texture2D>("Intro/devint-10"), Content.Load <Texture2D>("Intro/devint-11"), Content.Load <Texture2D>("Intro/devint-12"), Content.Load <Texture2D>("Intro/devint-13"), Content.Load <Texture2D>("Intro/devint-14"), Content.Load <Texture2D>("Intro/devint-15"), Content.Load <Texture2D>("Intro/devint-16"), Content.Load <Texture2D>("Intro/devint-17"), Content.Load <Texture2D>("Intro/devint-18"), Content.Load <Texture2D>("Intro/devint-19"), Content.Load <Texture2D>("Intro/devint-19"), Content.Load <Texture2D>("Intro/devint-19"), Content.Load <Texture2D>("Intro/devint-19"), Content.Load <Texture2D>("Intro/devint-19") }; scrIntro = new DevIntro(frames, 31); scrSplash = new SplashScreen(Content.Load <SpriteFont>("Fonts/Fkey"), Content.Load <SpriteFont>("Fonts/Title"), Content.Load <SpriteFont>("Fonts/Instruction")); scrLoader = new LevelLoader(Content.Load <SpriteFont>("Fonts/Level")); scrPlay = new PlayScreen(Content.Load <SpriteFont>("Fonts/PlayerHeader"), Content.Load <SpriteFont>("Fonts/PlayerData"), Content.Load <Texture2D>("Panel")); scrPause = new PauseScreen(Content.Load <SpriteFont>("Fonts/Pause")); scrGameover = new GameOver(Content.Load <SpriteFont>("Fonts/GameOver")); stars = new Starfield(GraphicsDevice); player = new Player(Content.Load <Texture2D>("Ship"), Content.Load <Texture2D>("Bullet"), Content.Load <SoundEffect>("Sounds/ShipFiring"), Content.Load <SoundEffect>("Sounds/ShipDeath"), new Vector2((GraphicsDevice.Viewport.Width - 200) / 2 - 40, GraphicsDevice.Viewport.Height - 91), new Vector2(0, 0), 4.0f); aliens = new AlienManager(Content.Load <Texture2D>("alien0"), Content.Load <Texture2D>("alien1"), Content.Load <Texture2D>("alien2"), Content.Load <Texture2D>("alien3"), Content.Load <Texture2D>("Bullet"), Content.Load <SoundEffect>("Sounds/AlienFiring"), Content.Load <SoundEffect>("Sounds/AlienDeath")); ufo = new UFOManager(Content.Load <Texture2D>("BigAlien"), Content.Load <Texture2D>("Present"), Content.Load <SoundEffect>("Sounds/UFOMoving"), Content.Load <SoundEffect>("Sounds/GiftboxDrop"), Content.Load <SoundEffect>("Sounds/GiftboxCollect")); }
/// <summary> /// Allows the game to run logic such as updating the world, /// checking for collisions, gathering input, and playing audio. /// </summary> /// <param name="gameTime">Provides a snapshot of timing values.</param> protected override void Update(GameTime gameTime) { bEvents.Update(GamePad.GetState(PlayerIndex.One), Keyboard.GetState()); switch (phase) { case gamePhase.DEVINTRO: phase = scrIntro.HandleInput(bEvents, phase); if (scrIntro.IsDone()) { phase = gamePhase.SPLASH; } break; case gamePhase.SPLASH: //Move objects scrSplash.SplashDance(GraphicsDevice, ufo); //Check for input phase = scrSplash.HandleInput(bEvents, phase, ufo, player); break; case gamePhase.HIGHSCORES: break; case gamePhase.LOADLEVEL: //Initialize for play state scrLoader.Initialize(player, aliens, ufo); //Move objects scrLoader.Update(stars, player, aliens, ufo, GraphicsDevice); //Check timer if (scrLoader.IsDone()) { phase = gamePhase.PLAY; } break; case gamePhase.PLAY: //Move non-player objects if (!scrPlay.Update(stars, player, aliens, ufo, GraphicsDevice)) { phase = gamePhase.GAMEOVER; //aliens have reached the bottom } //Random appearances ufo.Spawn(GraphicsDevice, player.level); aliens.Fire(player.level); //Check for input phase = scrPlay.HandleInput(bEvents, phase, player, GraphicsDevice); //Check for collisions scrPlay.DetectCollisions(player, aliens, ufo); //Change of state? if (player.lives == 0) { phase = gamePhase.GAMEOVER; } else if (aliens.count() == 0) { player.level++; phase = gamePhase.LOADLEVEL; } break; case gamePhase.PAUSE: phase = scrPause.HandleInput(bEvents, phase); break; case gamePhase.GAMEOVER: //Move objects stars.Update(GraphicsDevice); //Check for input phase = scrGameover.HandleInput(bEvents, phase); break; case gamePhase.QUIT: default: this.Exit(); break; } base.Update(gameTime); }