simple vector scrolling..

This is a discussion on simple vector scrolling.. within the C++ Programming forums, part of the General Programming Boards category; yeah i was wondering if you could help me with a simple algorithm im missing. I have some player scores ...

  1. #1
    Registered User
    Join Date
    Nov 2003
    Posts
    5

    simple vector scrolling..

    yeah i was wondering if you could help me with a simple algorithm im missing.
    I have some player scores I want to show in a game, and i have them stored in a vector. What i want to do is show 10 scores at a time on screen, then have a "next line" and "prev line" button to scroll through the scores.

    a basic idea ive been thinking about is make a 10-element vector and store the elements i want to display from the bigger vector onto that one. this is what i got so far:

    Code:
    void Stats::update_next()
    {
      cursor = (cursor+1)%len;
    }
    
    void Stats::update_prev()
    {
    if(cursor <= 0)
      return;
    else
      cursor = (cursor-1)% len;
    }
    
    
    vector<Player> Stats::current_stats(const vector<Player>& players)
    {
            vector<Player> temp2(10);
    	for (int i=0; i<temp2.size(); i++)
    	   temp2[i].push_back(players[(cursor+i)%len]);
    	return temp2;
    }
    where len = players.size() and cursor is initialized to 0 (on its first run).

    thanks in advace : ]

  2. #2
    Registered User
    Join Date
    Nov 2003
    Posts
    5
    n/m, figured it out ;D

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. creating very simple text editor using c
    By if13121 in forum C Programming
    Replies: 9
    Last Post: 10-19-2010, 05:26 PM
  2. Simple message encryption
    By Vicious in forum C++ Programming
    Replies: 10
    Last Post: 11-07-2004, 10:48 PM
  3. Binary Search Trees Part III
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 10-02-2004, 03:00 PM
  4. Simple simple program
    By Ryback in forum C++ Programming
    Replies: 10
    Last Post: 09-09-2004, 05:48 AM
  5. Need help with simple DAQ program
    By canada-paul in forum C++ Programming
    Replies: 12
    Last Post: 03-15-2002, 07:52 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21