printf画的俄罗斯方块(linux异步I/O,C++)
这个方块游戏是用linux终端的光标控制、颜色设置做的
(添了个功能,字母P暂停、恢复游戏)
用 A S D W 控制移动、转向,空格键下坠到底;
linux的异步aio函数解决了很多麻烦;
用了个简单的模板单例模式,继承它就可以;
对POSIX线程简单封装成java线程接口;
#include <memory>
#include "Tetris.h"
#include "TtyAuto.h"
static void instruction()
{
// 一些说明性文字
printf("\033[2J");
printf("\033[4;34;47m%s\033[0m", "\t\t\tYou can use the key 'A','S','D','W' to control the block.\n\n\t\t\tPress space key make the block down to bottom.\n\n\t\t\t'P' to pause the game.\n\n");
printf("\033[5;34;41m%s\033[0m", "\t\t\tPRESS ANY KEY TO START GAME...\n\n" );
getchar();
}
int main(int ac, char *av[])
{
std::auto_ptr<TtyAuto> autoAdjustTty(TtyAuto::getInstance());
instruction();
// 游戏开始
Tetris game;
game.start();
game.join();
printf("\r\t\t\t\t\t\r");
return 0;
}
#ifndef BERT_THREAD_H
#define BERT_THREAD_H
#include <pthread.h>
/**
* 线程封装,接口模仿JAVA
*/
class Runnable
{
public:
virtual ~Runnable() { }
/**
* 线程逻辑在此实现
*/
virtual void run() = 0;
};
class Thread: public Runnable
{
/**
* 本线程ID
*/
pthread_t m_tid;
/**
* 是否在运行的标志
*/
bool running;
/**
* 线程函数,内部调用run
*/
static void * threadFunc(void * arg);
public:
Thread();
~Thread();
/**
* 睡眠 秒
*/
static unsigned int sleep( unsigned int seconds);
/**
* 睡眠毫秒
*/
static unsigned int msleep( unsigned int mSeconds);
/**
* 启动线程
*/
bool start() ;
/**
* 等待本线程运行完
*/
void join() const;
/**
* 是否在运行
*/
bool isAlive() const
{
return running;
相关文档:
#include <sys/select.h>
#include <sys/time.h>
#include
<sys/types.h>
#include <unistd.h>
int select(int
nfds,fd_set *readfds,fd_set *writefds, fd_set *except fds,struct timeval
*timeout)
void FD_SET(int fd,fd_set *fdset)
void FD_CLR(int fd,fd_set
*fdset)
void F ......
如何发展Linux?中日两国之间存在何种差异?有什么好说的?
大约是在1997年的夏天,国内召开第一次Linux高层邀请研讨会,我想,现今那次邀请会的全体与会者都还健在,姓名我就不说了。记得,我去机场迎接Cliff Miller夫妇,那时,Cliff是日本TurboLinux的CEO,专 ......
转自:http://os.51cto.com/art/201002/184694.htm
世界上最大的技术支持、软件和硬件公司每天使用Linux完成各种任务与解决方案,那么这些大公司究竟是怎么使用Linux的呢?其实并不神秘,本
文为你揭晓答案,大多数公司都不会使用Linux作为桌面操作系统,主要是用于后端服务器操作系统,经过这些大公司的大胆尝试,许多事 ......
第九部分:除以下选项,其它全部删除
Networking
Networking options --->
[]Unix domain sockets
[]TCP/IP networking
第十部分:除以下选项,其它全部删除
Device Drivers --->设备驱动
Block devices-------〉
[]Compaq SMART2 support
[] Compaq Smart Array 5xxx supp ......