#!/usr/bin/env ruby # DouShouQi Textual Game Interface # Copyright (C) 2007 Aurelio A. Heckert # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program. If not, see . # or directly http://www.gnu.org/licenses/gpl-3.0.html require 'DouShouQi' game = DouShouQi::Game.new STDIN.sync = true plaing = true update = true dirNames = { 'N' => 'North', 'S' => 'South', 'W' => 'West', 'L' => 'Lest' } while plaing do if update puts "\n Turn: " + game.turn.to_s puts "\n " + game.showJungle.split( // ).join( ' ' ).gsub( /\n/, "\n " ) aliveAnimalsSymbols = game.listAliveAnimals( game.currentPlayerNum, :symbol ) if game.isOver? then puts " "+ game.player( game.winer ).name() +" wins the game!" plaing = false else puts " " + game.currentPlayer.name print " Select the animal [ #{ aliveAnimalsSymbols.join ', ' } ]. (Esc to exit game) " STDOUT.flush end end if game.isOver? cmd = "game over" else cmd = STDIN.getc if ( cmd == 27 ) then plaing = false cmd = "Esc" puts "\n End Game :-(" else cmd = (game.currentPlayerNum == 0)? cmd.chr.upcase : cmd.chr.downcase end end if aliveAnimalsSymbols.include? cmd then movingAnimal = game.getAnimal( game.currentPlayerNum, cmd, :symbol ) puts cmd +' = '+ movingAnimal[:name] print " Select the direction [ N, S, W, L ] " STDOUT.flush direction = '' while ! dirNames.keys.include?( direction ) do direction = STDIN.getc.chr.upcase end puts dirNames[direction] error = game.moveAnimal movingAnimal[:num], game.direction[ direction.to_sym ] puts ' ' + error.comment update = true else update = false end end