Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package mu.nu.nullpo.game.subsystem.mode;
- import mu.nu.nullpo.game.component.Piece;
- import mu.nu.nullpo.game.event.EventReceiver;
- import mu.nu.nullpo.game.play.GameEngine;
- import mu.nu.nullpo.util.CustomProperties;
- //For the love of all that is holy, don't play with different piece lists than the normal 7. Please
- // also this isn't netplay safe at all
- // Also hi, this is Romaji Milton Amulo, in 2018, coding Java again
- // USES A PROTECTED MODE VERSION OF MARATHON MODE
- public class MarathonModeButItHatesYou extends MarathonMode {
- @Override
- public String getName() {
- return "EVIL MARATHON";
- }
- private int[] record;
- private int badPiece;
- private boolean hasSkipped;
- private static final boolean debugMode=true;
- @Override
- public void startGame(GameEngine engine, int playerID) {
- super.startGame(engine, playerID);
- record = new int[7];
- record[0]=1; // pre set I as bad piece
- badPiece=0;
- hasSkipped=false;
- }
- /*
- * takes in what was just dropped
- */
- public void pieceLocked(GameEngine engine, int playerID, int lines) {
- record[engine.nowPieceObject.id] +=lines; //adds to record per piece.
- if (engine.nextPieceArrayID[engine.nextPieceCount]==badPiece) { //if bad, skip
- engine.nextPieceCount++;
- hasSkipped=true;
- }
- if (engine.nextPieceCount%7==0){
- recomputeBadPiece(engine);
- }
- }
- /*
- * Render score and what piece will be skipped.
- */
- @Override
- public void renderLast(GameEngine engine, int playerID) {
- super.renderLast(engine, playerID);
- if (hasSkipped) {
- engine.owner.receiver.drawScoreFont(engine, playerID, 0, 14, "SAFE FOR NOW", EventReceiver.COLOR_BLUE);
- } else {
- engine.owner.receiver.drawScoreFont(engine, playerID, 0, 14, Piece.getPieceName(badPiece) +
- " WILL BE SKIPPED", EventReceiver.COLOR_RED);
- }
- // if (debugMode) { //I don't understand, but this breaks everything
- // engine.owner.receiver.drawScoreFont(engine, playerID, 0, 15, String.valueOf(record[0])+""+
- // String.valueOf(record[1])+""+String.valueOf(record[2])+""+String.valueOf(record[3])
- // +""+String.valueOf(record[4])+""+String.valueOf(record[5])+""+String.valueOf(record[6]));
- // //Someone help me write out the values of record.
- // }
- }
- private void recomputeBadPiece(GameEngine engine) {
- //erase common min, so least favorite piece is never removed.
- int CommonMin=999999999; //should be high enough
- for (int value : record) {
- if (value<CommonMin) {
- CommonMin = value;
- if (CommonMin == 0) {
- break; //if the common min is zero, no need to keep looking
- }
- }
- }
- if(CommonMin >0) { //no point getting rid of the common min if it's zero
- for(int index=0;index<7;index++) {
- record[index]-=CommonMin;
- }
- }
- int total=0; //now, see how large to set the RNG
- for (int value : record) {
- total+=value;
- }
- if (total==0) { //if no piece is favored, be merciful, and don't have a skip piece. This time.
- badPiece=-1;
- return;
- }
- hasSkipped=false;
- int RGN = engine.random.nextInt(total); //get a random int at least one less than total.
- //RGN = Randomly Generated Number
- for(int index=0;index<7;index++) {
- RGN -= record[index];
- if (RGN<0) {
- badPiece=index; //set bad piece to when RGN goes below 0, and then leave
- break;
- }
- }
- }
- // now for edited copypasta code
- /**
- * Read rankings from property file
- * @param prop Property file
- * @param ruleName Rule name
- */
- @Override
- protected void loadRanking(CustomProperties prop, String ruleName) {
- for(int i = 0; i < RANKING_MAX; i++) {
- for(int j = 0; j < GAMETYPE_MAX; j++) {
- rankingScore[j][i] = prop.getProperty("evilmarathon.ranking." + ruleName + "." + j + ".score." + i, 0);
- rankingLines[j][i] = prop.getProperty("evilmarathon.ranking." + ruleName + "." + j + ".lines." + i, 0);
- rankingTime[j][i] = prop.getProperty("evilmarathon.ranking." + ruleName + "." + j + ".time." + i, 0);
- }
- }
- }
- /**
- * Save rankings to property file
- * @param prop Property file
- * @param ruleName Rule name
- */
- protected void saveRanking(CustomProperties prop, String ruleName) {
- for(int i = 0; i < RANKING_MAX; i++) {
- for(int j = 0; j < GAMETYPE_MAX; j++) {
- prop.setProperty("evilmarathon.ranking." + ruleName + "." + j + ".score." + i, rankingScore[j][i]);
- prop.setProperty("evilmarathon.ranking." + ruleName + "." + j + ".lines." + i, rankingLines[j][i]);
- prop.setProperty("evilmarathon.ranking." + ruleName + "." + j + ".time." + i, rankingTime[j][i]);
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement