Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8072943
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T14:10:52+00:00 2026-06-05T14:10:52+00:00

I’m learning some web programming programming right now and I’m a little stuck. I’m

  • 0

I’m learning some web programming programming right now and I’m a little stuck.

I’m trying to move a character around an array (like a simple rogue-like game) using the WASD keys but I can’t seem to figure it out.

So I was wondering if someone could explain to me what I’m doing wrong exactly?

heres the code:

<html>
<body style="font-family: Courier" onkeydown="move(event)">
<p id="game" >
<?php

// php functions regarding movement

    $map = array(
    "XXXXXXXXXX",
    "X........X",
    "X...XX...X",
    "X...XX...X",
    "X........X",
    "XXXX..XXXX",
    "X........X",
    "X..X..X..X",
    "X........X",
    "XXXXXXXXXX",

    );

    $player = new Player(2,2,"T");
    initMap($map);
    makePlayer($player);
    displayMap($map);
?>
</p>
<script  type="text/javascript" src="jquery.js">

function move(ev){
    var key = (ev) ? ev.which : event.keyCode;
    var c = String.fromCharCode(key);
    $("#game").html('function move is working') 

    switch(c){
    case "w":
        <?php 
            moveUp();
        ?>
        $("#game").empty();
    
        break;

    // keys ASD all share same code

    default:
        break;
    
}
}
</script>
</body>
</html>


/* output, no changes when key is pressed:

XXXXXXXXXX
X........X
X.T.XX...X
X...XX...X
X........X
XXXX..XXXX
X........X
X..X..X..X
X........X
XXXXXXXXXX
*/

Pressing any of the keys should clear the html from the #game div, but it does not. Any suggestions?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T14:10:53+00:00Added an answer on June 5, 2026 at 2:10 pm

    I think i can help you with your problem. Just try my example below about movements:

       1. HTML
           <div id="map"></div>
       2. CSS
           #map {position:relative; width:600px; height:300px; border:1px solid gray;}
           .ball {position:absolute; width:50px; height:50px; 
           -moz-border-radius:35px; border:1px solid red;}
    
       3. JS
           <script type="text/javascript">
           $(function(){
        var ball = $("<div class='ball'></div>");
                $("#map").append(ball);
                $(document).keydown(function(e){
                        //alert(e.keyCode);
                    var position = $(".ball").position();
    
                        switch(e.keyCode){
    
                                                        case 37:  //left
                                                       $(".ball").css("left", position.left  - 50  + "px");                        
                                        break;
                                        case 38:  //up
                                                $(".ball").css("top", position.top - 50  + "px");
                                        break;
                                        case 39: //right
                                                $(".ball").css("left", position.left + 50  +"px");
                                        break;
                                        case 40: //down
                                                $(".ball").css("top", position.top + 50 +"px");
                                        break;
                                }
                    });
    
    
    
    });
    </script>
    
    
    
      Hope this will help.tnx
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

For some reason, after submitting a string like this Jack’s Spindle from a text
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
this is what i have right now Drawing an RSS feed into the php,
I am trying to render a haml file in a javascript response like so:
I'm trying to use string.replace('’','') to replace the dreaded weird single-quote character: ’ (aka
I have some data like this: 1 2 3 4 5 9 2 6
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and
I would like to count the length of a string with PHP. The string

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.