/    Sign up×
Community /Pin to ProfileBookmark

Text Based Strategy Game

Hello,

I am trying to make a text based strategy game. The rules for the game are here [url]http://www.mrsticky005.com/Conquer.html[/url] and as you can see it’s a fairly complex game. But pretty much the general idea is you are trying to build and maintain a global empire from scratch.

This is what I’ve got going so far [url]http://www.mrsticky005.com/PlayConquer.html[/url]

Obviously I did not create the code for the chat.

I apologize in advance if I’m really really slow when it comes to this sort of stuff. Of course there are tutorial sites
but the problem is I don’t even know what I should be looking for.

Specifically what I want to know is how can I click on say the ocean button and get it so where it says location that it would show which ocean I was randomly selected for?

to post a comment
JavaScript

21 Comments(s)

Copy linkTweet thisAlerts:
@SempervivumJun 12.2016 — Obviously I did not create the code for the chat. [/QUOTE]Did you google for "php free chat download"? This finds a lot of chat scripts, e. g. this:

http://www.pcpin.com/

which seems to meet your requirements.
Copy linkTweet thisAlerts:
@mrsticky005authorJun 12.2016 — Did you google for "php free chat download"? This finds a lot of chat scripts, e. g. this:

http://www.pcpin.com/

which seems to meet your requirements.[/QUOTE]


I already have the chat on the site so I'm not sure how that would help in making the game.
Copy linkTweet thisAlerts:
@SempervivumJun 12.2016 — Sorry, then I didn't understand this correctly:Obviously I did not create the code for the chat.[/QUOTE]I understood it in that way that you have no code yet!
Copy linkTweet thisAlerts:
@mrsticky005authorJun 12.2016 — Ok. I figured out how to get it so when you click ocean it changes your location.

Now the next part is a bit trickier. I want to click "Atlantic Fishing $5" and have it deduct from the gold.
Copy linkTweet thisAlerts:
@mrsticky005authorJun 12.2016 — 15 Errors, 4 warning(s)

https://validator.w3.org/check?uri=http%3A%2F%2Fwww.mrsticky005.com%2FPlayConquer.html&charset=%28detect+automatically%29&doctype=Inline&group=0[/QUOTE]


Meaning? Look, I'm not some kind of coding expert (obviously). I write comics. This is a site for my comics

and on top of which I wanted to try and make this game. So I'm sure there are a billion errors.
Copy linkTweet thisAlerts:
@SempervivumJun 12.2016 — I want to click "Atlantic Fishing $5" and have it deduct from the gold.[/QUOTE]Don't understand: Where is the gold? I only find a string "Gold" in the Stats box.
Copy linkTweet thisAlerts:
@mrsticky005authorJun 12.2016 — Don't understand: Where is the gold? I only find a string "Gold" in the Stats box.[/QUOTE]

you start off the game by clicking the "oceans" button. This will take you to one of the four oceans.

Let's say you got the Atlantic Ocean. (It will show up under your location)

Next you click on "Atlantic Fishing $5"

What I want this to do is to

  • 1. automatically deduct $5 from your starting $50


  • so that your gold in your stats goes from $50 to $45


  • 2. If you "fish" in the Atlantic Ocean and you get Gold x 1 ($15) it will add $15


  • so $45 + $15

    $60
    Copy linkTweet thisAlerts:
    @mrsticky005authorJun 12.2016 — Basically when you go "fishing" it gets you a random item that will affect your stats in different ways.

    For example if you fish and get poison it will change your "status' to poisoned.
    Copy linkTweet thisAlerts:
    @SempervivumJun 12.2016 — your starting $50[/QUOTE]Cannot find this. Close to "Gold" in the Stats box nothing is displayed.
    Copy linkTweet thisAlerts:
    @mrsticky005authorJun 12.2016 — Cannot find this. Close to "Gold" in the Stats box nothing is displayed.[/QUOTE]


    i dont have anything displayed yet.

    how would i display it as a changing value?
    Copy linkTweet thisAlerts:
    @mrsticky005authorJun 12.2016 — Cannot find this. Close to "Gold" in the Stats box nothing is displayed.[/QUOTE]

    where it says gold is where the amount of money you have in the game would be shown. so it should act as a scoreboard
    Copy linkTweet thisAlerts:
    @SempervivumJun 12.2016 — It makes your code difficult to handle when you have seven javascript files. Concentrate them in one file.

    You need only one function getRandomWord() when you pass the array as a parameter.

    And give meaningful names to your functions.
    Copy linkTweet thisAlerts:
    @mrsticky005authorJun 12.2016 — It makes your code difficult to handle when you have seven javascript files. Concentrate them in one file.

    You need only one function getRandomWord() when you pass the array as a parameter.

    And give meaningful names to your functions.[/QUOTE]


    Last time I tried that the buttons were not working. Like it kept getting confused with what button does what.

    Or with where the "result" is suppose to go.

    What do you mean by "pass the array as a parameter"?

    Also wouldn't I need more than one function since the buttons do different thing?
    Copy linkTweet thisAlerts:
    @mrsticky005authorJun 12.2016 — Well I tried concentrating it all in one file and now none of it works. So I dunno.
    Copy linkTweet thisAlerts:
    @SempervivumJun 13.2016 — What do you mean by "pass the array as a parameter"?[/QUOTE]Define and call the function like this:
    [CODE]var getRandomWord = function (words) {
    return words[Math.floor(Math.random() * words.length)];
    };
    var word1 = getRandomWords(words1);
    var word2 = getRandomWords(words2);[/CODE]


    Well I tried concentrating it all in one file and now none of it works. So I dunno.[/QUOTE]Try it again and put it online. I will have a look at it. You may create a second page if you don't want to have a non working one online.
    Copy linkTweet thisAlerts:
    @SempervivumJun 13.2016 — If I read the code correctly, this should do the job:

    Javascript:
    [CODE]var stats = {gold: 0, fish: 0, nothing: 0};
    // extend this object according your needs

    var dataAtlanticFishing = [
    {text: "You rolled a 1 and got Gold x 1", type: "gold", amount: +30},
    {text: "You rolled a 2 and got Fish x 1", type: "fish", amount: +15},
    // and so on
    {text: "You rolled a 12 and got Nothing," type: "nothing", amount: 0)
    ];
    // define data for other sets of words

    function processClick(data, id) {
    cData =data[Math.floor(Math.random() * data.length)];
    document.getElementById(id).textContent = cData.text;
    stats[cData.type] += cData.amount;
    document.getElementById("balance-" + cData.type).value = balances[cData.type];
    };[/CODE]


    HTML:
    [code=html]// button as you have it already:
    <button onclick='processClick(dataAtlanticFishing, "text-AtlanticFishing")'>Atlantic Fishing $5</button>

    // Text is displayed here:
    <p id="text-AtlanticFishing"></p>

    // Stats containing balance. Not shure whether the balance for fish
    // should be separate by oceans
    Gold:<input type="text" id="balance-gold">
    Fish: <input type="text" id="balance-fish">[/code]


    Try to integrate this into your page and if it doesn't work, come back.

    I didn't test the code as I didn't implement the complete game.
    Copy linkTweet thisAlerts:
    @mrsticky005authorJun 13.2016 — If I read the code correctly, this should do the job:

    Javascript:
    [CODE]var stats = {gold: 0, fish: 0, nothing: 0};
    // extend this object according your needs

    var dataAtlanticFishing = [
    {text: "You rolled a 1 and got Gold x 1", type: "gold", amount: +30},
    {text: "You rolled a 2 and got Fish x 1", type: "fish", amount: +15},
    // and so on
    {text: "You rolled a 12 and got Nothing," type: "nothing", amount: 0)
    ];
    // define data for other sets of words

    function processClick(data, id) {
    cData =data[Math.floor(Math.random() * data.length)];
    document.getElementById(id).textContent = cData.text;
    stats[cData.type] += cData.amount;
    document.getElementById("balance-" + cData.type).value = balances[cData.type];
    };[/CODE]


    HTML:
    [code=html]// button as you have it already:
    <button onclick='processClick(dataAtlanticFishing, "text-AtlanticFishing")'>Atlantic Fishing $5</button>

    // Text is displayed here:
    <p id="text-AtlanticFishing"></p>

    // Stats containing balance. Not shure whether the balance for fish
    // should be separate by oceans
    Gold:<input type="text" id="balance-gold">
    Fish: <input type="text" id="balance-fish">[/code]


    Try to integrate this into your page and if it doesn't work, come back.

    I didn't test the code as I didn't implement the complete game.[/QUOTE]



    First off thanks for your help.

    Second, I tried implementing the code. I probably messed up somewhere.

    What would "var stats" be?
    Copy linkTweet thisAlerts:
    @SempervivumJun 13.2016 — No, at the current state it wasn't you who messed it up but I made a mistake. This line in conquer7.js is faulty:
    [CODE] {text: "You rolled a 12 and got Nothing," type: "nothing", amount: 0)[/CODE]
    The comma after "got Nothing" is misplaced. This is correct:
    [CODE] {text: "You rolled a 12 and got Nothing", type: "nothing", amount: 0)[/CODE]

    The purpose of the variable stats is to keep the values of the Stats box. So far I understood the game in that way that the amount of gold, fish etc. is summarized in that box. Correct me if I'm wrong.
    Copy linkTweet thisAlerts:
    @mrsticky005authorJun 13.2016 — No, at the current state it wasn't you who messed it up but I made a mistake. This line in conquer7.js is faulty:
    [CODE] {text: "You rolled a 12 and got Nothing," type: "nothing", amount: 0)[/CODE]
    The comma after "got Nothing" is misplaced. This is correct:
    [CODE] {text: "You rolled a 12 and got Nothing", type: "nothing", amount: 0)[/CODE]

    The purpose of the variable stats is to keep the values of the Stats box. So far I understood the game in that way that the amount of gold, fish etc. is summarized in that box. Correct me if I'm wrong.[/QUOTE]




    OK there are 7 Stats

  • 1. Gold

  • 2. HP (Health Points)

  • 3. Location

  • 4. Class

  • 5. Items

  • 6. Status

  • 7. Attack



  • 1. Gold is the amount of money you have in the game. You start off at $50. When you go "fishing" you have to pay a fee.

    Atlantic Ocean being the cheapest and Indian Ocean the most expensive. When you fish you get a random item.

    If you get "Gold x 1" it will increase your gold by a value of "+$15" . "Gold x 2" naturally doubles that to "+$30".

    Throughout the game you will be taxed. When you cannot pay your taxes you go to "Debtor's Prison" which is basically

    like Jail is in monopoly.


  • 2. HP or Health Points is the amount of health you have. You start off with 10 HP. If you get a "Fish x 1" this will increase

    your health by +10 HP when you "eat it". You do not have to eat the fish immediately. You can save it to your "items"

    and either use it later or even sell it to another player.


  • 3. Location is simply where you are in the game. You click on the Oceans button to pick a random ocean where you go "fishing".

    These oceans also contain the continents. When you cannot pay taxes you go to "Debtor's Prison"


  • 4. Class is who you are in the game. You start off as a Pirate, but you can become a "Ruler" when you either buy a continent or take one by force. If a continent is already under rule you can become a "Citizen". When you become a citizen your stats are combined into the continent's stats. So in other words the continent is the aggregate of all it's citizens stats.


  • 5. Items can either be used or collected. For example you can either use fish to gain HP, collect them to use at a latter time, or even sell them to other players.




  • 6. Status is whether you are poisoned or captured by a squid.


  • 7. Attack is how much damage you do when you attack your opponent. You start off with 10 ATK. This means that when you

    successfully attack your opponent you will take away 10 HP from them. This will also INCREASE your HP by 10.
  • Copy linkTweet thisAlerts:
    @SempervivumJun 14.2016 — Thanks for this explanation. I read it as far as it's related to fishing. Knowing this my code has to be extended a bit:
    [CODE]var stats = {gold: 50, fish: 0, hp:10, nothing: 0};
    // extend this object according your needs

    var dataAtlanticFishing = [
    {text: "You rolled a 1 and got Gold x 1", type: "gold", amount: +30},
    {text: "You rolled a 2 and got Fish x 1", type: "fish", amount: +15},
    // and so on
    {text: "You rolled a 12 and got Nothing," type: "nothing", amount: 0)
    ];
    // define data for the other oceans

    function doFishing(data, id, cost) {
    stats.gold -= cost;
    cData =data[Math.floor(Math.random() * data.length)];
    document.getElementById(id).textContent = cData.text;
    stats[cData.type] += cData.amount;
    document.getElementById("balance-" + cData.type).value = balances[cData.type];
    };[/CODE]

    [code=html]// button as you have it already:
    <button onclick='doFishing(dataAtlanticFishing, "text-AtlanticFishing", 5)'>Atlantic Fishing $5</button>

    // Text is displayed here:
    <p id="text-AtlanticFishing"></p>

    // Stats containing balance.
    Gold:<input type="text" id="balance-gold">
    Fish: <input type="text" id="balance-fish">
    Health Points: <input type="text" id="balance-hp">[/code]
    Completing this code you can code the fishing procedure by using only one function doFishing().
    ×

    Success!

    Help @mrsticky005 spread the word by sharing this article on Twitter...

    Tweet This
    Sign in
    Forgot password?
    Sign in with TwitchSign in with GithubCreate Account
    about: ({
    version: 0.1.9 BETA 5.24,
    whats_new: community page,
    up_next: more Davinci•003 tasks,
    coming_soon: events calendar,
    social: @webDeveloperHQ
    });

    legal: ({
    terms: of use,
    privacy: policy
    });
    changelog: (
    version: 0.1.9,
    notes: added community page

    version: 0.1.8,
    notes: added Davinci•003

    version: 0.1.7,
    notes: upvote answers to bounties

    version: 0.1.6,
    notes: article editor refresh
    )...
    recent_tips: (
    tipper: @AriseFacilitySolutions09,
    tipped: article
    amount: 1000 SATS,

    tipper: @Yussuf4331,
    tipped: article
    amount: 1000 SATS,

    tipper: @darkwebsites540,
    tipped: article
    amount: 10 SATS,
    )...