Skip to content

CorruptPriest/Catch-The-Bot-Java

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 

Repository files navigation

Hello, This is a project made in java for a simple terminal game.

->Explanation of the Code

  1. Imports:
  • We import the Utility package from java library to get certain fuctions.
  • We use Random for generating random numbers and Scanner for user input.
  1. Initialization:
  • We define mapSize as 10, representing each line's positions from 0 to 9.
  • A two-dimensional array map is created to represent two lines of the game area.
  • The player's starting position is set to (0,0) on line 0, while the bot's starting position is randomly generated.
  1. Game Loop:
  • The loop runs for a maximum of 10 turns.
  • The current state of the map is displayed using displayMap(), showing both players' positions.
  • The player can enter their move: "L" for left, "R" for right, "U" for up (to line 0), and "D" for down (to line 1).
  • Based on input, the player's position is updated accordingly while ensuring it stays within bounds.
  1. Bot Movement:
  • The bot moves randomly within its line and may switch lines randomly after each turn.
  1. Check for Catch Condition:
  • After each turn, we check if the player's position matches the bot's position.
  • If they match, a congratulatory message is displayed, and the game ends.
  1. Game Over:
  • If the loop completes without catching the bot, a game over message is displayed along with the final position of the bot.

About

This is a simple code for a simple game in Java.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages