#!/usr/bin/ruby #init curses require "ncurses" Ncurses::initscr #CONFIG Ncurses::nl Ncurses::noecho Ncurses::curs_set(0) Ncurses::nodelay(Ncurses::stdscr, true) Ncurses::raw Ncurses::keypad(Ncurses::stdscr,1) Ncurses::start_color Ncurses::init_pair(1,Ncurses::COLOR_GREEN, Ncurses::COLOR_RED) Ncurses::init_pair(2,Ncurses::COLOR_CYAN, Ncurses::COLOR_BLACK) my_window = Ncurses::WINDOW.new(24,75,0,0) #the pong class class Pong attr_accessor :x, :y, :keyUP, :keyDOWN, :length def move(direction) if (direction == 1) @y = @y-1 elsif (direction == 2) @y = @y+1 end end end class Ball attr_accessor :x, :y, :xspeed, :yspeed, :oldy, :oldx def move @oldx = @x @oldy = @y @x = @x + @xspeed @y = @y + @yspeed end end #create a pong firstpong = Pong.new firstpong.x = 4 firstpong.y = 4 firstpong.keyUP = "KEY_UP" firstpong.keyDOWN = "KEY_DOWN" firstpong.length = 3 #and another one secondpong = Pong.new secondpong.x = 70 secondpong.y = 15 secondpong.keyUP = "KEY_LEFT" secondpong.keyDOWN= "KEY_RIGHT" secondpong.length = 3 #okay now we have the pongs. #lets put a ball on the field! ball = Ball.new ball.x = 15 ball.y = 10 ball.xspeed=1 ball.yspeed=1 #main loop begin case(Ncurses.getch) when "q"[0] break when Ncurses::KEY_UP secondpong.move(1) when Ncurses::KEY_DOWN secondpong.move(2) when "a"[0] firstpong.move(1) when "z"[0] firstpong.move(2) end #do some magic ball things, like move it ball.move #check if ball hits wall if(ball.x >= 72) ball.xspeed = -1 elsif(ball.x <=2) ball.xspeed=1 elsif(ball.y <= 2) ball.yspeed = 1 elsif(ball.y >= 22) ball.yspeed = -1 end #draw things my_window.border(*([0]*8)) my_window.color_set(2,nil) #draw a black square on the old ball location my_window.mvaddstr(ball.oldy , ball.oldx , " ") my_window.mvaddstr(ball.y,ball.x, "*") #do the PONGS! c=0 my_window.mvaddstr(firstpong.y - 1, firstpong.x, " "); my_window.color_set(1,nil) begin my_window.mvaddstr(firstpong.y + c,firstpong.x, " ") c = c+1 end while c