logo

Memory Sequence Game - Java Program for Console Based Game

Design and implement a program in Java for a memory game or a maths quiz, and write a reflection on the completion of the task.

8 Pages998 Words259 Views
   

Added on  2023-06-10

About This Document

This program represents the Memory-Sequence game where the player can choose a particular difficulty and play the game accordingly. In this game random sequences of numbers are presented to the player and then the screen is wiped clean. Finally, the player is asked to repeat the sequence exactly as it was displayed to him. In the steps to develop this console based application I had to face a handful of problems. However, solving these problems helped me to learn some necessities about Java programming and game designing concepts.

Memory Sequence Game - Java Program for Console Based Game

Design and implement a program in Java for a memory game or a maths quiz, and write a reflection on the completion of the task.

   Added on 2023-06-10

ShareRelated Documents
Running head: MEMORY SEQUENCE GAME
Memory Sequence Game
Name of the student:
Name of the University:
Author note:
Memory Sequence Game - Java Program for Console Based Game_1
2
MEMORY SEQUENCE GAME
Flowchart
Source Code
import java.io.IOException;
import java.util.Random;
import java.util.Scanner;
public class MemorySequenceGame {
static int[] sequence = new int[15];
static int n, high=1;
public static void generateSeq(int mSecs){
Random rand = new Random();
for(int i=0;i<n;i++) {
sequence[i]=rand.nextInt(99) + 10;
try {
Thread.sleep(mSecs);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
Memory Sequence Game - Java Program for Console Based Game_2
3
MEMORY SEQUENCE GAME
}
System.out.print(sequence[i]+" ");
}
}
public static boolean play(int mSecs){
Scanner sc = new Scanner(System.in);
boolean winStatus = true;
int i;
while(n<=15) {
System.out.print("\nThe numbers are: ");
generateSeq(mSecs);
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
try {
new ProcessBuilder("cmd", "/c",
"cls").inheritIO().start().waitFor();
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
int input;
System.out.println("\n\nEnter all the "+n+" numbers in proper
sequence: ");
for(i=0;i<n;i++) {
input=sc.nextInt();
if(input!=sequence[i]) {
System.out.println("\nSorry!! You are eliminated!!");
winStatus=false;
return winStatus;
}
}
System.out.println("\nHurray!! You are promoted to Level: "+
((++n)-2));
}
return winStatus;
}
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int choice=1,subChoice;
boolean status;
while(choice != 0) {
n=3;
System.out.println("\n~~ Welcome to the Memory-Sequence-Game ~~");
System.out.println("\nEnter 1: Start a New Game.\nEnter 2: View
Highest Score\nEnter 0: Quit");
Memory Sequence Game - Java Program for Console Based Game_3

End of preview

Want to access all the pages? Upload your documents or become a member.

Related Documents
NIM Game Playing Interface in Java
|8
|2250
|180