battle programmers alliance
Would you like to react to this message? Create an account in a few clicks or log in to continue.


battle programming a forum for elite programmers with extreme will power to sharpen their skills
 
HomeSearchRegisterLog in
 

 simon memory game skill

Go down 
AuthorMessage
kurosen
codding
codding
kurosen

Posts : 291
Join date : 2012-04-17

simon memory game skill Empty
PostSubject: simon memory game skill   simon memory game skill EmptyWed Jan 20, 2021 12:37 pm

MemoryGame :
Code:
package chobit;

import java.util.ArrayList;

public class MemoryGame {
   private int index = 0;
   private ArrayList<String> colors = new ArrayList<>();
   private ArrayList<String> baseColors = new ArrayList<>();

   public MemoryGame() {
      baseColors.add("red");
      baseColors.add("blue");
      baseColors.add("black");
      baseColors.add("yellow");
   }

   public String reset() {
      index = 0;
      colors = new ArrayList<>();
      colors.add(genRndColor());
      return colors.get(0);
   }

   public String play(String input) {
      String[] spliten = input.split(" ");
      String strTemp = "";
      for (String str1 : spliten) {
         strTemp = strContainsList(str1);
         if (!strTemp.isEmpty()) {
            if (colors.get(index).equals(strTemp)) {
               index++;// boolean for ok return
               if (index == colors.size()) {
                  index = 0;
                  colors.add(genRndColor());
                  return getGameStr();
               }
            } else {
               return "you have reached level " + colors.size();
            }
         }
      }
      return "";
   }
   private String genRndColor() {
      int x = (int) Math.floor(Math.random() * 4);
      switch (x) {
      case 0:
         return "red";
      case 1:
         return "blue";
      case 2:
         return "black";
      case 3:
         return "yellow";
      }
      return"";
   }

   public String strContainsList(String str1) {
      for (String temp : baseColors) {
         if (str1.contains(temp)) {
            return temp;
         }
      }
      return "";
   }

   public String getGameStr() {
      String result = "";
      for (String string : colors) {
         result += string + " ";
      }
      return result;
   }
}

DiMemoryGame skill class :

Code:
package com.yotamarker.lgkotlin1;

public class DiMemoryGame extends DISkill {
    private int gameMode = 0;
    private DISkillUtils diSkillUtils = new DISkillUtils();
    private String outStr = "";
    private MemoryGame memoryGame = new MemoryGame();

    public DiMemoryGame(Kokoro kokoro) {
        super(kokoro);
    }

    @Override
    public void input(String ear, String skin, String eye) {
        if (ear.contains("play simon")) {
            gameMode = 1;
            outStr = "lets start with "+memoryGame.reset();
            //while gaming say i choose [colors]
            return;
        }
        switch (gameMode) {
            case 1:
                outStr = memoryGame.play(ear);
                if (outStr.contains("you have reached level")) {
                    gameMode = 0;
                }
                break;
            default:
                break;
        }
    }

    @Override
    public void output(Neuron noiron) {
        if (!outStr.isEmpty()) {
            String temp = outStr;
            outStr = "";
            noiron.algParts.add(diSkillUtils.verbatimGorithm("mini game", new APVerbatim(temp)));
        }
    }
}

scratch
Back to top Go down
kurosen
codding
codding
kurosen

Posts : 291
Join date : 2012-04-17

simon memory game skill Empty
PostSubject: Re: simon memory game skill   simon memory game skill EmptyWed Jan 20, 2021 12:40 pm

Back to top Go down
 
simon memory game skill
Back to top 
Page 1 of 1

Permissions in this forum:You cannot reply to topics in this forum
battle programmers alliance :: battle programming alliance :: the LivinGrimoire-
Jump to: