C++ MP3播放器按钮类似功能实现

// Class01.cpp : Defines the entry point for the console application.
//


#include "stdafx.h"
#include <stdlib.h>
#include <vector>
#include <string>
#include <conio.h>
#include <stdio.h>
#include <iostream>
using namespace std;

class Mp3Menu
{
private:
	vector<string> SongList;//歌曲容器,用于保存歌曲列表
    vector<string>::iterator SongListIter;//容器迭代器,用于指示歌曲
	int ListNO;
public:
	Mp3Menu();
	Mp3Menu(vector<string> &SongList);
	void Interface();//展示歌曲列表的界面函数,用于上下的功能
	void AddSong(const string SongName);//添加歌曲的函数
	void Init();
};

void Mp3Menu::Init()
{
	this->SongListIter = SongList.begin();
	this->ListNO = 0;
}

Mp3Menu::Mp3Menu()
{
	SongListIter = SongList.begin();
	this->ListNO = 0;
}

Mp3Menu::Mp3Menu(vector<string> &SongList)
{
	this->SongList = SongList;
	this->SongListIter = SongList.begin(); 
	this->ListNO = 0;
}

void Mp3Menu::AddSong(const string SongName)
{
	this->SongList.push_back(SongName);
}

void Mp3Menu::Interface()
{
	char button;
	int SongNumber = 0,i = 0,FourSong = 1;
	int CurrentNO = 1;
	Init();
	while( this->SongListIter != this->SongList.end() )
	{
		this->SongListIter++;
		SongNumber++;
	}
	while( 1 )
	{
		system("cls");
		if( (FourSong >= SongNumber-3) && SongNumber >= 4 )
			FourSong = SongNumber - 3;
		if( SongNumber >= 4 )
		{
			for( i = 1; i <= 4; i++ )
			{
				cout<<"--------------------"<<endl;
				if( i == CurrentNO )
					cout<<"-->"<<FourSong<<"."<<SongList.at(FourSong)<<endl;
				else
					cout<<FourSong<<"."<<SongList.at(FourSong)<<endl;
				FourSong++;
			}
		}
		else
		{
			for( i = 1; i <= SongNumber; i++ )
			{
				cout<<"--------------------"<<endl;
				if( i == CurrentNO )
					cout<<"-->"<<FourSong<<"."<<SongList.at(FourSong)<<endl;
				else
					cout<<FourSong<<"."<<SongList.at(FourSong)<<endl;
				FourSong++;
			}
		}
		button = getch();
		switch (button)
		{
			case '0':
				exit(1);break;
			case 's':
				this->ListNO++;
				CurrentNO++;
				if( this->ListNO > SongNumber - 1 )
				{
					this->ListNO = 0;
					CurrentNO = 1;
				}
				if( CurrentNO > 4 )
				{
					CurrentNO = 4;
				}
				break;
			case 'w':
				this->ListNO--;
				//CurrentNO--;
				if( this->ListNO < 0 )
				{
					this->ListNO = SongNumber - 1;
					CurrentNO = 4;
				}
				if( this->ListNO <= 3 )
					CurrentNO--;
				if( CurrentNO <= 0 )
				{
					CurrentNO = 1;
				}
				break;
			default:break;
		}
		if( this->ListNO > 3 )
			FourSong = this->ListNO - 3;
		else
			FourSong = 1;
	}

}



int _tmain(int argc, _TCHAR* argv[])
{
	vector<string> SongList;
	string temp;
	string SongName;
	//for( i = 0; i< 20; i++ )
	//{
	//	
	//	SongName = "love" + temp;
	//	SongList.push_back(SongName);
	//}
	SongList.push_back("a");
	SongList.push_back("b");
	SongList.push_back("c");
	SongList.push_back("d");
	SongList.push_back("f");
	SongList.push_back("e");
	SongList.push_back("f");
	SongList.push_back("g");
	SongList.push_back("h");
	SongList.push_back("i");
	SongList.push_back("j");
	SongList.push_back("k");
	Mp3Menu test(SongList);
	test.Interface();
	
	return 0;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

南窗客斯黄

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值