GameApplication.java - import import import import import import import import import import import import import javafx.application.Application

GameApplication.java - import import import import import...

This preview shows page 1 - 3 out of 6 pages.

import javafx.application.Application; import javafx.application.Platform; import javafx.scene.Scene; import javafx.scene.layout.HBox; import javafx.stage.Stage; import pa1.City; import pa1.GameEngine; import pa1.GameMap; import pa1.Player; import pa1.exceptions.TooPoorException; import pa1.ministers.Minister; import pa1.technologies.Technology; import ui.*; import java.io.IOException; import java.util.List; import java.util.Random; public class GameApplication extends Application { Stage stage; // GameMap private static GameEngine gameEngine = new GameEngine(); // UI Panes Menu menu = new Menu(); GameCanvas gameCanvas; InfoBar infoBar = new InfoBar(gameEngine.getMap()); // UI Scenes Scene menuScene = new Scene(menu); Scene gameplayScene; Player currentPlayer; private static Random random = new Random(); // Generate a random integer between 0 (inclusive) and max (exclusive) private static int getRandomInt(int max) { return max > 0 ? random.nextInt(max) : 0; } // Choose one element randomly in the list private static <T> T chooseOneRandomly(List<T> list) { if (list.isEmpty()) return null; int index = getRandomInt(list.size()); return list.get(index); } private class ComputerThread implements Runnable { private Player player; ComputerThread() { this.player = currentPlayer; } @Override public void run() { List<Minister> readyMinisters = player.getReadyMinisters(); for (Minister minister : readyMinisters) { // TODO: implement a computer thread that makes random decisions
Image of page 1

Subscribe to view the full document.

/** * Step 1: * Choose 5 things randomly, from the player member variable * 1. choose a random action number from 0 to 9 * 2. choose a random city from the player's cities * 3. choose a random neighbor of above chosen city (to be used as attackTarget) * 4. choose a random technology from the player's technologies * 5. pick a random number from 0 to the number of troops stationed at the city * chosen at (2), call this number troopNum * * You may find the methods getRandomInt() and chooseOneRandomly() useful * */ int randomActionNumber = getRandomInt(10); City playerCity = chooseOneRandomly(player.getCities()); GameMap gameMap = gameEngine.getMap(); City neighborCity = chooseOneRandomly( gameMap.getNeighboringCities(playerCity) );//wrong statement Technology technology = chooseOneRandomly(player.getTechnologies()); int troopNum = getRandomInt(playerCity.getTroops() + 1); Platform.runLater(() -> { /** * Step2: * 1. Call gameEngine.processPlayerCommand() method, using
Image of page 2
Image of page 3
  • Fall '14

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern

Ask Expert Tutors You can ask You can ask ( soon) You can ask (will expire )
Answers in as fast as 15 minutes