Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
J
JTankTrouble
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
9831111
JTankTrouble
Commits
096e9cb2
Commit
096e9cb2
authored
Jul 24, 2020
by
nargessalehi98
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add correct map size.
parent
655f2ab7
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
55 additions
and
36 deletions
+55
-36
GameFrame.java
src/GameFrame.java
+55
-36
No files found.
src/GameFrame.java
View file @
096e9cb2
...
@@ -24,7 +24,7 @@ import java.util.Scanner;
...
@@ -24,7 +24,7 @@ import java.util.Scanner;
*/
*/
public
class
GameFrame
extends
JFrame
{
public
class
GameFrame
extends
JFrame
{
public
static
final
int
GAME_HEIGHT
=
8
0
0
;
// 720p game resolution
public
static
final
int
GAME_HEIGHT
=
8
8
0
;
// 720p game resolution
//720
//720
public
static
final
int
GAME_WIDTH
=
16
*
720
/
9
;
// wide aspect ratio
public
static
final
int
GAME_WIDTH
=
16
*
720
/
9
;
// wide aspect ratio
...
@@ -46,18 +46,17 @@ public class GameFrame extends JFrame {
...
@@ -46,18 +46,17 @@ public class GameFrame extends JFrame {
setResizable
(
false
);
setResizable
(
false
);
setSize
(
GAME_WIDTH
,
GAME_HEIGHT
);
setSize
(
GAME_WIDTH
,
GAME_HEIGHT
);
setLayout
(
new
BorderLayout
());
setLayout
(
new
BorderLayout
());
PlayerState
=
new
JPanel
();
PlayerState
=
new
JPanel
();
PlayerState
.
setBackground
(
Color
.
pink
);
PlayerState
.
setBackground
(
Color
.
pink
);
add
(
PlayerState
,
BorderLayout
.
SOUTH
);
add
(
PlayerState
,
BorderLayout
.
SOUTH
);
try
{
try
{
image1
=
ImageIO
.
read
(
new
File
(
"Tank_dark.png"
));
image1
=
ImageIO
.
read
(
new
File
(
"Tank_dark.png"
));
image2
=
ImageIO
.
read
(
new
File
(
"Tank_blue.png"
));
image2
=
ImageIO
.
read
(
new
File
(
"Tank_blue.png"
));
image3
=
ImageIO
.
read
(
new
File
(
"Tank_red.png"
));
image3
=
ImageIO
.
read
(
new
File
(
"Tank_red.png"
));
image4
=
ImageIO
.
read
(
new
File
(
"Tank_green.png"
));
image4
=
ImageIO
.
read
(
new
File
(
"Tank_green.png"
));
image5
=
ImageIO
.
read
(
new
File
(
"Tank_sand.png"
));
image5
=
ImageIO
.
read
(
new
File
(
"Tank_sand.png"
));
}
}
catch
(
IOException
e
)
{
catch
(
IOException
e
){
System
.
out
.
println
(
e
);
System
.
out
.
println
(
e
);
}
}
}
}
...
@@ -143,18 +142,20 @@ public class GameFrame extends JFrame {
...
@@ -143,18 +142,20 @@ public class GameFrame extends JFrame {
g2d
.
setColor
(
Color
.
BLACK
);
g2d
.
setColor
(
Color
.
BLACK
);
//g2d.fillOval(state.locX, state.locY, state.diam, state.diam);
//g2d.fillOval(state.locX, state.locY, state.diam, state.diam);
g2d
.
setColor
(
Color
.
lightGray
);
g2d
.
setColor
(
Color
.
lightGray
);
g2d
.
fillRect
(
0
,
640
,
1280
,
160
);
g2d
.
fillRect
(
0
,
720
,
1280
,
160
);
// g2d.drawImage(image1,state.locX,state.locY,null);
// g2d.drawImage(image1,state.locX,state.locY,null);
g2d
.
setColor
(
Color
.
black
);
g2d
.
setColor
(
Color
.
black
);
g2d
.
drawImage
(
rotate
(
image1
,
state
.
rotateAmount
),
state
.
locX
,
state
.
locY
,
null
);
g2d
.
drawImage
(
rotate
(
image1
,
state
.
rotateAmount
),
state
.
locX
,
state
.
locY
,
null
);
File
accounts
=
new
File
(
"map.txt"
);
File
accounts
=
new
File
(
"map4.txt"
);
setName
(
g2d
,
"narges"
,
"sara"
,
"bardia"
);
setName
(
g2d
,
"narges"
,
"sara"
,
"bardia"
);
try
(
Scanner
scanner
=
new
Scanner
(
new
FileReader
(
accounts
)))
{
try
(
Scanner
scanner
=
new
Scanner
(
new
FileReader
(
accounts
)))
{
int
lineCounter
=
0
;
int
lineCounter
=
0
;
int
currentX
=
30
;
int
currentX
=
30
;
int
currentY
=
7
0
;
int
currentY
=
6
0
;
setMap
(
g2d
,
new
File
(
"map.txt"
));
while
(
scanner
.
hasNext
())
{
while
(
scanner
.
hasNext
())
{
char
[]
chars
=
scanner
.
next
().
toCharArray
();
char
[]
chars
=
scanner
.
next
().
toCharArray
();
...
@@ -162,7 +163,9 @@ public class GameFrame extends JFrame {
...
@@ -162,7 +163,9 @@ public class GameFrame extends JFrame {
for
(
int
k
=
0
;
k
<
chars
.
length
;
k
++)
{
for
(
int
k
=
0
;
k
<
chars
.
length
;
k
++)
{
if
(
lineCounter
%
2
==
0
)
{
if
(
lineCounter
%
2
==
0
)
{
if
(
k
%
2
==
0
)
{
if
(
k
%
2
==
0
)
{
if
(
chars
[
k
]
==
'1'
)
if
(
chars
[
k
]
==
'1'
)
g2d
.
fillRect
(
currentX
,
currentY
,
5
,
5
);
g2d
.
fillRect
(
currentX
,
currentY
,
5
,
5
);
currentX
+=
5
;
currentX
+=
5
;
...
@@ -179,10 +182,12 @@ public class GameFrame extends JFrame {
...
@@ -179,10 +182,12 @@ public class GameFrame extends JFrame {
g2d
.
fillRect
(
currentX
,
currentY
,
5
,
50
);
g2d
.
fillRect
(
currentX
,
currentY
,
5
,
50
);
currentX
+=
5
;
currentX
+=
5
;
}
else
{
}
else
{
if
(
chars
[
k
]
==
'1'
)
// if (chars[k] == '1') {
g2d
.
fillRect
(
currentX
,
currentY
,
50
,
50
);
// g2d.setColor(Color.white);
// //g2d.fillRect(currentX, currentY, 50, 50);
// g2d.setColor(Color.black);
// }
currentX
+=
50
;
currentX
+=
50
;
}
}
}
}
}
}
...
@@ -197,23 +202,37 @@ public class GameFrame extends JFrame {
...
@@ -197,23 +202,37 @@ public class GameFrame extends JFrame {
}
}
}
}
public
void
setName
(
Graphics2D
g2d
,
String
player1
,
String
player2
,
String
player3
){
public
void
setMap
(
Graphics2D
g2D
,
File
map
)
{
if
(
player1
!=
null
)
{
int
row
=
1
;
g2d
.
drawImage
(
image2
,
150
,
670
,
null
);
int
column
=
0
;
player1
=
"narges"
;
try
(
Scanner
scanner
=
new
Scanner
(
new
FileReader
(
map
)))
{
g2d
.
drawString
(
player1
,
160
,
665
);
column
=
scanner
.
nextLine
().
length
();
while
(
scanner
.
hasNext
())
{
column
=
scanner
.
nextLine
().
length
();
row
++;
}
}
catch
(
Exception
ee
)
{
ee
.
printStackTrace
();
}
}
public
void
setName
(
Graphics2D
g2d
,
String
player1
,
String
player2
,
String
player3
)
{
if
(
player1
!=
null
)
{
g2d
.
drawImage
(
image2
,
150
,
750
,
null
);
player1
=
"narges"
;
g2d
.
drawString
(
player1
,
160
,
745
);
}
}
if
(
player2
!=
null
)
{
if
(
player2
!=
null
)
{
g2d
.
drawImage
(
image3
,
450
,
67
0
,
null
);
g2d
.
drawImage
(
image3
,
450
,
75
0
,
null
);
g2d
.
drawString
(
player2
,
455
,
66
5
);
g2d
.
drawString
(
player2
,
455
,
74
5
);
}
}
if
(
player3
!=
null
)
{
if
(
player3
!=
null
)
{
g2d
.
drawImage
(
image4
,
750
,
67
0
,
null
);
g2d
.
drawImage
(
image4
,
750
,
75
0
,
null
);
g2d
.
drawString
(
player3
,
755
,
66
5
);
g2d
.
drawString
(
player3
,
755
,
74
5
);
}
}
g2d
.
drawImage
(
image5
,
1050
,
670
,
null
);
g2d
.
drawImage
(
image5
,
1050
,
750
,
null
);
}
}
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment