Lil bit of game logic
This commit is contained in:
@ -66,6 +66,10 @@ public class Floor {
|
||||
FillWalls(xzCorner.getBlockY(), xzCorner.getBlockY() + 15, Material.AIR);
|
||||
}
|
||||
|
||||
public void WarnWalls(Material material) {
|
||||
FillWalls(xzCorner.getBlockY() + 2, xzCorner.getBlockY() + 4, material);
|
||||
}
|
||||
|
||||
public void SoloTile(Material material) {
|
||||
for (int row = 0; row < gridSize; row++) {
|
||||
for (int col = 0; col < gridSize; col++) {
|
||||
@ -75,8 +79,6 @@ public class Floor {
|
||||
Material.AIR);
|
||||
}
|
||||
}
|
||||
|
||||
FillWalls(xzCorner.getBlockY() + 2, xzCorner.getBlockY() + 4, material);
|
||||
}
|
||||
|
||||
private void FillTile(int xMin, int zMin, Material material) {
|
||||
|
||||
@ -16,7 +16,7 @@ public class GameConfig {
|
||||
private boolean playersHaveKnockbackStick;
|
||||
private boolean playersHaveFishingRod;
|
||||
private boolean spectatorsCanMessWithPlayers;
|
||||
private static final Map<String, Material> availableColours = new HashMap<>();
|
||||
private static final Map<Material, String> availableColours = new HashMap<>();
|
||||
private Location postGameTpLocation;
|
||||
private Location floorCenter;
|
||||
private final Location[] playerJoinArea = new Location[2];
|
||||
@ -49,7 +49,7 @@ public class GameConfig {
|
||||
|
||||
for (String colour : coloursSection.getKeys(false)){
|
||||
var material = Material.getMaterial(coloursSection.getString(colour));
|
||||
availableColours.put(colour, material);
|
||||
availableColours.put(material, colour);
|
||||
}
|
||||
}
|
||||
|
||||
@ -127,7 +127,7 @@ public class GameConfig {
|
||||
FloorGame.SaveConfig();
|
||||
}
|
||||
|
||||
public Map<String, Material> getColourMap() {
|
||||
public Map<Material, String> getColourMap() {
|
||||
return availableColours;
|
||||
}
|
||||
|
||||
|
||||
@ -3,11 +3,12 @@ package com.pobnellion.floorGame.game;
|
||||
import com.pobnellion.floorGame.FloorGame;
|
||||
import com.pobnellion.floorGame.Util;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Random;
|
||||
import java.util.logging.Level;
|
||||
@ -18,7 +19,11 @@ public class GameInstance {
|
||||
private final ArrayList<Player> players = new ArrayList<>();
|
||||
private final ArrayList<Player> spectators = new ArrayList<>();
|
||||
private final GameConfig config;
|
||||
public int round;
|
||||
private int round;
|
||||
private boolean roundInProgress;
|
||||
private LocalDateTime nextRoundStartTime;
|
||||
private Material roundColour;
|
||||
|
||||
|
||||
public GameInstance(GameConfig config) {
|
||||
floor = new Floor(config.getFloorCenter(), config.getGridSize(), config.getTileSize(), config.getAvailableColours());
|
||||
@ -51,17 +56,41 @@ public class GameInstance {
|
||||
}
|
||||
|
||||
private void GameLoopTask() {
|
||||
var rand = new Random();
|
||||
var colour = floor.colours[rand.nextInt(floor.colours.length)];
|
||||
floor.SoloTile(colour);
|
||||
|
||||
var roundTime = 1 + floor.tileSize * 0.5 - round * (0.2 * floor.tileSize);
|
||||
|
||||
new BukkitRunnable() {
|
||||
|
||||
var a =new BukkitRunnable() {
|
||||
public void run() {
|
||||
floor.Reset();
|
||||
}
|
||||
}.runTaskLater(FloorGame.GetInstance(), 1000);
|
||||
|
||||
a.
|
||||
}
|
||||
|
||||
private BukkitRunnable round = new BukkitRunnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
var rand = new Random();
|
||||
roundColour = floor.colours[rand.nextInt(floor.colours.length)];
|
||||
|
||||
|
||||
|
||||
floor.SoloTile(colour);
|
||||
|
||||
}
|
||||
};
|
||||
|
||||
private BukkitRunnable warnColour = new BukkitRunnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
floor.WarnWalls(roundColour);
|
||||
var colourName = config.getColourMap().get(roundColour).toUpperCase();
|
||||
|
||||
// TODO: stay based on round time
|
||||
players.forEach(player -> player.sendTitle(null, colourName, 0, 10, 0));
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public void Stop() {
|
||||
@ -76,10 +105,6 @@ public class GameInstance {
|
||||
}
|
||||
|
||||
private double GetRoundTime() {
|
||||
if (round < 40)
|
||||
return 1 + 0.5 * floor.tileSize - 0.08 * floor.tileSize * round * 0.1;
|
||||
|
||||
// TODO: flatter line after round 40
|
||||
return 0;
|
||||
return 1 + 0.5 * floor.tileSize + Math.pow(0.85, Math.floor(round * 0.1));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user