Jump to content

Recommended Posts

Hey,

 

I'm creating a simple Minesweeper game in Java for school. I'm having a small issue though. I don't know how to display an integer within a char variable.

 

What I'm doing is checking the left, right, bottom and top for mines and if it's found increment the points for each mine.

 

I'm using a bi dimensional array, Table[x ][y] (table is assigned as a char) and I'm printing it out.

 

After adding all the points I want to display the points to that assigned coordinates (x, y). But I can't do Table[x ][y] == points as Table is searching for a character not an integer. I also tried doing Table[x ][y] = ' ' +points but that's a no go.

 

Is there something I can do to display the points?

Well the number characters are 48-57:

 

0 = 48

1 = 49

....

9 = 57

 

 

 

So as long as you're talking single digits, it's essentially (this is c++ code... you'll have to do the Java equivalent):

 

char c = '5';

int num = ((int) c) - 48;

 

 

 

 

 

 

 

 

 

(Or did I entirely misunderstand your question?)

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.