private static List <PlayerDatas> getPlayersHistoric() { List <PlayerDatas> historics = new List <PlayerDatas>(); XElement xml = XElement.Load("PlayersHistoric.xml"); foreach (XElement x in xml.Elements()) { PlayerDatas p = new PlayerDatas(); p.setName(x.Attribute("name").Value); p.setPoints(int.Parse(x.Attribute("points").Value)); historics.Add(p); } return(historics); }
// Metodo de leitura do teclado void KeyboardHandler() { KeyboardState state = Keyboard.GetState(); // Encerra o jogo se a tecla esc for precionada if (state.IsKeyDown(Keys.Escape)) { Exit(); } // Inicia o jogo de a tecla espaço for precionada. if (!controlParameters.getGameStarted()) { if (state.IsKeyDown(Keys.Space)) { startParametersWhithKeyboard(true, false, false, false, false, false); } return; } // Reinicia se for precionado enter após game over if (controlParameters.getGameOver()) { if (state.IsKeyDown(Keys.Enter)) { controlParameters.setGameName(false); startParametrs(controlParameters.getGameOver(), controlParameters.getWin(), controlParameters.getDead(), controlParameters.getGameStarted(), Constants.initialLives, Constants.initialScore, Constants.initialLevel, Constants.intervalBetwenNewObstacleLoop, Constants.intervalBetwenChangeStreat, Constants.initialFroggerPass, controlParameters.getGameGetName(), controlParameters.getShowResults()); startParametersWhithKeyboard(true, false, false, false, false, false); } else if (state.IsKeyDown(Keys.Insert)) { playerDatas.setName(name); playerDatas.setPoints(controlParameters.getscore()); // Salva no historico players = controlHistoric.getTopXPlayers(Constants.bestNumbers, playerDatas); // Imprime o historico controlParameters.setShowResults(true); } else { makeName(state); } } if (controlParameters.getDead() && state.IsKeyDown(Keys.Space) && !controlParameters.getGameOver()) { StartNextLive(true, false, false, false); } if (controlParameters.getWin()) { if (controlParameters.getLevel() == Constants.maxLevel) { if (state.IsKeyDown(Keys.Enter)) { controlParameters.setGameName(false); startParametrs(controlParameters.getGameOver(), controlParameters.getWin(), controlParameters.getDead(), controlParameters.getGameStarted(), Constants.initialLives, Constants.initialScore, Constants.initialLevel, Constants.intervalBetwenNewObstacleLoop, Constants.intervalBetwenChangeStreat, Constants.initialFroggerPass, controlParameters.getGameGetName(), controlParameters.getShowResults()); startParametersWhithKeyboard(true, false, false, false, false, false); controlParameters.setLevel(Constants.zero); } else if (state.IsKeyDown(Keys.Insert)) { playerDatas.setName(name); playerDatas.setPoints(controlParameters.getscore()); // Salva no historico players = controlHistoric.getTopXPlayers(Constants.bestNumbers, playerDatas); // Imprime o historico controlParameters.setShowResults(true); } else { makeName(state); } } else { if (state.IsKeyDown(Keys.Enter)) { startParametersWhithKeyboard(true, false, false, false, false, false); } } } if (controlParameters.getPause() <= Constants.zero && !controlParameters.getWin() && !controlParameters.getGameOver() && !controlParameters.getDead()) { // Controla teclas de direção com controle de area da tela a ser usada if (state.IsKeyDown(Keys.Up) || state.IsKeyDown(Keys.W)) { frooger.setAngle(Constants.angleFrogger0); if (frooger.getY() > (screenHeight / Constants.beginPosition)) { frooger.setY(frooger.getY() - controlParameters.getPass()); } } else if (state.IsKeyDown(Keys.Down) || state.IsKeyDown(Keys.S)) { frooger.setAngle(Constants.angleFrogger180); if (frooger.getY() < (screenHeight - (screenHeight / Constants.minLimit))) { frooger.setY(frooger.getY() + controlParameters.getPass()); } } else if (state.IsKeyDown(Keys.Left) || (state.IsKeyDown(Keys.A))) { frooger.setAngle(Constants.angleFrogger90); if (frooger.getX() > screenWidth / Constants.maxLimit) { frooger.setX(frooger.getX() - controlParameters.getPass()); } } else if (state.IsKeyDown(Keys.Right) || state.IsKeyDown(Keys.D)) { frooger.setAngle(Constants.angleFrogger270); if (frooger.getX() < (screenWidth - (screenWidth / Constants.maxLimit))) { frooger.setX(frooger.getX() + controlParameters.getPass()); } } } }