一个非常小的例子,挺好玩的

// simple curses example; keeps drawing the inputted characters, in columns
// downward, shifting rightward when the last row is reached, and
// wrapping around when the rightmost column is reached

#include <curses.h> // required

int r,c, // current row and column (upper-left is (0,0))
nrows, // number of rows in window
ncols; // number of columns in window

void draw(char dc)
{
    move(r,c); // curses call to move cursor to row r, column c
    delch(); insch(dc); // curses calls to replace character under cursor by dc
    refresh(); // curses call to update screen
    r++; // go to next row
    // check for need to shift right or wrap around
    if (r == nrows)
    {
        r = 0;
        c++;

        if (c == ncols)
            c = 0;
    }
}

int main()
{
    int i; char d;
    WINDOW *wnd;
    wnd = initscr(); // curses call to initialize window
    cbreak(); // curses call to set no waiting for Enter key
    noecho(); // curses call to set no echoing
    getmaxyx(wnd,nrows,ncols); // curses call to find size of window
    clear(); // curses call to clear screen, send cursor to position (0,0)
    refresh(); // curses call to implement all changes since last refresh

    r = 0; c = 0;
    while (1)
    {
        d = getch(); // curses call to input from keyboard
        if (d == 'q') break; // quit?
            draw(d); // draw the character
    }

    endwin(); // curses call to restore the original window and leave

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
这里给出一个基于Python Turtle模块的小游戏,叫做“躲避球”(Dodgeball)。 游戏规则: 1. 控制一个小球躲避落下的球。 2. 落下的球速度逐渐加快,难度逐渐增加。 3. 如果小球被击中,游戏结束,显示得分。 代码如下: ```python import turtle import random # 设置窗口大小和标题 wn = turtle.Screen() wn.title("Dodgeball") wn.bgcolor("black") wn.setup(width=600, height=600) # 创建玩家小球 player = turtle.Turtle() player.shape("circle") player.color("white") player.penup() # 设置落下的球列表和速度 balls = [] ball_speed = 1 # 创建落下的球 def create_ball(): ball = turtle.Turtle() ball.shape("circle") ball.color("red") ball.penup() ball.goto(random.randint(-280, 280), 280) balls.append(ball) # 移动玩家小球 def move_left(): x = player.xcor() x -= 20 player.setx(x) def move_right(): x = player.xcor() x += 20 player.setx(x) # 绑定键盘事件 wn.listen() wn.onkeypress(move_left, "Left") wn.onkeypress(move_right, "Right") # 循环游戏 score = 0 while True: # 创建落下的球 if random.randint(1, 10) == 1: create_ball() # 移动落下的球 for ball in balls: y = ball.ycor() y -= ball_speed ball.sety(y) # 判断是否击中玩家小球 if ball.distance(player) < 20: wn.bgcolor("red") player.hideturtle() ball.hideturtle() print("Game Over! Score:", score) wn.exitonclick() # 判断是否落到底部 if y < -280: ball.hideturtle() balls.remove(ball) # 加速落下的球 ball_speed += 0.001 score += 1 ``` 运行代码,就可以开始玩“躲避球”小游戏啦!
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值