rendered paste body#!/usr/bin/ruby#init cursesrequire "ncurses"Ncurses::initscr#CONFIGNcurses::nlNcurses::noechoNcurses::curs_set(0)Ncurses::nodelay(Ncurses::stdscr, true)Ncurses::rawNcurses::keypad(Ncurses::stdscr,1)Ncurses::start_colorNcurses::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 classclass Pong attr_accessor :x, :y, :keyUP, :keyDOWN, :length def move(direction) if (direction == 1) @y = @y-1 elsif (direction == 2) @y = @y+1 end endendclass Ball attr_accessor :x, :y, :xspeed, :yspeed, :oldy, :oldx def move @oldx = @x @oldy = @y @x = @x + @xspeed @y = @y + @yspeed endend#create a pongfirstpong = Pong.newfirstpong.x = 4firstpong.y = 4firstpong.keyUP = "KEY_UP"firstpong.keyDOWN = "KEY_DOWN"firstpong.length = 3#and another onesecondpong = Pong.newsecondpong.x = 70secondpong.y = 15secondpong.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.newball.x = 15ball.y = 10ball.xspeed=1ball.yspeed=1#main loopbegin 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<firstpong.length my_window.color_set(2,nil) my_window.mvaddstr(firstpong.y + c , firstpong.x, " ") #second pong my_window.color_set(2,nil) my_window.mvaddstr(secondpong.y - 1, secondpong.x , " ") c=0 my_window.color_set(1,nil) begin my_window.mvaddstr(secondpong.y + c,secondpong.x, " ") c=c+1 end while c<secondpong.length my_window.color_set(2,nil) my_window.mvaddstr(secondpong.y + c, secondpong.x, " ") #update screen my_window.noutrefresh() Ncurses::doupdate sleep(0.05) end while trueNcurses::echoNcurses::nocbreakNcurses::curs_set(1)Ncurses::endwin