This site requires JavaScript, please enable it in your browser!
Greenfoot back
Roshan123
Roshan123 wrote ...

2021/10/12

Saving 2 high scores seperately at a time

1
2
3
Super_Hippo Super_Hippo

2021/10/17

#
You can also check out my Pac-Man scenario. It has two separate highscores for two values (score and level). There is no nearby ranking though. The sorting algorithm isn’t really optimized, but it works well.
Roshan123 Roshan123

2021/10/17

#
@Super_Hippo, (note that i have no mean to insult u, so don't get irritated by reading the story written below) Long long ago, when i used to be a child of my parents, i was searching for a scenario with 2 seperate high score system. I searched it day and night but i never found what i wanted and then one day i remembered that I have already played a game with such type of mechanism. I tried my best to remember the name and very soon i recalled it. It was only ur's scenario,,, yes ur's. Ur scenario was 100000 in one but when i clicked the "open in greenfoot" button, it was the most worst decision i have ever taken becaz when i looked into it, i don't know.... Out of nowhere i screamed loud just becaz i was not able to understand it and then i got a conclusion that its in german and not in English. Moral of the story :- 1st, i don't have much knowledge of java. 2nd, i don't understand german language. This were the 2 reasons why i ignored it and Thanks for sharing it!!!
Roshan123 Roshan123

2021/10/18

#
@danpost, let it be. I think its taking too much time so it's better not to waste ur time on the algorithms
Roshan123 Roshan123

2021/10/20

#
i don't know what i did but the top score is not working(the one which u provided recently). Is it working on urs? If yes then ignore the below one and tell me how did u intialized the ScoreBoard? I created a program in blue j (which determines the highest input and also prints the top scores in descending order ) and i wanna ask that, is it going to work if i implement to get Top of the users in greenfoot? If its gonna work then, 1 more question i.e. do i need to make a vast amount of changes in it or just few things?
import java.util.*;
public class check_HIGHEST_NUM
{
  public static void main()
  {
     ArrayList<Integer> yourList=new ArrayList<Integer>(1000);
     ArrayList<Integer> othersList=new ArrayList<Integer>(1000);
     ArrayList<Integer> globalList=new ArrayList<Integer>(1000);
     
     int n=0,copy=0,count=0;
     int n1=0,copy1=0,count1=0;
     int check=0;
     
     Scanner sc=new Scanner(System.in);
     
     System.out.println("Your num");
     do
     {
       n=sc.nextInt();
       yourList.add(n);
       globalList.add(n);
       count++;
     }while(count<=0);
     
     System.out.println("Other's num");
     do
     {
       n1=sc.nextInt();
       othersList.add(n1);
       globalList.add(n1);
       count1++;
     }while(count1<=2);
     
     Integer max1=Collections.max(yourList);
     Integer max2=Collections.max(othersList);
     
     if(max2>max1)
        check=max2;
     else if(max1>max2)
        check=max1;
       
     Collections.sort(globalList, Collections.reverseOrder()) ;
     
     System.out.println("@Your_Score"+yourList+"\n"+"@Other's Score"+othersList+"\n"+"@Highest_Score"+check+"\n"+"@Top scores in dec order"+globalList);
  }
}
danpost danpost

2021/10/20

#
Change the for loop starting at line 35 here to
for (int i=1; i<list.size(); i++)
{
    int n = i;
    while (n > 0 && list.get(n).getInt(game) > list.get(n-1).getInt(game))
    {
        java.util.Collections.swap(list, n, n-1);
    }
    n--;
}
Roshan123 Roshan123

2021/10/21

#
click it and save ur score. U will notice that it saves but it neither highlights ur score nor sets ur rank. Even if u open the app and try to score at least 3( without changing the name ), u will notice that its as same as the above problem 1 more problem i.e. if u score anything on website then just click on "RANK" button and after viewing the high scores click on "BACK" button. i dont know why it automatically moving on website and not in the app
danpost danpost

2021/10/21

#
Modified methods:
private void drawScores(int game)
{
    final int pixelsPerUser = 50+2*GAP;
    final int numUsers = ((getImage().getHeight()-(HEADER_TEXT_HEIGHT+10))/pixelsPerUser);
    final int topSpace = getImage().getHeight()-(numUsers*pixelsPerUser)-GAP;
    getImage().setColor(BACKGROUND_COLOR);
    getImage().fill();
    drawString("Top Players", 120, topSpace-HEADER_TEXT_HEIGHT-5, MAIN_COLOR, HEADER_TEXT_HEIGHT);
    drawString("Your Score", 120 + getImage().getWidth()/2, topSpace-HEADER_TEXT_HEIGHT-5, MAIN_COLOR, HEADER_TEXT_HEIGHT);        
    List<UserInfo> list = UserInfo.getTop(200);
    for (int i=1; i<list.size(); i++)
    {
        int n = i;
        while (n > 0 && list.get(n).getInt(game) > list.get(n-1).getInt(game)) java.util.Collections.swap(list, n, (n--)-1);
    }
    List<UserInfo> tops = list.subList(0, Math.min(numUsers, list.size()));
    drawUserPanel(game, GAP, topSpace, (getImage().getWidth()/2)-GAP, topSpace+numUsers*pixelsPerUser, tops, 0);
    UserInfo me = UserInfo.getMyInfo();
    int rank = 0;
    for ( ; rank<list.size(); rank++) if (list.get(rank).getUserName().equals(me.getUserName())) break;
    tops = list.subList(rank, rank+1);
    drawUserPanel(game, getImage().getWidth()/2+GAP, topSpace, getImage().getWidth()-GAP, topSpace+1+pixelsPerUser, tops, rank);
}

private void drawUserPanel(int game, int left, int top, int right, int bottom, List users, int startRank)
{
    getImage().setColor(MAIN_COLOR);
    getImage().drawRect(left, top, right-left, bottom-top);
    if (users == null) return;
    UserInfo me = UserInfo.getMyInfo();
    int y = top + GAP;
    for (Object obj : users)
    {
        UserInfo user = (UserInfo)obj;
        if (user == null) continue;
        Color c = (me != null && user.getUserName().equals(me.getUserName())) ? BACKGROUND_HIGHLIGHT_COLOR : BACKGROUND_COLOR;
        getImage().setColor(c);
        getImage().fillRect(left+5, y-GAP+1, right-left-10, 50+2*GAP-1);
        int x = left + 10;
        drawString("#"+Integer.toString(users.indexOf(user)+1+startRank), x, y+18, MAIN_COLOR, 14);
        x += 50;
        drawString(Integer.toString(user.getInt(game)), x, y+18, SCORE_COLOR, 14);
        x += 80;
        getImage().drawImage(user.getUserImage(), x, y);
        x += 55;
        drawString(user.getUserName(), x, y+18, MAIN_COLOR, 14);
        y += 50+2*GAP;
    }
}
Roshan123 Roshan123

2021/10/21

#
Thank u so much!!! It works perfectly except i don't know why it moves automatically on website. It doesn't even stop but it's not my main concern. I think i have to apply elimination method again and again to see which class and line getting triggered in web & i know a secret about u i.e. U r a certified java progammer
danpost danpost

2021/10/21

#
Roshan123 wrote...
U r a certified java progammer
Wrong. I have had little (mostly cursory) instruction in programming (introductory level). Most of what I know come from self-teaching -- as a hobby. Languages touched on in introductory level instruction were Machine, Assembly, Pascal, Fortran, Cobal and RGP. Java, as well as OOP in general, were not even a thing back then.
Roshan123 Roshan123

2021/10/22

#
Ohh sorry, actually i found ur website where u mentioned that u r a java programmer and i took "java programmer" as "Certified java programmer" in my mind Even if i visited that app but their was no reply from u. I thought u used it long years ago so i left it
You need to login to post a reply.
1
2
3