JonPerl has asked for the wisdom of the Perl Monks concerning the following question:
ok so basically Im tying to draw a map using ASCII and then erase it then redraw it so it refreshes and people can see updates (like my "@" char moving across the screen). I have no idea how to get it to work and my current code isnt working.#!/usr/bin/perl use strict; $| = 1; my @map =([1,1,1,1,1,1,1,1,1,1,1,1,1,1,1], [1,0,0,0,0,0,0,0,0,0,0,0,0,0,1], [1,0,0,0,0,0,0,0,0,0,0,0,0,0,1], [1,0,0,0,0,0,0,0,0,0,0,0,0,0,1], [1,0,0,0,0,0,0,0,0,0,0,0,0,0,1], [1,0,0,0,0,0,0,0,0,0,0,0,0,0,1], [1,0,0,0,0,0,0,0,0,0,0,0,0,0,1], [1,0,0,0,0,0,0,0,0,0,0,0,0,0,1], [1,0,0,0,0,0,0,0,0,0,0,0,0,0,1], [1,0,0,0,0,0,0,0,0,0,0,0,0,0,1], [1,0,0,0,0,0,0,0,0,0,0,0,0,0,1], [1,0,0,0,0,0,0,0,0,0,0,0,0,0,1], [1,0,0,0,0,0,0,0,0,0,0,0,0,0,1], [1,0,0,0,0,0,0,0,0,0,0,0,0,0,1], [1,1,1,1,1,1,1,1,1,1,1,1,1,1,1]); my @char = (8,4); my %chir = {'xposition' => $char[0], 'ypostion' => $char[1]}; my $game = 1; #set to 0 for false while($game){ for (my $i=0;$i<@map;$i++){ for (my $p=0;$p<@{$map[$i]};$p++){ if(($i==8)&&($p==4)){ print("@"); } elsif($map[$i]->[$p]==0){ print(" "); } elsif($map[$i]->[$p]==1){ print("*"); } print(" "); } print("\n"); } for (my $i=0;$i<@map;$i++){ for (my $p=0;$p<@{$map[$i]};$p++){ print "\b" x 1; } print "\b" x 1; } }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: How do I get my ascii tile code to refresh without looking weird
by Joost (Canon) on Sep 12, 2007 at 18:20 UTC | |
|
Re: How do I get my ascii tile code to refresh without looking weird
by superfrink (Curate) on Sep 12, 2007 at 18:15 UTC | |
|
Re: How do I get my ascii tile code to refresh without looking weird
by Anno (Deacon) on Sep 12, 2007 at 18:53 UTC |